3 E
-mail
: jan
@swi.psy
.uva
.nl
5 Copyright
(C
) 1996 University of Amsterdam
. All rights reserved
.
8 :- asserta
(user
:file_search_path
(chr, '.')).
9 :- asserta
(user
:file_search_path
(library
, '.')).
10 :- use_module
(chr). % == library
(chr)
12 :- set_prolog_flag
(optimise
, true
).
13 %:- set_prolog_flag
(trace_gc
, true
).
15 :- format
('CHR test suite. To run all tests run ?- test.~n~n', []).
17 % Required to get this always running regardless of user LANG setting
.
18 % Without this the tests won
't run on machines with -for example- LANG=ja
19 % according to NIDE Naoyuki, nide@ics.nara-wu.ac.jp. Thanks!
21 :- getenv('LANG
', _) -> setenv('LANG
', 'C
'); true.
24 /*******************************
26 *******************************/
36 assert(script_dir(Dir)).
38 find_script_dir(Dir) :-
39 prolog_load_context(file, File),
40 follow_links(File, RealFile),
41 file_directory_name(RealFile, Dir).
43 follow_links(File, RealFile) :-
44 read_link(File, _, RealFile), !.
45 follow_links(File, File).
50 run_test_script(Script) :-
51 file_base_name(Script, Base),
52 file_name_extension(Pred, _, Base),
53 load_files(Script, []), %[silent(true)]),
56 run_test_scripts(Directory) :-
57 ( script_dir(ScriptDir),
58 concat_atom([ScriptDir, /, Directory], Dir),
63 atom_concat(Dir, '/*.chr', Pattern),
64 expand_file_name(Pattern, Files),
65 file_base_name(Dir, BaseDir),
66 format('Running scripts from
~w
', [BaseDir]), flush,
72 ( catch(run_test_script(H), Except, true)
75 ; Except = blocked(Reason)
76 -> assert(blocked(H, Reason)),
78 ; script_failed(H, Except)
80 ; script_failed(H, fail)
84 script_failed(File, fail) :-
85 format('~NScript
~w failed
~n
', [File]),
86 assert(failed(script(File))).
87 script_failed(File, Except) :-
88 message_to_string(Except, Error),
89 format('~NScript
~w failed
: ~w
~n
', [File, Error]),
90 assert(failed(script(File))).
93 /*******************************
95 *******************************/
104 retractall(failed(_)),
105 retractall(blocked(_,_)),
111 forall(testdir(Dir), run_test_scripts(Dir)).
115 findall(Head-Reason, blocked(Head, Reason), L),
117 -> format('~nThe following tests are blocked
:~n
', []),
118 ( member(Head-Reason, L),
119 format(' ~p
~t
~40|~w
~n
', [Head, Reason]),
126 findall(X, failed(X), L),
129 -> format('~n
*** ~w tests failed
***~n
', [Len]),
131 ; format('~nAll tests passed
~n
', [])
134 test_failed(R, Except) :-
136 functor(Head, Name, 1),
137 arg(1, Head, TestName),
138 clause_property(R, line_count(Line)),
139 clause_property(R, file(File)),
141 -> format('~N
~w
:~d
: Test
~w
(~w
) failed
~n
',
142 [File, Line, Name, TestName])
143 ; message_to_string(Except, Error),
144 format('~N
~w
:~d
: Test
~w
(~w
):~n
~t
~8|ERROR
: ~w
~n
',
145 [File, Line, Name, TestName, Error])
147 assert(failed(Head)).
150 throw(blocked(Reason)).