Re: how to test by hand (plunit)

Ross Boylan <[email protected]>
Newsgroups gmane.comp.ai.prolog.swi
Message-ID <1388701490.22575.205.camel@localhost>
On Wed, 2014-01-01 at 11:27 +0100, Jan Wielemaker wrote:
> 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.  
Sometimes it seems OK, sometimes not.  In the example below, the fact
about lvcreate is accessible at top level, but within the call to
'plunit_disk rules':bf03m it is not, apparently because lvcreate is
qualified by 'plunit_disk rules'.

Here is a session, which earlier had
[funk]  % 2 lines, defining lvcreate for lv(amd64, daisy) and bf03m
['rulesTest.plt'] % which include rules.pl and some fake lvcreate facts.
run_tests.  % some pass some don't

The bf03m predicate I attempt to use below is defined in rules.pl.


[trace]  ?- lvcreate(lv(amd64, daisy), _, W).  % here the lvcreate fact is accessible
   Call: (6) lvcreate(lv(amd64, daisy), _G1923, _G1924) ? 
   Exit: (6) lvcreate(lv(amd64, daisy), unknownsize, when(date(2012, 11, 12), seq(20))) ? 
W = when(date(2012, 11, 12), seq(20)).

[trace]  ?- 'plunit_disk rules':bf03m(_G1922, lv(amd64, daisy), _G1925).
   Call: (6) 'plunit_disk rules':bf03m(_G2254, lv(amd64, daisy), _G2256) ? 
   Call: (7) 'plunit_disk rules':lvcreate(lv(amd64, daisy), _G2354, _G2256) ? 
   Fail: (7) 'plunit_disk rules':lvcreate(lv(amd64, daisy), _G2354, _G2256) ? % and here it is not
   Fail: (6) 'plunit_disk rules':bf03m(_G2254, lv(amd64, daisy), _G2256) ? 
false.

The full transcript is attached.
https://bitbucket.org/RossBoylan/disks/commits/188ad814db35144479a554190d45b03e6fe4266d
is the current commit; the other files are available there if you want
to look (rulesTest.pl, rules.pl and fact.pl are operative).

I've already deleted funk.pl, but it was
lvcreate(lv('amd64', 'daisy'), unknownsize, when(date(2012, 11, 12), seq(20))).
bf03m(SrcVG, lv(LV, SrcVG), When) :- lvcreate(lv(LV, SrcVG), _Size, When).

Maybe the fact that bf03m was defined at top level (via [funk]) triggers
this behavior.



> 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
> 
My interest wasn't so much in re-running a particular test but in
executing other queries against the same set of facts as used in the
test suite.

Ross
> > 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
> > 

-------------- next part --------------
Welcome to SWI-Prolog (Multi-threaded, 64 bits, Version 6.4.1)
Copyright (c) 1990-2013 University of Amsterdam, VU Amsterdam
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to redistribute it under certain conditions.
Please visit http://www.swi-prolog.org for details.

For help, use ?- help(Topic). or ?- apropos(Word).

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

?- lvcreate(lv(LV, daisy), _, W).
LV = amd64,
W = when(date(2012, 11, 12), seq(20)).

?- bf03m(Src, lv(amd64, daisy), W).
false.

?- lvcreate(lv(amd64, daisy), _, W).
W = when(date(2012, 11, 12), seq(20)).

?- bf03m(daisy, lv(amd64, daisy), W).
false.

?- make.
% /home/ross/disks/funk compiled 0.00 sec, 1 clauses
true.

?- bf03m(daisy, lv(amd64, daisy), W).
W = when(date(2012, 11, 12), seq(20)).

?- [rulesTest.plt].
ERROR: Syntax error: Operator expected
ERROR: [rulesTest
ERROR: ** here **
ERROR: .plt] . 
?- ['rulesTest.plt'].
%   ordered compiled into ordered 0.00 sec, 23 clauses
Warning: /home/ross/disks/rules.pl:710:
	Singleton variables: [W]
Warning: /home/ross/disks/rules.pl:715:
	Singleton variables: [W]
Warning: /home/ross/disks/rules.pl:731:
	Singleton variables: [LV]
Warning: /home/ross/disks/rules.pl:734:
	Singleton variables: [LV]
Warning: /home/ross/disks/rules.pl:735:
	Singleton variables: [LV]
Warning: /home/ross/disks/rules.pl:781:
	Singleton variables: [W0,W1,LV,VG]
Warning: /home/ross/disks/rules.pl:968:
	Clauses of plunit_disk rules:portray/1 are not together in the source-file
