plunit_assert

PlUnit is a unit testing library for Prolog. Its goals are:

  1. provide a more expressive and familiar API for PlUnit by implementing xUnit-like test predicates such as assert_true/1 and assert_type/2
  2. provide significantly more helpful and user-friendly feedback on test fail
  3. full compatibility with PlUnit: you can still use assertion/1 if you wish Whilst this wasn't an explicit design goal initially, another benefit of plunit_assert is:
  4. it can easily be leveraged by calling its test predicates directly within the Prolog REPL, which can be a trying experience with manual calls to assertion/1. See this in action under Examples below.

API Documentation

The API documentation is generated by PlDoc and the latest is always available here:

https://simonharris.github.io/plunit_assert/

Installation

Packages are hosted here:

https://packages.pointbeing.net/plunit_assert/

Thus, the current version of the library can be installed using:

?- pack_install(plunit_assert, [url('https://packages.pointbeing.net/plunit_assert/plunit_assert-0.2.1.tgz')]).

It is also discoverable via pack_list/1:

?- pack_list(plunit_assert).
% Contacting server at https://www.swi-prolog.org/pack/query ... ok
p plunit_assert@0.2.1       - An expressive xUnit-like API for PlUnit with more helpful fail messages
true.

?- pack_install(plunit_assert).
...etc...

Examples

?- assert_type(3.0, boolean).
[plunit_assert] Asserted 3.0 is of type 'boolean' but got 'float'
false.
?- assert_equals(3+1, 4).
true.

?- assert_is(3+1, 4).
[plunit_assert] Asserted identity but 3+1 and 4 are not identical
false.
?- assert_lte(3^7, 6+9.6).
[plunit_assert] Comparison failed: 3^7 (2187) is not less than or equal to 6+9.6 (15.6)
false.

Prolog files

plunit_assert.pl  -- The test API for plunit_assert
assert_equals/2This is a superset of assert_is/2 and arithmetic comparison with =:=.
assert_false/1Test that Goal fails and therefore is falsy.
assert_gt/2Test that A is greater than B.
assert_gte/2Test that A is greater than or equal to B.
assert_in/2Test that Var is in Collection.
assert_is/2Test that A and B are identical terms.
assert_is_not/2Test that A and B are not identical terms.
assert_lt/2Test that A is less than B.
assert_lte/2Test that A is less than or equal to B.
assert_not_equals/2Test that A and B are not equal terms.
assert_not_in/2Test that Var is not in Collection.
assert_not_type/2Test that Var is not of type Type.
assert_not_unbound/1Test that Var is not unbound.
assert_output/3Test that a predicate's output arguments match what is expected.
assert_test_fails/1Meta test to check that Goal would trigger a PlUnit test fail.
assert_test_message/2Meta test to check we get roughly the right fail messages back.
assert_test_passes/1Meta test to check that Goal would not trigger a PlUnit test fail.
assert_true/1Test that Goal succeeds and therefore is truthy.
assert_type/2Test that Var is of type Type.
assert_unbound/1Test that Var is unbound.