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. 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

  2. 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