plunit.pl -- Unit Testing
Unit testing environment for SWI-Prolog and SICStus Prolog. For usage, please visit https://www.swi-prolog.org/pldoc/package/plunit.
- current_test_flag(?Name, ?Value) is nondet[private]
- Query flags that control the testing process. Emulates SWI-Prologs flags.
- set_test_flag(+Name, +Value) is det[private]
- set_test_options(+Options)
- Specifies how to deal with test suites. Defined options are:
- load(+Load)
- Whether or not the tests must be loaded. Values are
never
,always
,normal
(only if not optimised) - run(+When)
- When the tests are run. Values are
manual
,make
ormake(all)
. - silent(+Bool)
- If
true
(defaultfalse
), report successful tests using message levelsilent
, only printing errors and warnings. - output(+When)
- If
always
, emit all output as it is produced, ifnever
, suppress all output and ifon_failure
, emit the output if the test fails. - sto(+Bool)
- How to test whether code is subject to occurs check
(STO). If
false
(default), STO is not considered. Iftrue
and supported by the hosting Prolog, code is run in all supported unification mode and reported if the results are inconsistent. - cleanup(+Bool)
- If
true
(default =false), cleanup report at the end of run_tests/1. Used to improve cooperation with memory debuggers such as dmalloc. - concurrent(+Bool)
- If
true
(defaultfalse
), run all tests in a unit concurrently.
- loading_tests[private]
- True if tests must be loaded.
- begin_tests(+UnitName:atom) is det
- begin_tests(+UnitName:atom, Options) is det
- Start a test-unit. UnitName is the name of the test set. the
unit is ended by :-
end_tests(UnitName)
. - end_tests(+Name) is det
- Close a unit-test module.
- make_unit_module(+Name, -ModuleName) is det[private]
- unit_module(+Name, -ModuleName) is det[private]
- expand_test(+Name, +Options, +Body, -Clause) is det[private]
- Expand
test(Name, Options)
:- Body into a clause for 'unit test'/4 and 'unit body'/2. - expand(+Term, -Clauses) is semidet[private]
- valid_options(+Options, :Pred) is det[private]
- Verify Options to be a list of valid options according to Pred.
- test_option(+Option) is semidet[private]
- True if Option is a valid option for
test(Name, Options)
. - test_option(+Option) is semidet[private]
- True if Option is a valid option for :-
begin_tests(Name, Options)
. - reify(:Goal, -Result) is det[private]
- run_tests is semidet
- run_tests(+TestSet) is semidet
- Run tests and report about the results. The predicate run_tests/0 runs all known tests that are not blocked. The predicate run_tests/1 takes a specification of tests to run. This is either a single specification or a list of specifications. Each single specification is either the name of a test-unit or a term <test-unit>:<test>, denoting a single test within a unit.
- count_tests(+Spec, -Count) is det[private]
- Count the number of tests to run.
- run_tests_in_files(+Files:list) is det[private]
- Run all test-units that appear in the given Files.
- make_run_tests(+Files)[private]
- Called indirectly from make/0 after Files have been reloaded.
- run_test(+Unit, +Name, +Line, +Options, +Body) is det[private]
- Run a single test.
- test_caps(-Type, +Unit, +Name, +Line, +Options, +Body, -Result, -Key) is nondet[private]
- run_test_6(+Unit, +Name, +Line, +Options, :Body, -Result) is det[private]
- 6th step of the tests. Deals with tests that must be ignored
(blocked, conditions fails), setup and cleanup at the test level.
Result is one of:
- blocked(Unit, Name, Line, Reason)
- condition_failed(Unit, Name, Line)
- failure(Unit, Name, Line, How, Time)
- How is one of:
- succeeded
- Exception
cmp_error(Cmp, E)
wrong_answer(Cmp)
- failed
- no_exception
wrong_error(Expect, E)
wrong_answer(Expected, Bindings)
- success(Unit, Name, Line, Determinism, Time)
- setup_failed(Unit, Name, Line)
- run_test_7(+Unit, +Name, +Line, +Options, :Body, -Result) is det[private]
- This step deals with the expected outcome of the test. It runs the actual test and then compares the result to the outcome. There are two main categories: dealing with a single result and all results.
- non_det_test(+Expected, +Unit, +Name, +Line, +Options, +Body, -Result)[private]
- Run tests on non-deterministic predicates.
- result_vars(+Expected, -Vars) is det[private]
- Create a term
v(V1, ...)
containing all variables at the left side of the comparison operator on Expected. - nondet_compare(+Expected, +Bindings, +Unit, +Name, +Line) is semidet[private]
- Compare list/set results for non-deterministic predicates.
- cmp(+CmpTerm, -Left, -Op, -Right) is det[private]
- call_det(:Goal, -Det) is nondet[private]
- True if Goal succeeded. Det is unified to
true
if Goal left no choicepoints andfalse
otherwise. - match_error(+Expected, +Received) is semidet[private]
- True if the Received errors matches the expected error. Matching is based on subsumes_term/2.
- setup(+Module, +Context, +Options) is semidet[private]
- Call the setup handler and fail if it cannot run for some
reason. The condition handler is similar, but failing is not
considered an error. Context is one of
- unit(Unit)
- If it is the setup handler for a unit
- test(Unit, Name, Line)
- If it is the setup handler for a test
- condition(+Module, +Context, +Options) is semidet[private]
- Evaluate the test or test unit condition.
- call_ex(+Module, +Goal)[private]
- Call Goal in Module after applying goal expansion.
- cleanup(+Module, +Options) is det[private]
- Call the cleanup handler and succeed. Failure or error of the cleanup handler is reported, but tests continue normally.
- failure(+Unit, +Name, +Line, +How, +Time, +Options) is det[private]
- Test failed. Report the error.
- assert_cyclic(+Term) is det[private]
- Assert a possibly cyclic unit clause. Current SWI-Prolog assert/1 does not handle cyclic terms, so we emulate this using the recorded database.
- begin_test(Unit, Test, Line, STO) is det[private]
- end_test(Unit, Test, Line, STO) is det[private]
- Maintain running/5 and report a test has started/is ended using
a
silent
message:plunit(begin(Unit:Test, File:Line, STO))
plunit(end(Unit:Test, File:Line, STO))
- running_tests is det
- Print the currently running test.
- current_test(?Unit, ?Test, ?Line, ?Body, ?Options) is nondet
- True when a test with the specified properties is loaded.
- current_test_unit(?Unit, ?Options) is nondet
- True when a Unit is a current unit test declared with Options.
- test_summary(?Unit, -Summary) is det[private]
- True if there are no failures, otherwise false.
- report is det[private]
- Print a summary of the tests that ran.
- test_report(+What) is det
- Produce reports on test results after the run. Currently only
supports
fixme
for What. - current_test_set(?Unit) is nondet[private]
- True if Unit is a currently loaded test-set.
- unit_file(+Unit, -File) is det[private]
- unit_file(-Unit, +File) is nondet[private]
- load_test_files(+Options) is det
- Load .plt test-files related to loaded source-files.
- info(+Term)[private]
- Runs
print_message(Level, Term)
, where Level is one ofsilent
orinformational
(default). - user:message_hook(+Severity, +Message, +Lines) is semidet[multifile]
- Redefine printing some messages. It appears SICStus has no way to get multiple messages at the same line, so we roll our own. As there is a lot pre-wired and checked in the SICStus message handling we cannot reuse the lines. Unless I miss something ...
Undocumented predicates
The following predicates are exported, but not or incorrectly documented.