5.5 Unit Testing
expression | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
expression | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
expression | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
In ~is mode, evaluates the expected_expr or expected_body, then checks that the original result is not an exception and is equal by ==.
In ~is_now mode, check like ~is mode, but using is_now.
In ~is_a mode, checks that the original result is not an exception and satisfies annot.
In ~prints_like mode, evaluates the expected_expr or expected_body, then checks that the original result is not an exception and has the same printed form as the expected result.
In ~matches mode, checks that the original result is not an exception, that the number of result values matches the number of supplied expected_binds, and that each value matches the corresponding expected_bind.
In ~prints mode, evaluates the expected_expr or expected_body in a mode that captures output to Port.Output.current() to a string, then checks that there is no exception and the output string is the same as the expected result.
In ~throws mode, obtains one or more strings (as multiple values) by evaluating expected_body or expected_expr, then checks that original body or expr threw an exception and that each string is contained in the exception message.
In ~completes mode, checks merely that the original result is not an exception. A #void is implicitly added to the end of body or expr, so it could end with a definition.
If ~eval is present, then body is quoted to be parsed and evaluated using eval at run time. A typical use of ~eval is to test syntax errors. When evaluator_expr is provided, then its result is installed as the current evaluator for eval; otherwise, an evaluator is created with Evaluator.make_rhombus. The body sequence is evaluated as an interactive form (i.e., eval is called with ~as_interactive: #true).
Providing multiple expr expected_result groups in a single check form is the same as providing each group to a separate check form. The ~eval mode is not supported in the shorthand forms of check.
The evaluation of an expr or body sequence is wrapped with a prompt for the default continuation prompt tag.
When a test fails, a failure message is printed to the current error port, but using the current error display handler when a source location is available. No output is printed for a successful test.
check: failed
got: 2
expected: 3 Port.Output(#’string)
> check:
1+1
~is 2
> check:
1+1 ~is 2
1+1 ~is 3
check: failed
got: 2
expected: 3 Port.Output(#’string)
> check:
1+1
~is_a Int
> check:
1+1
~is_a String
check: failed
got: 2
expected: satisfying String Port.Output(#’string)
> check:
> check:
~prints_like '2'
> check:
1+"a"
~throws "expected: Number"
check: failed
got: exception +: value does not satisfy annotation
annotation: Number
value: "a"
expected: exception "expected: Number" Port.Output(#’string)
> check:
+ // oops: causes syntax error for overall `check` form
~throws "infix operator without preceding argument"
+: infix operator without preceding argument Port.Output(#’string)
> check:
~eval // lets `check` confirm the expected syntax error
~throws "infix operator without preceding argument"
> check:
~eval
~throws values("+", "infix operator without preceding argument")