Requirements

org.scalactic.Requirements
See theRequirements companion trait
object Requirements extends Requirements

Companion object that facilitates the importing of Requirements members as an alternative to mixing it in. One use case is to import Requirements 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.scalactic.Requirements._
import org.scalactic.Requirements._
 
scala> val a = 1
a: Int = 1
 
scala> require(a == 2)
java.lang.IllegalArgumentException: 1 did not equal 2
    at org.scalactic.Requirements$RequirementsHelper.macroRequire(Requirements.scala:56)
    at .<init>(<console>:20)
    at .<clinit>(<console>)
    at .<init>(<console>:7)
    at .<clinit>(<console>)
    at $print(<console>)
    at sun.reflect.NativeMethodAccessorImpl.invoke...

Attributes

Companion
trait
Source
Requirements.scala
Graph
Supertypes
trait Requirements
class Object
trait Matchable
class Any
Self type

Members list

Type members

Classlikes

class RequirementsHelper extends Serializable

Helper class used by code generated by the require macro.

Helper class used by code generated by the require macro.

Attributes

Source
Requirements.scala
Supertypes
trait Serializable
class Object
trait Matchable
class Any

Value members

Inherited methods

inline def require(inline condition: Boolean, clue: Any)(implicit prettifier: Prettifier): Unit

Require that a boolean condition about an argument passed to a method, function, or constructor, and described in the given clue, is true.

Require that a boolean condition about an argument passed to a method, function, or constructor, and described in the given clue, is true.

If the condition is true, this method returns normally. Else, it throws IllegalArgumentException with the String obtained by invoking toString on the specified clue and appending that to the macro-generated error message as the exception's detail message.

Value parameters

clue

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

condition

the boolean condition to check as requirement

Attributes

Throws
IllegalArgumentException

if the condition is false.

NullPointerException

if message is null.

Inherited from:
Requirements
Source
Requirements.scala
inline def require(inline condition: Boolean)(implicit prettifier: Prettifier): Unit

Require that a boolean condition is true about an argument passed to a method, function, or constructor.

Require that a boolean condition is true about an argument passed to a method, function, or constructor.

If the condition is true, this method returns normally. Else, it throws IllegalArgumentException.

This method is implemented in terms of a Scala macro that will generate an error message. See the main documentation for this trait for examples.

Value parameters

condition

the boolean condition to check as requirement

Attributes

Throws
IllegalArgumentException

if the condition is false.

Inherited from:
Requirements
Source
Requirements.scala
inline def requireNonNull(arguments: Any*)(implicit prettifier: Prettifier, pos: Position): Unit

Require that all passed arguments are non-null.

Require that all passed arguments are non-null.

If none of the passed arguments are null, this method returns normally. Else, it throws NullArgumentException with an error message that includes the name (as it appeared in the source) of each argument that was null.

Value parameters

arguments

arguments to check for null value

Attributes

Throws
NullArgumentException

if any of the arguments are null.

Inherited from:
Requirements
Source
Requirements.scala
inline def requireState(inline condition: Boolean, clue: Any)(implicit prettifier: Prettifier): Unit

Require that a boolean condition about the state of an object on which a method has been invoked, and described in the given clue, is true.

Require that a boolean condition about the state of an object on which a method has been invoked, and described in the given clue, is true.

If the condition is true, this method returns normally. Else, it throws IllegalStateException with the String obtained by invoking toString on the specified clue appended to the macro-generated error message as the exception's detail message.

Value parameters

clue

an object whose toString method returns a message to include in a failure report.

condition

the boolean condition to check as a requirement

Attributes

Throws
IllegalStateException

if the condition is false.

NullPointerException

if message is null.

Inherited from:
Requirements
Source
Requirements.scala
inline def requireState(inline condition: Boolean)(implicit prettifier: Prettifier): Unit

Require that a boolean condition is true about the state of an object on which a method has been invoked.

Require that a boolean condition is true about the state of an object on which a method has been invoked.

If the condition is true, this method returns normally. Else, it throws IllegalStateException.

This method is implemented in terms of a Scala macro that will generate an error message.

Value parameters

condition

the boolean condition to check as requirement

Attributes

Throws
IllegalStateException

if the condition is false.

Inherited from:
Requirements
Source
Requirements.scala

Concrete fields

Helper instance used by code generated by macro assertion.

Helper instance used by code generated by macro assertion.

Attributes

Source
Requirements.scala