PropertyHelper¶
Helper for PonyCheck properties.
Mirrors the TestHelper API as closely 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.
Constructors¶
create¶
new val create(
env': Env val,
runner: _IPropertyRunner tag,
run_notify: _PropertyRunNotify val,
run: (_Shrink val | _Run val),
params: String val)
: PropertyHelper val^
Parameters¶
- env': Env val
- runner: _IPropertyRunner tag
- run_notify: _PropertyRunNotify val
- run: (_Shrink val | _Run val)
- params: 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.
Parameters¶
Returns¶
- None val
fail¶
Flag the test as having failed.
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)
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.
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.
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
.
Parameters¶
- success: Bool val
Returns¶
- None val
dispose_when_done¶
Dispose the actor after a property run / a shrink is done.
Parameters¶
- disposable: DisposableActor tag
Returns¶
- None val