PropertyHelper¶
Helper for ponycheck properties.
Mirrors the TestHelper API as close as possible.
Contains assertion functions and functions for completing asynchronous properties, for expecting and completing or failing actions.
Internally a new PropertyHelper will be created for each call to a property with a new sample and also for every shrink run. So don't assume anything about the identity of the PropertyHelper inside of your Properties.
This class is val
by default so it can be safely passed around to other
actors.
It exposes the process Env as public env
field in order to
give access to the root authority and other stuff.
class val PropertyHelper
Constructors¶
create¶
new val create(
env': Env val,
runner: _IPropertyRunner tag,
run_notify: _PropertyRunNotify val,
run_context: String val)
: PropertyHelper val^
Parameters¶
- env': Env val
- runner: _IPropertyRunner tag
- run_notify: _PropertyRunNotify val
- run_context: String val
Returns¶
- PropertyHelper val^
Public fields¶
let env: Env val¶
Public Functions¶
log¶
Log the given message.
The verbose parameter allows messages to be printed only when the --verbose command line option is used. For example, by default assert failures are logged, but passes are not. With --verbose both passes and fails are reported.
Logs are printed one test at a time to avoid interleaving log lines from concurrent tests.
fun box log(
msg: String val,
verbose: Bool val = false)
: None val
Parameters¶
Returns¶
- None val
fail¶
Flag the test as having failed.
fun box fail(
msg: String val = "Test failed")
: None val
Parameters¶
- msg: String val = "Test failed"
Returns¶
- None val
assert_false¶
Assert that the given expression is false.
fun box assert_false(
predicate: Bool val,
msg: String val = "",
loc: SourceLoc val = __loc)
: Bool val
Parameters¶
Returns¶
- Bool val
assert_true¶
Assert that the given expression is true.
fun box assert_true(
predicate: Bool val,
msg: String val = "",
loc: SourceLoc val = __loc)
: Bool val
Parameters¶
Returns¶
- Bool val
assert_error¶
Assert that the given test function throws an error when run.
fun box assert_error(
test: {(): None ?} box,
msg: String val = "",
loc: SourceLoc val = __loc)
: Bool val
Parameters¶
Returns¶
- Bool val
assert_no_error¶
Assert that the given test function does not throw an error when run.
fun box assert_no_error(
test: {(): None ?} box,
msg: String val = "",
loc: SourceLoc val = __loc)
: Bool val
Parameters¶
Returns¶
- Bool val
assert_is[A: A]¶
Assert that the 2 given expressions resolve to the same instance
fun box assert_is[A: A](
expect: A,
actual: A,
msg: String val = "",
loc: SourceLoc val = __loc)
: Bool val
Parameters¶
Returns¶
- Bool val
assert_isnt[A: A]¶
Assert that the 2 given expressions resolve to different instances.
fun box assert_isnt[A: A](
not_expect: A,
actual: A,
msg: String val = "",
loc: SourceLoc val = __loc)
: Bool val
Parameters¶
Returns¶
- Bool val
assert_eq[A: (Equatable[A] #read & Stringable #read)]¶
Assert that the 2 given expressions are equal.
fun box assert_eq[A: (Equatable[A] #read & Stringable #read)](
expect: A,
actual: A,
msg: String val = "",
loc: SourceLoc val = __loc)
: Bool val
Parameters¶
Returns¶
- Bool val
assert_ne[A: (Equatable[A] #read & Stringable #read)]¶
Assert that the 2 given expressions are not equal.
fun box assert_ne[A: (Equatable[A] #read & Stringable #read)](
not_expect: A,
actual: A,
msg: String val = "",
loc: SourceLoc val = __loc)
: Bool val
Parameters¶
Returns¶
- Bool val
assert_array_eq[A: (Equatable[A] #read & Stringable #read)]¶
Assert that the contents of the 2 given ReadSeqs are equal.
fun box assert_array_eq[A: (Equatable[A] #read & Stringable #read)](
expect: ReadSeq[A] box,
actual: ReadSeq[A] box,
msg: String val = "",
loc: SourceLoc val = __loc)
: Bool val
Parameters¶
Returns¶
- Bool val
assert_array_eq_unordered[A: (Equatable[A] #read & Stringable #read)]¶
Assert that the contents of the 2 given ReadSeqs are equal ignoring order.
fun box assert_array_eq_unordered[A: (Equatable[A] #read & Stringable #read)](
expect: ReadSeq[A] box,
actual: ReadSeq[A] box,
msg: String val = "",
loc: SourceLoc val = __loc)
: Bool val
Parameters¶
Returns¶
- Bool val
expect_action¶
expect some action of the given name to complete for the property to hold.
If all expected actions are completed successfully, the property is considered successful.
If 1 action fails, the property is considered failing.
Call complete_action(name)
or fail_action(name)
to mark some action as completed.
Example:
actor AsyncActor
let _ph: PropertyHelper
new create(ph: PropertyHelper) =>
_ph = ph
be complete(s: String) =>
if (s.size() % 2) == 0 then
_ph.complete_action("is_even")
else
_ph.fail_action("is_even")
class EvenStringProperty is Property1[String]
fun name(): String => "even_string"
fun gen(): Generator[String] =>
Generators.ascii()
fun property(arg1: String, ph: PropertyHelper) =>
ph.expect_action("is_even")
AsyncActor(ph).check(arg1)
fun box expect_action(
name: String val)
: None val
Parameters¶
- name: String val
Returns¶
- None val
complete_action¶
Complete an expected action successfully.
If all expected actions are completed successfully, the property is considered successful.
If 1 action fails, the property is considered failing.
If the action name
was not expected, i.e. was not registered using
expect_action
, nothing happens.
fun val complete_action(
name: String val)
: None val
Parameters¶
- name: String val
Returns¶
- None val
fail_action¶
Mark an expected action as failed.
If all expected actions are completed successfully, the property is considered successful.
If 1 action fails, the property is considered failing.
fun val fail_action(
name: String val)
: None val
Parameters¶
- name: String val
Returns¶
- None val
complete¶
Complete an asynchronous property successfully.
Once this method is called the property
is considered successful or failing
depending on the value of the parameter success
.
For more fine grained control over completing or failing
a property that consists of many steps, consider using
expect_action
, complete_action
and fail_action
.
fun box complete(
success: Bool val)
: None val
Parameters¶
- success: Bool val
Returns¶
- None val
dispose_when_done¶
Dispose the actor after a property run / a shrink is done.
fun box dispose_when_done(
disposable: DisposableActor tag)
: None val
Parameters¶
- disposable: DisposableActor tag
Returns¶
- None val