-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest.pro
More file actions
99 lines (81 loc) · 2.48 KB
/
Copy pathtest.pro
File metadata and controls
99 lines (81 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
% Run main/0 to run all automatic tests.
% -------------------- things to be tested
:- import(file("sketch_browser.pro"),[
browser/1
]).
:- import(file("test_auto.pro"),[
test/1 as test_auto
, run/1 as run_test_auto
]).
:- import(file("test_manual.pro"),[
test/1 as test_manual
, run/1 as run_test_manual
]).
test(auto:A) :- test_auto(A).
test(manual:A) :- test_manual(A).
run(auto:A) :- run_test_auto(A).
run(manual:A) :- run_test_manual(A).
run(manual:_, skip) :- !.
run(Name, ok) :- run(Name), !.
run(_, fail) :- !.
test_position(Name, Index/Total) :-
findall(A, test(A), Names),
length(Names, Total),
nth1(Index, Names, Name).
:- dynamic known/1.
test_result(Name, Result) :-
test(Name), known(test_result(Name,A)),
A = Result.
test_result(Name, Result) :-
test(Name), \+ known(test_result(Name,_)),
run(Name, A),
assertz(known(test_result(Name,A))),
A = Result.
% -------------------- imperative
main :-
format("~`=t~30| Test began at ~@.\n", [show_time]),
retractall(known(_)),
run_tests,
summarize,
format("~`=t~30| Test ended at ~@.\n", [show_time]).
% Sometimes main/0 is reserved.
test_main :- main.
show_time :-
current_output(Out),
get_time(Time),
format_time(Out, '%F %T %Z', Time).
run_tests :-
forall(test_position(Test, Index/Max), (
format("~`-t~30| [~w/~w] ~w\n", [Index,Max,Test]),
test_result(Test, Result),
report(Test, Result)
)).
report(Test, skip) :- !, format("~`-t~30| \e[1mskip\e[22m: ~w\n",[Test]).
report(Test, fail) :- !, format("~`-t~30| \e[1mfail\e[22m: ~w\n",[Test]).
report(_, _) :- !.
summarize :-
count(test(_), Count),
count(test_result(_, skip), SkipCount),
count(test_result(_, fail), FailCount),
format("~`=t~30| Summary\n", []),
format("Number of tests : ~w\n", [Count]),
format("Number of skipped tests : ~w\n", [SkipCount]),
format("Number of failed tests : ~w\n", [FailCount]),
format("~`=t~30| Failed tests\n", []),
(FailCount =< 0
-> write("There are no failed tests at this time,\n"),
write("but this should not be taken to mean that the software does not contain errors.\n")
; forall(test_result(Test,fail), (
test_position(Test, Pos),
format("[~w] ~w\n", [Pos,Test])
))
).
count(Goal, Count) :-
F = count(0), (
call(Goal),
arg(1, F, M),
N is M + 1,
nb_setarg(1, F, N),
fail
; F = count(Count)
).