In scalatest, how to show full diff in test result?
Asked Answered
E

2

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?

Elaterid answered 29/10, 2021 at 17:52 Comment(0)
C
1

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.

Culberson answered 5/1, 2023 at 9:6 Comment(0)
P
0

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

Practice answered 10/12, 2022 at 0:50 Comment(2)
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?Culberson
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.Culberson

© 2022 - 2024 — McMap. All rights reserved.