Re: how to test by hand (plunit)

Jan Wielemaker <[email protected]>
Newsgroups gmane.comp.ai.prolog.swi
Message-ID <[email protected]>
On 12/30/2013 10:27 PM, Ross Boylan wrote:
> 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.

This should work fine.  If the scoping was wrong (which should not be the
case), you would get an existence error.

The `correct' way to run a single test is

	?- run_tests('disk rules':rename3).

See http://www.swi-prolog.org/pldoc/doc_for?object=run_tests/1

	Cheers --- Jan

> 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.
> 
> 
> 
> 
> _______________________________________________
> SWI-Prolog mailing list
> [email protected]
> https://lists.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.