how to test by hand (plunit)
Ross Boylan <[email protected]>
| Newsgroups | gmane.comp.ai.prolog.swi |
|---|---|
| Message-ID | <1388438865.22575.162.camel@localhost> |
When my tests don't work sometimes I want to play around with the
functions and facts being tested. They seem to be stuck in a unit test
scope. Could someone suggest a better workflow?
Here are some highlights from the test file:
<ruleTest.plt>
:- begin_tests('disk rules').
:- ['rules.pl'].
born(xm1, when(date(2010, 1, 1), seq(10)), sony, "first fake machine").
disk(xda, when(date(2010, 1, 1), seq(20)), size(500, m), maxtor, ide, "first fake disk").
% many more fake facts
% many tests
test(rename3, [set(X = [lv(lv1, myvg), lv(lv1, mynewvg)])]) :-
same_device(lv(lv1, myvg), when(date(2010, 3, 1), seq(50)), X, _).
:- end_tests('disk rules').
</ruleTest.plt>
The predicates defined in rules.pl are not directly accessible; when I
try to use them it asks me if I want to correct them to the scope of the
tests.
?- volume_from_event(lv(lv1, myvg), when(date(2010, 3, 1), seq(40)), LV1, W1).
Correct to: "'plunit_disk rules':volume_from_event(lv(lv1,myvg),when(date(2010,3,1),seq(40)),LV1,W1)"? y
false.
I think the result is false because the decision to run the qualified
predicate does not have access to the facts defined in ruleTest.plt. I
would like to check using the fake facts of rules.plt, but those seem to
be inside the scope of the unit tests.
If I try to load the rules directly:
?- ['rules.pl'].
ERROR: load_files/2: No permission to load source `/home/ross/disks/rules.pl' (Non-module file already loaded into module plunit_disk rules; trying to load into user)
I worked around this by doing:
?- unload_file('rulesTest.plt').
true.
?- ['rules.pl'].
% various warnings
?- ['fact.pl'].
% more warnings
and then testing the rules using the "real" facts in fact.pl.
I'm hoping there's a better way.
fact.pl and rules.pl are vanilla prolog without modules.
Thanks.
Ross Boylan
And Happy New Year to all on the western calendar.