users-prolog
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Predicate ordering when using current_predicate/1


From: Daniel Diaz
Subject: Re: Predicate ordering when using current_predicate/1
Date: Fri, 22 Nov 2013 17:53:03 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.1.0

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

reply via email to

[Prev in Thread] Current Thread [Next in Thread]