3 Part of CHR
(Constraint Handling Rules
)
6 E
-mail
: wielemak
@science.uva
.nl
7 WWW
: http
://www
.swi
-prolog
.org
8 Copyright
(C
): 2005,2006, University of Amsterdam
10 This program is free software
; you can redistribute it
and/or
11 modify it under the terms of the GNU General Public License
12 as published by the Free Software Foundation
; either version
2
13 of the License
, or (at your option
) any later version
.
15 This program is distributed
in the hope that it will be useful
,
16 but WITHOUT ANY WARRANTY
; without even the implied warranty of
17 MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE
. See the
18 GNU General Public License
for more details
.
20 You should have received a copy of the GNU Lesser General Public
21 License along with this library
; if not, write to the Free Software
22 Foundation
, Inc
., 59 Temple Place
, Suite
330, Boston
, MA
02111-1307 USA
24 As a special exception
, if you
link this library with other files
,
25 compiled with a Free Software compiler
, to produce an executable
, this
26 library does
not by itself cause the resulting executable to be covered
27 by the GNU General Public License
. This exception does
not however
28 invalidate any other reasons why the executable file might be covered by
29 the GNU General Public License
.
32 :- asserta
(user
:file_search_path
(chr, '.')).
33 :- asserta
(user
:file_search_path
(library
, '.')).
34 :- use_module
(library
(chr)).
35 %% :- use_module
(chr). % == library
(chr)
37 :- set_prolog_flag
(optimise
, true
).
38 %:- set_prolog_flag
(trace_gc
, true
).
40 :- format
('CHR test suite. To run all tests run ?- test.~n~n', []).
42 /*******************************
44 *******************************/
54 assert
(script_dir
(Dir
)).
56 find_script_dir
(Dir
) :-
57 prolog_load_context
(file
, File
),
58 follow_links
(File
, RealFile
),
59 file_directory_name
(RealFile
, Dir
).
61 follow_links
(File
, RealFile
) :-
62 read_link
(File
, _
, RealFile
), !.
63 follow_links
(File
, File
).
68 run_test_script
(Script
) :-
69 file_base_name
(Script
, Base
),
70 file_name_extension
(Pred
, _
, Base
),
71 format
(' ~w~n',[Script
]),
72 load_files
(Script
, []), %[silent
(true
)]),
75 run_test_scripts
(Directory
) :-
76 ( script_dir
(ScriptDir
),
77 concat_atom
([ScriptDir
, /, Directory
], Dir
),
82 atom_concat
(Dir
, '/*.chr', Pattern
),
83 expand_file_name
(Pattern
, Files
),
84 file_base_name
(Dir
, BaseDir
),
85 format
('Running scripts from ~w ', [BaseDir
]), flush
,
91 ( catch
(run_test_script
(H
), Except
, true
)
94 ; Except
= blocked
(Reason
)
95 -> assert
(blocked
(H
, Reason
)),
97 ; script_failed
(H
, Except
)
99 ; script_failed
(H
, fail
)
103 script_failed
(File
, fail
) :-
104 format
('~NScript ~w failed~n', [File
]),
105 assert
(failed
(script
(File
))).
106 script_failed
(File
, Except
) :-
107 message_to_string
(Except
, Error
),
108 format
('~NScript ~w failed: ~w~n', [File
, Error
]),
109 assert
(failed
(script
(File
))).
112 /*******************************
114 *******************************/
123 retractall
(failed
(_
)),
124 retractall
(blocked
(_
,_
)),
130 forall
(testdir
(Dir
), run_test_scripts
(Dir
)).
134 findall
(Head
-Reason
, blocked
(Head
, Reason
), L
),
136 -> format
('~nThe following tests are blocked:~n', []),
137 ( member
(Head
-Reason
, L
),
138 format
(' ~p~t~40|~w~n', [Head
, Reason
]),
145 findall
(X
, failed
(X
), L
),
148 -> format
('~n*** ~w tests failed ***~n', [Len
]),
150 ; format
('~nAll tests passed~n', [])
153 test_failed
(R
, Except
) :-
155 functor
(Head
, Name
, 1),
156 arg
(1, Head
, TestName
),
157 clause_property
(R
, line_count
(Line
)),
158 clause_property
(R
, file
(File
)),
160 -> format
('~N~w:~d: Test ~w(~w) failed~n',
161 [File
, Line
, Name
, TestName
])
162 ; message_to_string
(Except
, Error
),
163 format
('~N~w:~d: Test ~w(~w):~n~t~8|ERROR: ~w~n',
164 [File
, Line
, Name
, TestName
, Error
])
166 assert
(failed
(Head
)).
169 throw
(blocked
(Reason
)).