Trait/Object

org.scalatest.diagrams

Diagrams

Related Docs: object Diagrams | package diagrams

Permalink

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
Visibility
  1. Public
  2. All

Type Members

  1. class CheckingEqualizer[L] extends AnyRef

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

    Permalink
    Definition Classes
    TripleEqualsSupport

Value Members

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

    Permalink
    Definition Classes
    AnyRef → Any
  2. def !==[T](right: Spread[T]): TripleEqualsInvocationOnSpread[T]

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

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

    Permalink
    Definition Classes
    TripleEqualsSupport
  5. final def ##(): Int

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

    Permalink
    Definition Classes
    AnyRef → Any
  7. def ===[T](right: Spread[T]): TripleEqualsInvocationOnSpread[T]

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

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

    Permalink
    Definition Classes
    TripleEqualsSupport
  10. final def asInstanceOf[T0]: T0

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

    Permalink

    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
    Exceptions thrown

    NullArgumentException if message is null.

    TestFailedException if the condition is false.

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

    Permalink

    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
    Exceptions thrown

    TestFailedException if the condition is false.

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

    Permalink
    Definition Classes
    Assertions
  14. macro def assertDoesNotCompile(code: String)(implicit pos: Position): Assertion

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

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

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

    Permalink
    Definition Classes
    Assertions
  18. macro def assertTypeError(code: String)(implicit pos: Position): Assertion

    Permalink
    Definition Classes
    Assertions
  19. macro def assume(condition: Boolean, clue: Any)(implicit prettifier: Prettifier, pos: Position): Assertion

    Permalink

    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
    Exceptions thrown

    NullArgumentException if message is null.

    TestCanceledException if the condition is false.

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

    Permalink

    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
    Exceptions thrown

    TestCanceledException if the condition is false.

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

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

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

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

    Permalink
    Definition Classes
    Assertions
  25. def clone(): AnyRef

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

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

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

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

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

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

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

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

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

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

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

    Permalink
    Definition Classes
    Assertions
  37. def finalize(): Unit

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

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

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

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

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

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

    Permalink
    Definition Classes
    AnyRef
  44. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  45. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  46. def pending: Assertion with PendingStatement

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

    Permalink
    Definition Classes
    Assertions
  48. final val succeed: Assertion

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

    Permalink
    Definition Classes
    AnyRef
  50. def toString(): String

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

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

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

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

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

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

    Permalink
    Definition Classes
    Assertions

Deprecated Value Members

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

    Permalink
    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]

    Permalink
    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]

    Permalink
    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]

    Permalink
    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