Warning: /home/ross/disks/rules.pl:974:
	Clauses of plunit_disk rules:portray/1 are not together in the source-file
%  rules.pl compiled into plunit_disk rules 0.00 sec, 135 clauses
Warning: /home/ross/disks/rulesTest.plt:37:
	Singleton variables: [G]
% rulesTest.plt compiled 0.02 sec, 506 clauses
true.

?- run_tests.
% PL-Unit: disk rules ...
ERROR: /home/ross/disks/rulesTest.plt:88:
	test content1: wrong answer (compared using ==)
ERROR:     Expected: real_ideal([],[])
ERROR:     Got:      real_ideal([path([osfirst1,oldhome])],[xda1])
ERROR: /home/ross/disks/rulesTest.plt:99:
	test content2: wrong answer (compared using ==)
ERROR:     Expected: real_ideal([],[])
ERROR:     Got:      real_ideal([path([osfirst1,oldhome])],[xda1])
ERROR: /home/ross/disks/rulesTest.plt:109:
	test rename1: received error: </2: Arguments are not sufficiently instantiated
ERROR: /home/ross/disks/rulesTest.plt:111:
	test rename2: received error: </2: Arguments are not sufficiently instantiated
ERROR: /home/ross/disks/rulesTest.plt:118:
	test rename3: wrong "set" answer:
ERROR:     Expected: [lv(lv1,mynewvg),lv(lv1,myvg)]
ERROR:        Found: [lv(lvold,mynewvg),lv(lvold,myvg)]
 done
% 5 tests failed
% 3 tests passed
false.

?- block_ancestors(lv(amd64, daisy), now, G).
Correct to: "'plunit_disk rules':block_ancestors(lv(amd64,daisy),now,G)"? y
G = graph([], []).

?- block_for(Src, lv(amd64, daisy), now, W).
Correct to: "'plunit_disk rules':block_for(Src,lv(amd64,daisy),now,W)"? y
false.

?- bf03m(Src, lv(amd64, daisy), now, W).
ERROR: Undefined procedure: bf03m/4
ERROR:     However, there are definitions for:
ERROR:         bf03m/3
false.

?- bf03m(Src, lv(amd64, daisy), W).
Src = daisy,
W = when(date(2012, 11, 12), seq(20)).

?- debug.
true.

[debug]  ?- 'plunit_disk rules':block_for(Src,lv(amd64,daisy),now,W).
false.

[debug]  ?- 'plunit_disk rules':block_for(Src, lv(amd64,daisy), now, W).
false.

[debug]  ?- trace.
true.

[trace]  ?- 'plunit_disk rules':block_for(Src, lv(amd64,daisy), now, W).
   Call: (6) 'plunit_disk rules':block_for(_G1922, lv(amd64, daisy), now, _G1925) ? ?
Options:
+:                  spy        -:              no spy
/c|e|r|f|u|a goal:  find       .:              repeat find
a:                  abort      A:              alternatives
b:                  break      c (ret, space): creep
[depth] d:          depth      e:              exit
f:                  fail       [ndepth] g:     goals (backtrace)
h (?):              help       i:              ignore
l:                  leap       L:              listing
n:                  no debug   p:              print
r:                  retry      s:              skip
u:                  up         w:              write
m:		      exception details
C:                  toggle show context
   Call: (6) 'plunit_disk rules':block_for(_G1922, lv(amd64, daisy), now, _G1925) ? 
^  Call: (7) setof(candidate(_G1922, lv(amd64, daisy), _G1925), bf01(_G1922, lv(amd64, daisy), now, _G1925), _G2031) ? l
false.

[debug]  ?- 'plunit_disk rules':block_for(Src, lv(amd64,daisy), now, W).
false.

[debug]  ?- trace.
true.

[trace]  ?- 'plunit_disk rules':block_for(Src, lv(amd64,daisy), now, W).
   Call: (6) 'plunit_disk rules':block_for(_G1922, lv(amd64, daisy), now, _G1925) ? 
