8

When there is an equality assertion in scalatest that fails. It generally shows only the different part, e.g.:

"...error;
!I e: F[Arg]
[g invalid because
nonconformant bounds;
[Arg, Nothing]
[A <: __wrapper$1$47213a912399466a973eddce7b3420f4.__wrapper$1$47213a912399466a973eddce7b3420f4.]Bounds.Base, B]
  im..." did not equal "...error;
!I e: F[Arg]
[Bounds.g invalid because
nonconformant bounds;
[Arg, Nothing]
[A <: ]Bounds.Base, B]
  im..."
org.scalatest.exceptions.TestFailedException: "...error;
!I e: F[Arg]
[g invalid because
nonconformant bounds;
[Arg, Nothing]
[A <: __wrapper$1$47213a912399466a973eddce7b3420f4.__wrapper$1$47213a912399466a973eddce7b3420f4.]Bounds.Base, B]
  im..." did not equal "...error;
!I e: F[Arg]
[Bounds.g invalid because
nonconformant bounds;
[Arg, Nothing]
[A <: ]Bounds.Base, B]
  im..."

A lot of information are lost in this report. In addition, When the IDE is armed with a diff parser, it will show the comparison result incorrectly. Is there way to disable this feature in scalatest, so there won't be any ellipsis in the report?

tribbloid
  • 4,026
  • 14
  • 64
  • 103

2 Answers2

0

You can add the flag -- -Dtest.show_diff=true. The full command will look like: test-only *TestFileName* -- -Dtest.show_diff=true

Murphpdx
  • 102
  • 8
  • Presumably this answer is about sbt command line, but I can't even get that to work. How would one turn this option on in say IntelliJ? – Peter Lamberg Jan 04 '23 at 18:11
  • I don't think this works with ScalaTest 3.x.x anymore. I can't find the string show_diff in the source code. See my other answer. – Peter Lamberg Jan 05 '23 at 09:01
0

Unfortunately this is impossible at the moment starting with ScalaTest 3.x.x without writing your own custom assertion code. See this issue.

You can change the prettifier to Prettifier.basic like this for example:

import scalatest.org.Assertions._
import org.scalactic.Prettifier

assert(foo == bar)(Prettifier.basic, org.scalactic.source.Position.here)

But even then I it will use the StringDiffer with a hard coded MaxContext of 20 characters.

Johny T Koshy
  • 3,857
  • 2
  • 23
  • 40
Peter Lamberg
  • 8,151
  • 3
  • 55
  • 69