Packages

  • package root
    Definition Classes
    root
  • package org
    Definition Classes
    root
  • package scalatest

    ScalaTest's main traits, classes, and other members, including members supporting ScalaTest's DSL for the Scala interpreter.

    ScalaTest's main traits, classes, and other members, including members supporting ScalaTest's DSL for the Scala interpreter.

    Definition Classes
    org
  • trait DiagrammedAssertions extends Assertions

    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.

    Definition Classes
    scalatest
  • AssertionsHelper
  • CheckingEqualizer
  • DiagrammedAssertionsHelper
  • Equalizer
c

org.scalatest.DiagrammedAssertions

DiagrammedAssertionsHelper

class DiagrammedAssertionsHelper extends AnyRef

Helper class used by code generated by the overriden assert macro.

Source
DiagrammedAssertions.scala
Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. DiagrammedAssertionsHelper
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new DiagrammedAssertionsHelper()

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  5. def clone(): AnyRef
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @native() @throws( ... )
  6. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  7. def equals(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  8. def finalize(): Unit
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  9. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  10. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  11. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  12. def macroAssert(bool: DiagrammedExpr[Boolean], clue: Any, sourceText: String, pos: Position): Assertion

    Assert that the passed in Bool is true, else fail with TestFailedException with error message that include a diagram showing expression values.

    Assert that the passed in Bool is true, else fail with TestFailedException with error message that include a diagram showing expression values.

    bool

    the Bool to assert for

    clue

    optional clue to be included in TestFailedException's error message when assertion failed

  13. def macroAssume(bool: DiagrammedExpr[Boolean], clue: Any, sourceText: String, pos: Position): Assertion

    Assume that the passed in Bool is true, else throw TestCanceledException with error message that include a diagram showing expression values.

    Assume that the passed in Bool is true, else throw TestCanceledException with error message that include a diagram showing expression values.

    bool

    the Bool to assume for

    clue

    optional clue to be included in TestCanceledException's error message when assertion failed

  14. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  15. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  16. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  17. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  18. def toString(): String
    Definition Classes
    AnyRef → Any
  19. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  20. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  21. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @throws( ... )

Inherited from AnyRef

Inherited from Any

Ungrouped