3

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.

Lucas Wiman
  • 10,021
  • 2
  • 37
  • 41

1 Answers1

3

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.
Steven
  • 2,437
  • 5
  • 32
  • 36
  • That works if the tests are in the same file as `foo.pl`, but fails with `test x: received error: not/1: Undefined procedure: plunit_foo:x/1` if I put the tests into `foo.plt`. How did you load the file before you issued the `run_tests` goal? Here's the error I get: https://gist.github.com/lucaswiman/7eb3390f53913f6182fa – Lucas Wiman Nov 24 '15 at 06:10
  • 1
    I ran it using [PDT](https://eclipse.org/pdt/)'s console. When I try to do the same using the normal SWI-Prolog console I get the same error as you; I'm not immediately sure how to fix that. – Steven Nov 24 '15 at 23:51
  • @RecursivelyIronic Did you happen to solve this eventually? I ran into the "Undefined procedure: plunit_foo…" problem yesterday and can't figure out how to fix it. – lemonad Sep 27 '16 at 10:09
  • 2
    @RecursivelyIronic Sorry for pinging you on such an old question, I think I got it working now by making `foo.pl` into a module and by importing it (`use_module`) in the .plt file. – lemonad Sep 27 '16 at 10:19