users-prolog
[Top][All Lists]
Advanced

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

Re: Predicate searching by wildcard or similar


From: Paulo Moura
Subject: Re: Predicate searching by wildcard or similar
Date: Tue, 5 Nov 2013 21:41:36 +0000

Hi Sean,

On 05/11/2013, at 21:27, Sean Charles <address@hidden> wrote:

> Hi,
> 
> I just wrote a *really simple* testing framework for my project, it looks 
> like this at the test script end:
> 
> test_package([it('should ensure that global values have expected settings', 
> defaults_correctly_set_test)
>            ,it('should correctly set the quiet flag on "-q"', 
> respect_quiet('-q'))
>            ,it('should correctly set the quiet flag on "--quiet"', 
> respect_quiet('--quiet'))
>            ,it('should correctly set the wrap flag on "--wrap"', respect_wrap)
>            ,it('should correctly set the check flag on "--nocheck"', 
> respect_check)
>            ,it('should add unhandled options as source filenames', 
> filename_check)
>            ,it('should throw exceptions on unknown options', 
> handle_unknown_options)
>            ]).
> 
> The test_package predicate is called from the framework by the script, the 
> script pulls in the file and that has an initialisation instruction:
> 
> :- initialization(run_tests).
> 
> run_tests :-
>       test_package(AllTests),
>       maplist(call, AllTests),
>       ink(normal, '*done*'),
>       stop.
> 
> 
> What would have made it *really* nice was to have been able to find all 
> predicates starting with test_ or ending with _test etc. so that I would not 
> have needed to make the test_package predicate unify the variable with the 
> list of tests to be run. Some tests mentioned above...
> 
> defaults_correctly_set_test :-
>       cl_set_defaults,
>       
> get_all_globals([],[],user_input,user_output,php,nowrap,check,plain,noisy).
> 
> 
> respect_quiet(Flag) :-
>       cl_set_defaults,
>       process_option(Flag),
>       get_all_globals(_,_,_,_,_,_,_,_,quiet).
> 
> 
> As you can see, having to enter the test predicate AND enter it in the test 
> package isn’t ideal ALTHOUGH it does allow me to provide a nice label but I 
> could have done that with a really long predicate name anyway.
> 
> So, how would I do that in GNU Prolog…if it is possible. The listing() 
> predicate is not much help in this instance…

You may find some inspiration on the Logtalk unit test tool, which uses the 
term-expansion mechanism in its implementation to collect the tests defined in 
an unit in order to run them. See:

https://github.com/LogtalkDotOrg/logtalk3/tree/master/tools/lgtunit

You should also be able to use it for testing your project code.

Cheers,

Paulo

-----------------------------------------------------------------
Paulo Moura
Logtalk developer

Email: <mailto:address@hidden>
Web:   <http://logtalk.org/>
-----------------------------------------------------------------







reply via email to

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