Skip to content

PropertyHelper

[Source]

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

[Source]

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


Public fields

let env: Env val

[Source]


Public Functions

log

[Source]

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


fail

[Source]

Flag the test as having failed.

fun box fail(
  msg: String val = "Test failed")
: None val

Parameters

  • msg: String val = "Test failed"

Returns


assert_false

[Source]

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


assert_true

[Source]

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


assert_error

[Source]

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


assert_no_error

[Source]

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


assert_is[A: A]

[Source]

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


assert_isnt[A: A]

[Source]

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


assert_eq[A: (Equatable[A] #read & Stringable #read)]

[Source]

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


assert_ne[A: (Equatable[A] #read & Stringable #read)]

[Source]

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


assert_array_eq[A: (Equatable[A] #read & Stringable #read)]

[Source]

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


assert_array_eq_unordered[A: (Equatable[A] #read & Stringable #read)]

[Source]

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


expect_action

[Source]

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

Returns


complete_action

[Source]

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

Returns


fail_action

[Source]

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

Returns


complete

[Source]

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

Returns


dispose_when_done

[Source]

Dispose the actor after a property run / a shrink is done.

fun box dispose_when_done(
  disposable: DisposableActor tag)
: None val

Parameters

Returns