org.scalatest.diagrams

Diagrams

trait Diagrams extends Assertions

Sub-trait of Assertions that overrides 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 org.scalatest.diagrams.Diagrams._
import org.scalatest.diagrams.Diagrams._

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, Diagrams falls back to the default style of error message, since drawing a diagram would be difficult. Here's an example showing how Diagrams 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 Diagrams was inspired by Peter Niederwieser's work in Spock and Expecty.

Linear Supertypes
Assertions, TripleEquals, TripleEqualsSupport, AnyRef, Any
Known Subclasses
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. Diagrams
  2. Assertions
  3. TripleEquals
  4. TripleEqualsSupport
  5. AnyRef
  6. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Type Members

  1. class CheckingEqualizer[L] extends AnyRef

    Definition Classes
    TripleEqualsSupport
  2. class Equalizer[L] extends AnyRef

    Definition Classes
    TripleEqualsSupport

Value Members

  1. final def !=(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  2. final def !=(arg0: Any): Boolean

    Definition Classes
    Any
  3. def !==[T](right: Spread[T]): TripleEqualsInvocationOnSpread[T]

    Definition Classes
    TripleEqualsSupport
  4. def !==(right: Null): TripleEqualsInvocation[Null]

    Definition Classes
    TripleEqualsSupport
  5. def !==[T](right: T): TripleEqualsInvocation[T]

    Definition Classes
    TripleEqualsSupport
  6. final def ##(): Int

    Definition Classes
    AnyRef → Any
  7. final def ==(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  8. final def ==(arg0: Any): Boolean

    Definition Classes
    Any
  9. def ===[T](right: Spread[T]): TripleEqualsInvocationOnSpread[T]

    Definition Classes
    TripleEqualsSupport
  10. def ===(right: Null): TripleEqualsInvocation[Null]

    Definition Classes
    TripleEqualsSupport
  11. def ===[T](right: T): TripleEqualsInvocation[T]

    Definition Classes
    TripleEqualsSupport
  12. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  13. def assert(condition: Boolean, clue: Any)(implicit prettifier: Prettifier, pos: Position): Assertion

    Assert that a boolean condition, described in String message, is true.

    Assert that a boolean condition, described in String message, is true. If the condition is true, this method returns normally. Else, it throws TestFailedException with the String obtained by invoking toString on the specified clue as the exception's detail message and a diagram showing expression values.

    If multi-line Boolean is passed in, it will fallback to the macro implementation of Assertions that does not contain diagram.

    condition

    the boolean condition to assert

    clue

    An objects whose toString method returns a message to include in a failure report.

    Definition Classes
    Diagrams → Assertions
    Annotations
    @macroImpl( ... )
    Exceptions thrown
    NullArgumentException

    if message is null.

    TestFailedException

    if the condition is false.

  14. def assert(condition: Boolean)(implicit prettifier: Prettifier, pos: Position): Assertion

    Assert that a boolean condition is true.

    Assert that a boolean condition is true. If the condition is true, this method returns normally. Else, it throws TestFailedException.

    This method is implemented in terms of a Scala macro that will generate a more helpful error message that includes a diagram showing expression values.

    If multi-line Boolean is passed in, it will fallback to the macro implementation of Assertions that does not contain diagram.

    condition

    the boolean condition to assert

    Definition Classes
    Diagrams → Assertions
    Annotations
    @macroImpl( ... )
    Exceptions thrown
    TestFailedException

    if the condition is false.

  15. def assertCompiles(code: String)(implicit pos: Position): Assertion

    Definition Classes
    Assertions
    Annotations
    @macroImpl( ... )
  16. def assertDoesNotCompile(code: String)(implicit pos: Position): Assertion

    Definition Classes
    Assertions
    Annotations
    @macroImpl( ... )
  17. def assertResult(expected: Any)(actual: Any)(implicit prettifier: Prettifier, pos: Position): Assertion

    Definition Classes
    Assertions
  18. def assertResult(expected: Any, clue: Any)(actual: Any)(implicit prettifier: Prettifier, pos: Position): Assertion

    Definition Classes
    Assertions
  19. def assertThrows[T <: AnyRef](f: ⇒ Any)(implicit classTag: ClassTag[T], pos: Position): Assertion

    Definition Classes
    Assertions
  20. def assertTypeError(code: String)(implicit pos: Position): Assertion

    Definition Classes
    Assertions
    Annotations
    @macroImpl( ... )
  21. def assume(condition: Boolean, clue: Any)(implicit prettifier: Prettifier, pos: Position): Assertion

    Assume that a boolean condition, described in String message, is true.

    Assume that a boolean condition, described in String message, is true. If the condition is true, this method returns normally. Else, it throws TestCanceledException with the String obtained by invoking toString on the specified clue as the exception's detail message and a diagram showing expression values.

    If multi-line Boolean is passed in, it will fallback to the macro implementation of Assertions that does not contain diagram.

    condition

    the boolean condition to assume

    clue

    An objects whose toString method returns a message to include in a failure report.

    Definition Classes
    Diagrams → Assertions
    Annotations
    @macroImpl( ... )
    Exceptions thrown
    NullArgumentException

    if message is null.

    TestCanceledException

    if the condition is false.

  22. def assume(condition: Boolean)(implicit prettifier: Prettifier, pos: Position): Assertion

    Assume that a boolean condition is true.

    Assume that a boolean condition is true. If the condition is true, this method returns normally. Else, it throws TestCanceledException.

    This method is implemented in terms of a Scala macro that will generate a more helpful error message that includes a diagram showing expression values.

    If multi-line Boolean is passed in, it will fallback to the macro implementation of Assertions that does not contain diagram.

    condition

    the boolean condition to assume

    Definition Classes
    Diagrams → Assertions
    Annotations
    @macroImpl( ... )
    Exceptions thrown
    TestCanceledException

    if the condition is false.

  23. def cancel(cause: Throwable)(implicit pos: Position): Nothing

    Definition Classes
    Assertions
  24. def cancel(message: String, cause: Throwable)(implicit pos: Position): Nothing

    Definition Classes
    Assertions
  25. def cancel(message: String)(implicit pos: Position): Nothing

    Definition Classes
    Assertions
  26. def cancel()(implicit pos: Position): Nothing

    Definition Classes
    Assertions
  27. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  28. def convertEquivalenceToAToBConstraint[A, B](equivalenceOfB: Equivalence[B])(implicit ev: <:<[A, B]): CanEqual[A, B]

    Definition Classes
    TripleEquals → TripleEqualsSupport
  29. def convertEquivalenceToBToAConstraint[A, B](equivalenceOfA: Equivalence[A])(implicit ev: <:<[B, A]): CanEqual[A, B]

    Definition Classes
    TripleEquals → TripleEqualsSupport
  30. def convertToCheckingEqualizer[T](left: T): CheckingEqualizer[T]

    Definition Classes
    TripleEquals → TripleEqualsSupport
  31. implicit def convertToEqualizer[T](left: T): Equalizer[T]

    Definition Classes
    TripleEquals → TripleEqualsSupport
  32. def defaultEquality[A]: Equality[A]

    Definition Classes
    TripleEqualsSupport
  33. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  34. def equals(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  35. def fail(cause: Throwable)(implicit pos: Position): Nothing

    Definition Classes
    Assertions
  36. def fail(message: String, cause: Throwable)(implicit pos: Position): Nothing

    Definition Classes
    Assertions
  37. def fail(message: String)(implicit pos: Position): Nothing

    Definition Classes
    Assertions
  38. def fail()(implicit pos: Position): Nothing

    Definition Classes
    Assertions
  39. def finalize(): Unit

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  40. final def getClass(): Class[_]

    Definition Classes
    AnyRef → Any
  41. def hashCode(): Int

    Definition Classes
    AnyRef → Any
  42. def intercept[T <: AnyRef](f: ⇒ Any)(implicit classTag: ClassTag[T], pos: Position): T

    Definition Classes
    Assertions
  43. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  44. def lowPriorityTypeCheckedConstraint[A, B](implicit equivalenceOfB: Equivalence[B], ev: <:<[A, B]): CanEqual[A, B]

    Definition Classes
    TripleEquals → TripleEqualsSupport
  45. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  46. final def notify(): Unit

    Definition Classes
    AnyRef
  47. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  48. def pending: Assertion with PendingStatement

    Definition Classes
    Assertions
  49. def pendingUntilFixed(f: ⇒ Unit)(implicit pos: Position): Assertion with PendingStatement

    Definition Classes
    Assertions
  50. final val succeed: Assertion

    Definition Classes
    Assertions
  51. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  52. def toString(): String

    Definition Classes
    AnyRef → Any
  53. def typeCheckedConstraint[A, B](implicit equivalenceOfA: Equivalence[A], ev: <:<[B, A]): CanEqual[A, B]

    Definition Classes
    TripleEquals → TripleEqualsSupport
  54. implicit def unconstrainedEquality[A, B](implicit equalityOfA: Equality[A]): CanEqual[A, B]

    Definition Classes
    TripleEquals → TripleEqualsSupport
  55. final def wait(): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  56. final def wait(arg0: Long, arg1: Int): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  57. final def wait(arg0: Long): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  58. def withClue[T](clue: Any)(fun: ⇒ T): T

    Definition Classes
    Assertions

Deprecated Value Members

  1. def conversionCheckedConstraint[A, B](implicit equivalenceOfA: Equivalence[A], cnv: (B) ⇒ A): CanEqual[A, B]

    Definition Classes
    TripleEquals → TripleEqualsSupport
    Annotations
    @deprecated
    Deprecated

    (Since version 3.1.0) The conversionCheckedConstraint method has been deprecated and will be removed in a future version of ScalaTest. It is no longer needed now that the deprecation period of ConversionCheckedTripleEquals has expired. It will not be replaced.

  2. def convertEquivalenceToAToBConversionConstraint[A, B](equivalenceOfB: Equivalence[B])(implicit ev: (A) ⇒ B): CanEqual[A, B]

    Definition Classes
    TripleEquals → TripleEqualsSupport
    Annotations
    @deprecated
    Deprecated

    (Since version 3.1.0) The convertEquivalenceToAToBConversionConstraint method has been deprecated and will be removed in a future version of ScalaTest. It is no longer needed now that the deprecation period of ConversionCheckedTripleEquals has expired. It will not be replaced.

  3. def convertEquivalenceToBToAConversionConstraint[A, B](equivalenceOfA: Equivalence[A])(implicit ev: (B) ⇒ A): CanEqual[A, B]

    Definition Classes
    TripleEquals → TripleEqualsSupport
    Annotations
    @deprecated
    Deprecated

    (Since version 3.1.0) The convertEquivalenceToBToAConversionConstraint method has been deprecated and will be removed in a future version of ScalaTest. It is no longer needed now that the deprecation period of ConversionCheckedTripleEquals has expired. It will not be replaced.

  4. def lowPriorityConversionCheckedConstraint[A, B](implicit equivalenceOfB: Equivalence[B], cnv: (A) ⇒ B): CanEqual[A, B]

    Definition Classes
    TripleEquals → TripleEqualsSupport
    Annotations
    @deprecated
    Deprecated

    (Since version 3.1.0) The lowPriorityConversionCheckedConstraint method has been deprecated and will be removed in a future version of ScalaTest. It is no longer needed now that the deprecation period of ConversionCheckedTripleEquals has expired. It will not be replaced.

Inherited from Assertions

Inherited from TripleEquals

Inherited from TripleEqualsSupport

Inherited from AnyRef

Inherited from Any

Ungrouped