Lucas Wiman
Lucas Wiman

Reputation: 11217

How to run plunit tests in prolog

I'm having difficulty getting plunit to execute tests in seeemingly the most trivial case. Here's my setup:

foo.pl

x(5) :- !.
not(x(6)).

foo.plt

:- begin_tests(foo).
test_something(x) :- not(x(5)).

test_seomthing_else(x) :- x(6).
:- end_tests(foo).

This works as expected in swipl:

?- [foo].
% foo compiled 0.00 sec, 3 clauses
true.

?- x(5).
true.

?- x(6).
false.

But I can't seem to get the foo.plt file to fail

?- load_test_files(foo).
% /tmp/example/foo.plt compiled into plunit 0.00 sec, 4 clauses
true.

?- run_tests.
% PL-Unit: foo  done
% No tests to run
true.

The test_something_else testcase should clearly be failing, but plunit's run_tests/0 seems unaware there are any tests to run.

Upvotes: 3

Views: 3458

Answers (1)

Steven
Steven

Reputation: 2477

From the plunit manual:

The entry points are defined by rules using the head test(Name) or test(Name, Options) [...]

So instead of having test_something(x) and test_something_else(x), you need to simply use test(x).

:- begin_tests(foo).
test(x) :- not(x(5)).

test(x) :- x(6).
:- end_tests(foo).

Running this will give the expected output:

?- run_tests.
% PL-Unit: foo 
ERROR: [...]
    test x: failed

ERROR: [...]
    test x: failed

 done
% 2 tests failed
% 0 tests passed
false.

Upvotes: 3

Related Questions