如何 运行 在 prolog 中进行 plunit 测试

How to run plunit tests in prolog

我很难让 plunit 在看似最微不足道的情况下执行测试。这是我的设置:

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).

这在 swipl 中按预期工作:

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

?- x(5).
true.

?- x(6).
false.

但我似乎无法使 foo.plt 文件失败

?- 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.

test_something_else 测试用例显然应该失败了,但是 plunit 的 run_tests/0 似乎没有意识到 运行.

有任何测试

来自plunit manual

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

所以不用 test_something(x)test_something_else(x),你只需要使用 test(x).

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

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

运行 这将给出预期的输出:

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

ERROR: [...]
    test x: failed

 done
% 2 tests failed
% 0 tests passed
false.