Daniel,
Your answers always leave me wondering why I didn’t see the “obvious” for myself…sigh. Well, I immediately went and read the relevant documentation and so I am sure I would have figured it out had I the intelligence to find predicate_property/2 myself!
I smell a good “meta-level” application coming on god dammit. I am never gong to finish my main project at this rate as I keep getting side-tracked by other shiny possibilities!
Armed with this then I will attempt now to re-jig my test framework and then complete the Redis client and put it out there for public consumption… I will probably make it compatible with SWI as well as it is pretty simple.
Thanks again, All the best. Sean.
Hi,
here is a piece of code doing what you want
get_tests(L) :-
setof(t(File, Line, Name), get_one_test(File, Line,
Name), L).
get_one_test(File, Line, Name) :-
current_predicate(Name/0),
atom_concat('test_', _, Name),
predicate_property(Name, prolog_file(File)),
predicate_property(Name, prolog_line(Line)).
This returns a list containing triplets t(File, Line, Name)
where File is the file pathname of the test, Line
is the line number in the source file and Name the test
name (beginning by test_). The list is sorted on File
and then on Line.
I keep the File in case your tests reside in different files, if
it is not the case you simplify the code by removing everything
related to File (including predicate_property(...,
prolog_line(Line))).
If you only need the list of test names (and don't want the File
and Line), you can define
get_tests_name(AllTests) :-
get_tests(L),
findall(Name, member(t(_,_,Name), L), AllTests).
Then get_test_names does the job.
Daniel
Le 21/11/2013 16:48, emacstheviking a écrit :
Hi,
There is no mention of the actual order of returned
predicates, recently I created a testing framework and it has
this line of code thanks to Daniel,
findall(Name,(current_predicate(Name/0),
atom_concat('test_', _, Name)),AllTests)
I am writing tests now that rely upon them being executed
in the order that they are defined in the source file i.e. the
temporal order in which they were added to the database I
presume.
However, they do not seem to come out in the expected order
unless I have done something wrong but the above line of code
is what dictates the order of execution.
Sean.
--
Ce message a été vérifié par
MailScanner
pour des virus ou des polluriels et rien de
suspect n'a été trouvé.
|