Skip to main content

Assertions

This topic describes the functions available for making assertions within tests. These functions are used to verify expected conditions and behaviors, ensuring the correctness of the code under test.

assert_equals(actual: T, expected: T)

Asserts that two values are equal.

Parameters:

  • actual: T - The actual value to compare.
  • expected: T - The expected value.

Throws: An exception if the values are not equal.

assert_not_equals(actual: T, expected: T)

Asserts that two values are not equal.

Parameters:

  • actual: T - The actual value to compare.
  • expected: T - The value that should not be equal to the actual value.

Throws: An exception if the values are equal.

assert_true(actual: boolean)

Asserts that the value is "true".

Parameters:

  • actual: boolean - The boolean value to test.

Throws: An exception if the value is not "true".

assert_false(actual: boolean)

Asserts that the value is "false".

Parameters:

  • actual: boolean - The boolean value to test.

Throws: An exception if the value is not "false".

assert_null(actual: T?)

Asserts that the value is null.

Parameters:

  • actual: T? - The value to test for nullity.

Throws: An exception if the value is not null.

assert_not_null(actual: T?)

Asserts that the value is not null.

Parameters:

  • actual: T? - The value to test for non-nullity.

Throws: An exception if the value is null.

assert_lt(actual: T, expected: T)

Asserts that the actual value is less than the expected value.

Parameters:

  • actual: T - The actual value to compare.
  • expected: T - The expected value.

Throws: An exception if the actual value is not less than the expected value.

assert_gt(actual: T, expected: T)

Asserts that the actual value is greater than the expected value.

Parameters:

  • actual: T - The actual value to compare.
  • expected: T - The expected value.

Throws: An exception if the actual value is not greater than the expected value.

assert_le(actual: T, expected: T)

Asserts that the actual value is less than or equal to the expected value.

Parameters:

  • actual: T - The actual value to compare.
  • expected: T - The expected value.

Throws: An exception if the actual value is not less than or equal to the expected value.

assert_ge(actual: T, expected: T)

Asserts that the actual value is greater than or equal to the expected value.

Parameters:

  • actual: T - The actual value to compare.
  • expected: T - The expected value.

Throws: An exception if the actual value is not greater than or equal to the expected value.

assert_gt_lt(actual: T, min: T, max: T)

Asserts that the actual value is greater than min and less than max.

Parameters:

  • actual: T - The actual value to compare.
  • min: T - The minimum value.
  • max: T - The maximum value.

Throws: An exception if the actual value is not within the specified range.

assert_gt_le(actual: T, min: T, max: T)

Asserts that the actual value is greater than min and less than or equal to max.

Parameters:

  • actual: T - The actual value to compare.
  • min: T - The minimum value.
  • max: T - The maximum value.

Throws: An exception if the actual value is not within the specified range.

assert_ge_lt(actual: T, min: T, max: T)

Asserts that the actual value is greater than or equal to min and less than max.

Parameters:

  • actual: T - The actual value to compare.
  • min: T - The minimum value.
  • max: T - The maximum value.

Throws: An exception if the actual value is not within the specified range.

assert_ge_le(actual: T, min: T, max: T)

Asserts that the actual value is greater than or equal to min and less than or equal to max.

Parameters:

  • actual: T - The actual value to compare.
  • min: T - The minimum value.
  • max: T - The maximum value.

Throws: An exception if the actual value is not within the specified range.

assert_events(expected: (text, gtv)...)

Checks whether the list of events emitted during the last block execution matches the expected list of events.

Parameters:

  • expected: (text, gtv)... - A list of tuples, where each tuple represents an expected event with its name and Global Type Value (gtv).

Throws: An exception if the actual events do not match the expected events.

rell.test.get_events(): list<(text, gtv)>

Returns the list of events emitted during the last block execution.

Returns: A list of tuples, where each tuple represents an event with its name and gtv.

assert_fails(f: () -> unit): rell.test.failure

Asserts that a function fails.

Parameters:

  • f: () -> unit - The function to test for failure.

Returns: A rell.test.failure object containing information about the failure, if the function fails.

Throws: An exception if the function does not fail.

Optional Parameter:

  • expected: text - If specified, the actual error message must contain the expected text.

Partial function for assert_fails()

Use partial function application to pass a function to assert_fails(). For example:

function foo(x: integer) {
require(x >= 0, "x is negative: " + x);
}
...
assert_fails(foo(-123, *)); // OK
assert_fails("x is negative: -123", foo(-123, *)); // OK
assert_fails(foo(123, *)); // Fails

Use the returned value if non-exact error message matching is needed:

val f = assert_fails(foo(-123, *));
assert_true(f.message.starts_with("x is negative: "));