org.scalatest.diagrams
Type members
Classlikes
A trait that represent an expression recorded by DiagrammedExprMacro
, which includes the following members:
A trait that represent an expression recorded by DiagrammedExprMacro
, which includes the following members:
-
a boolean value
-
an anchor that records the position of this expression
-
anchor values of this expression (including sub-expressions)
DiagrammedExpr
is used by code generated from DiagrammedAssertionsMacro
, it needs to be public
so that the generated code can be compiled. It is expected that ScalaTest users would ever need to use DiagrammedExpr
directly.
- Companion:
- object
DiagrammedExpr
companion object that provides factory methods to create different sub types of DiagrammedExpr
DiagrammedExpr
companion object that provides factory methods to create different sub types of DiagrammedExpr
DiagrammedExpr
is used by code generated from DiagrammedAssertionsMacro
, it needs to be public
so that the generated code can be compiled. It is expected that ScalaTest users would ever need to use DiagrammedExpr
directly.
- Companion:
- class
Sub-trait of Assertions
that override assert
and assume
methods to include
a diagram showing the values of expression in the error message when the assertion or assumption fails.
Sub-trait of Assertions
that override assert
and assume
methods to include
a diagram showing the values of expression in the error message when the assertion or assumption fails.
Here are some examples:
scala> import DiagrammedAssertions._ import DiagrammedAssertions._ scala> assert(a == b || c >= d) org.scalatest.exceptions.TestFailedException: assert(a == b || c >= d) | | | | | | | 1 | 2 | 3 | 4 | | false | false false at org.scalatest.Assertions$class.newAssertionFailedException(Assertions.scala:422) ... scala> assert(xs.exists(_ == 4)) org.scalatest.exceptions.TestFailedException: assert(xs.exists(_ == 4)) | | | false List(1, 2, 3) at org.scalatest.Assertions$class.newAssertionFailedException(Assertions.scala:422) ... scala> assert("hello".startsWith("h") && "goodbye".endsWith("y")) org.scalatest.exceptions.TestFailedException: assert("hello".startsWith("h") && "goodbye".endsWith("y")) | | | | | | | "hello" true "h" | "goodbye" false "y" false at org.scalatest.Assertions$class.newAssertionFailedException(Assertions.scala:422) ... scala> assert(num.isInstanceOf[Int]) org.scalatest.exceptions.TestFailedException: assert(num.isInstanceOf[Int]) | | 1.0 false at org.scalatest.Assertions$class.newAssertionFailedException(Assertions.scala:422) ... scala> assert(Some(2).isEmpty) org.scalatest.exceptions.TestFailedException: assert(Some(2).isEmpty) | | | | 2 false Some(2) at org.scalatest.Assertions$class.newAssertionFailedException(Assertions.scala:422) ... scala> assert(None.isDefined) org.scalatest.exceptions.TestFailedException: assert(None.isDefined) | | None false at org.scalatest.Assertions$class.newAssertionFailedException(Assertions.scala:422) ... scala> assert(xs.exists(i => i > 10)) org.scalatest.exceptions.TestFailedException: assert(xs.exists(i => i > 10)) | | | false List(1, 2, 3) at org.scalatest.Assertions$class.newAssertionFailedException(Assertions.scala:422) ...
If the expression passed to assert
or assume
spans more than one line, DiagrammedAssertions
falls
back to the default style of error message, since drawing a diagram would be difficult. Here's an example showing how
DiagrammedAssertions
will treat a multi-line assertion (i.e., you don't get a diagram):
scala> assert("hello".startsWith("h") && | "goodbye".endsWith("y")) org.scalatest.exceptions.TestFailedException: "hello" started with "h", but "goodbye" did not end with "y" at org.scalatest.Assertions$class.newAssertionFailedException(Assertions.scala:422) ...
Also, since an expression diagram essentially represents multi-line ascii art, if a clue string is provided, it appears above the diagram, not after it. It will often also show up in the diagram:
scala> assert(None.isDefined, "Don't do this at home") org.scalatest.exceptions.TestFailedException: Don't do this at home assert(None.isDefined, "Don't do this at home") | | None false at org.scalatest.Assertions$class.newAssertionFailedException(Assertions.scala:422) ... scala> assert(None.isDefined, | "Don't do this at home") org.scalatest.exceptions.TestFailedException: Don't do this at home assert(None.isDefined, | | None false at org.scalatest.Assertions$class.newAssertionFailedException(Assertions.scala:422) ...
Trait DiagrammedAssertions
was inspired by Peter Niederwieser's work in Spock and Expecty.
- Companion:
- object
Companion object that facilitates the importing of DiagrammedAssertions
members as
an alternative to mixing it in. One use case is to import DiagrammedAssertions
members so you can use
them in the Scala interpreter:
Companion object that facilitates the importing of DiagrammedAssertions
members as
an alternative to mixing it in. One use case is to import DiagrammedAssertions
members so you can use
them in the Scala interpreter:
$scala -classpath scalatest.jar Welcome to Scala 2.13.6 (OpenJDK 64-Bit Server VM, Java yyy). Type in expressions for evaluation. Or try :help. scala> import org.scalatest.Assertions._ import org.scalatest.Assertions._ scala> assert(1 === 2) org.scalatest.exceptions.TestFailedException: assert(1 === 2) | | | 1 | 2 false at org.scalatest.Assertions$class.newAssertionFailedException(Assertions.scala:422) at org.scalatest.DiagrammedAssertions$.newAssertionFailedException(DiagrammedAssertions.scala:249) at org.scalatest.DiagrammedAssertions$DiagrammedAssertionsHelper.macroAssert(DiagrammedAssertions.scala:111) at .<init>(<console>:20) at .<clinit>(<console>) at .<init>(<console>:7) at .<clinit>(<console>) at $print(<console>) at sun.reflect.NativeMethodAccessorImpl.invoke...
- Companion:
- class