^  Call: (7) setof(candidate(_G1922, lv(amd64, daisy), _G1925), bf01(_G1922, lv(amd64, daisy), now, _G1925), _G2031) ? s
^  Fail: (7) setof(candidate(_G1922, lv(amd64, daisy), _G1925), 'plunit_disk rules':bf01(_G1922, lv(amd64, daisy), now, _G1925), _G2034) ? s
   Redo: (6) 'plunit_disk rules':block_for(_G1922, lv(amd64, daisy), now, _G1925) ? 
   Call: (7) 'plunit_disk rules':bf03m(_G1922, lv(amd64, daisy), _G1925) ? 
   Call: (8) 'plunit_disk rules':lvcreate(lv(amd64, daisy), _G2024, _G1925) ? 
   Fail: (8) 'plunit_disk rules':lvcreate(lv(amd64, daisy), _G2024, _G1925) ? 
   Fail: (7) 'plunit_disk rules':bf03m(_G1922, lv(amd64, daisy), _G1925) ? 
   Redo: (6) 'plunit_disk rules':block_for(_G1922, lv(amd64, daisy), now, _G1925) ? 
   Call: (7) 'plunit_disk rules':mountPath(_G1922, lv(amd64, daisy), now, _G1925) ? 
   Fail: (7) 'plunit_disk rules':mountPath(_G1922, lv(amd64, daisy), now, _G1925) ? 
   Redo: (6) 'plunit_disk rules':block_for(_G1922, lv(amd64, daisy), now, _G1925) ? 
^  Call: (7) findall(candidate(_G1922, lv(amd64, daisy), _G2015), bf04(_G1922, lv(amd64, daisy), now, _G2015), _G2031) ? 
   Call: (12) 'plunit_disk rules':bf04(_G1922, lv(amd64, daisy), now, _G2015) ? 
   Call: (13) 'plunit_disk rules':partition(lv(amd64, daisy), _G1922, _G2015, _G2049) ? s
   Fail: (13) 'plunit_disk rules':partition(lv(amd64, daisy), _G1922, _G2015, _G2049) ? 
   Fail: (12) 'plunit_disk rules':bf04(_G1922, lv(amd64, daisy), now, _G2015) ? s
^  Exit: (7) findall(candidate(_G1922, lv(amd64, daisy), _G2015), 'plunit_disk rules':bf04(_G1922, lv(amd64, daisy), now, _G2015), []) ? 
^  Call: (7) apply:maplist(bf05, [], _G2048) ? 
   Call: (8) apply:maplist_([], _G2050, 'plunit_disk rules':bf05) ? 
   Exit: (8) apply:maplist_([], [], 'plunit_disk rules':bf05) ? 
^  Exit: (7) apply:maplist('plunit_disk rules':bf05, [], []) ? 
   Call: (7) sort([], _G2050) ? 
   Exit: (7) sort([], []) ? 
   Call: (7) lists:member(lv(amd64, daisy), []) ? 
   Fail: (7) lists:member(lv(amd64, daisy), []) ? 
   Fail: (6) 'plunit_disk rules':block_for(_G1922, lv(amd64, daisy), now, _G1925) ? 
false.

[trace]  ?- lvcreate(lv(amd64, daisy), _, W).
   Call: (6) lvcreate(lv(amd64, daisy), _G1923, _G1924) ? 
   Exit: (6) lvcreate(lv(amd64, daisy), unknownsize, when(date(2012, 11, 12), seq(20))) ? 
W = when(date(2012, 11, 12), seq(20)).

[trace]  ?- 'plunit_disk rules':bf03m(_G1922, lv(amd64, daisy), _G1925) ?
|    .
ERROR: Syntax error: Unbalanced operator
ERROR: 'plunit_disk rules':bf03m(_G1922, lv(amd64, daisy), _G1925) ? 
ERROR: ** here **
ERROR: . 
[trace]  ?- 'plunit_disk rules':bf03m(_G1922, lv(amd64, daisy), _G1925).
   Call: (6) 'plunit_disk rules':bf03m(_G2006, lv(amd64, daisy), _G2008) ? 
   Call: (7) 'plunit_disk rules':lvcreate(lv(amd64, daisy), _G2106, _G2008) ? 
   Fail: (7) 'plunit_disk rules':lvcreate(lv(amd64, daisy), _G2106, _G2008) ? 
   Fail: (6) 'plunit_disk rules':bf03m(_G2006, lv(amd64, daisy), _G2008) ? f
false.

[trace]  ?- 'plunit_disk rules':bf03m(_G1922, lv(amd64, daisy), _G1925).
   Call: (6) 'plunit_disk rules':bf03m(_G2254, lv(amd64, daisy), _G2256) ? 
   Call: (7) 'plunit_disk rules':lvcreate(lv(amd64, daisy), _G2354, _G2256) ? 
   Fail: (7) 'plunit_disk rules':lvcreate(lv(amd64, daisy), _G2354, _G2256) ? 
   Fail: (6) 'plunit_disk rules':bf03m(_G2254, lv(amd64, daisy), _G2256) ? 
false.

[trace]  ?-
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.