swipl-devel
swipl-devel copied to clipboard
Maybe of interest: a load_test_files/2 which also reports on files loaded and skipped
A possible extension of load_test_files/1:
It has the exact same functionality as the current load_test_files/1 but additionally instantiates a list of compound terms loaded(File)
and skipped(File)
to be able to easily collect the results of the load_test_files operation.
load_test_files(_Options,Which) :-
(nonvar(Which) -> % "Which" will be set
'$uninstantiation_error'(Which) % and thus must be uninstantiated
; true),
findall(Pair,test_file(Pair),Pairs), % collect File-TestFile pairs (load order probably unimportant)
load_test_files_2(Pairs,Which). % load and side-effect the Prolog database
test_file(File-TestFile) :-
source_file(File), % File is a previously loaded source file
file_name_extension(Base, Old, File), % and which can be decomposed into Base (maybe with path) and suffix Old
Old \== plt, % and which does not have a .plt extension
file_name_extension(Base, plt, TestFile), % and which can be recomposed into TestFile
exists_file(TestFile). % and for which TestFile exists on-disk
% ---
% Loading loop
% ---
load_test_files_2([],[]).
load_test_files_2([File-TestFile|Pairs],[skipped(TestFile)|Which]) :-
plunit:test_file_for(TestFile, File), % do nothing if already loaded
!,
load_test_files_2(Pairs,Which).
load_test_files_2([File-TestFile|Pairs],[loaded(TestFile)|Which]) :-
load_files(TestFile,
[ if(changed), % "loads the file if not loaded modified since last load"
imports([]) % "import nothing"?
]),
asserta(plunit:test_file_for(TestFile, File)),
load_test_files_2(Pairs,Which).
So for example:
?- load_test_files([],Which).
Which = [loaded('/home/user/Development/PACKING/prolog_code/tmp/texty_typetests.plt')].
?- load_test_files([],Which).
Which = [skipped('/home/user/Development/PACKING/prolog_code/tmp/texty_typetests.plt')].