Skip to content

A unit testing library for Prolog, providing an expressive xUnit-like API for PlUnit, and significantly enhanced reporting and debugging of test failures.

License

Notifications You must be signed in to change notification settings

simonharris/plunit_assert

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

68 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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:

  1. 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 [email protected]       - 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.

About

A unit testing library for Prolog, providing an expressive xUnit-like API for PlUnit, and significantly enhanced reporting and debugging of test failures.

Resources

License

Stars

Watchers

Forks

Packages

No packages published