]> Repositorios git - scryer-prolog.git/commitdiff
use common test_framework module for several test suites
authorMark Thom <[email protected]>
Wed, 10 Apr 2024 21:46:52 +0000 (15:46 -0600)
committerMark Thom <[email protected]>
Wed, 10 Apr 2024 21:47:31 +0000 (15:47 -0600)
src/loader.pl
src/tests/dif.pl
src/tests/ground.pl
src/tests/term_variables.pl
src/tests/test_framework.pl [new file with mode: 0644]
src/tests/when.pl
tests/scryer/cli/src_tests/dif_tests.toml
tests/scryer/cli/src_tests/ground_tests.toml
tests/scryer/cli/src_tests/term_variables_tests.toml
tests/scryer/cli/src_tests/when_tests.toml

index cdfbf4f9530e8e352127a554f4b18715ba7a1ced..0998182d1ad767e4af095c2ae69541f1d3ceaf92 100644 (file)
@@ -890,7 +890,7 @@ expand_call_goal_(UnexpandedGoals, Module, ExpandedGoals) :-
           goal_expansion(UnexpandedGoals1, user, Goals),
           (  predicate_property(Module:Goals, meta_predicate(MetaSpecs0)),
              MetaSpecs0 =.. [_ | MetaSpecs] ->
-             expand_module_names(Goals, MetaSpecs, Module, ExpandedGoals, HeadVars, TGs)
+             expand_module_names(Goals, MetaSpecs, Module, ExpandedGoals, [], [])
           ;  ExpandedGoals = Goals
           )
        ;  ExpandedGoals = UnexpandedGoals1
index c7dfbdd7b7257ade5644b112c5ac7ad1fe80c1d9..3a41895b73e22459a519b3811ff62988bcfbfbdc 100644 (file)
@@ -1,5 +1,7 @@
 /**/
 
+:- module(dif_tests, []).
+
 :- use_module(library(dcgs)).
 :- use_module(library(format)).
 :- use_module(library(lists)).
@@ -7,10 +9,30 @@
 :- use_module(library(iso_ext)).
 :- use_module(library(dif)).
 
+:- use_module(test_framework).
+
+assert_p(A, B) :-
+    phrase(portray_clause_(A), Portrayed),
+    phrase((B, ".\n"), Portrayed).
+
+:- meta_predicate call_residual_goals(0, ?).
+
+call_residual_goals(Goal, ResidualGoals) :-
+    call_residue_vars(Goal, Vars),
+    variables_residual_goals(Vars, ResidualGoals).
+
+variables_residual_goals(Vars, Goals) :-
+    phrase(variables_residual_goals(Vars), Goals).
+
+variables_residual_goals([]) --> [].
+variables_residual_goals([Var|Vars]) -->
+    dif:attribute_goals(Var),
+    variables_residual_goals(Vars).
+
 % Tests from https://www.complang.tuwien.ac.at/ulrich/iso-prolog/dif
 
 test("dif#1",(
-    call_residual_goals(dif(1,2), Res),
+    call_residual_goals(dif_tests:dif(1,2), Res),
     Res = []
 )).
 
@@ -19,7 +41,7 @@ test("dif#2",(
 )).
 
 test("dif#3",(
-    call_residual_goals((dif(1,Y), Y=2), Res),
+    call_residual_goals(dif_tests:(dif(1,Y), Y=2), Res),
     Y == 2,
     Res = []
 )).
@@ -47,40 +69,40 @@ test("dif#8",(
 % I don't understand exactly what is expected for dif#9 and dif#10
 
 test("dif#11",(
-    call_residual_goals((X=Y, dif(X-Y,1-2)), Res),
+    call_residual_goals(dif_tests:(X=Y, dif(X-Y,1-2)), Res),
     X == Y,
     Res = []
 )).
 
 test("dif#12",(
-    call_residual_goals((dif(X-Y,1-2), X=Y), Res),
+    call_residual_goals(dif_tests:(dif(X-Y,1-2), X=Y), Res),
     X == Y,
     Res = []
 )).
 
 test("dif#13",(
-    call_residual_goals((X=Y, Y=1, dif(X-Y,1-2)), Res),
+    call_residual_goals(dif_tests:(X=Y, Y=1, dif(X-Y,1-2)), Res),
     X == 1,
     Y == 1,
     Res = []
 )).
 
 test("dif#14",(
-    call_residual_goals((dif(X-Y,1-2), X=Y, Y=1), Res),
+    call_residual_goals(dif_tests:(dif(X-Y,1-2), X=Y, Y=1), Res),
     X == 1,
     Y == 1,
     Res = []
 )).
 
 test("dif#15",(
-    call_residual_goals((dif(X-Y,1-2), X=Y, X=2), Res),
+    call_residual_goals(dif_tests:(dif(X-Y,1-2), X=Y, X=2), Res),
     X == 2,
     Y == 2,
     Res = []
 )).
 
 test("dif#16",(
-    call_residual_goals((dif(A-C,B-D), C-D=z-z, A-B=1-2), Res),
+    call_residual_goals(dif_tests:(dif(A-C,B-D), C-D=z-z, A-B=1-2), Res),
     A == 1,
     B == 2,
     C == z,
@@ -89,7 +111,7 @@ test("dif#16",(
 )).
 
 test("dif#17",(
-    call_residual_goals((A-B=1-2, C-D=z-z, dif(A-C,B-D)), Res),
+    call_residual_goals(dif_tests:(A-B=1-2, C-D=z-z, dif(A-C,B-D)), Res),
     A == 1,
     B == 2,
     C == z,
@@ -98,32 +120,32 @@ test("dif#17",(
 )).
 
 test("dif#18",(
-    call_residual_goals((dif(A,[C|B]), A=[[]|_], A=[B]), Res),
+    call_residual_goals(dif_tests:(dif(A,[C|B]), A=[[]|_], A=[B]), Res),
     A == [[]],
     B == [],
     Res = [dif:dif([[]], [C])]
 )).
 
 test("dif#19",(
-    call_residual_goals((dif([E],[/]), E=1), Res),
+    call_residual_goals(dif_tests:(dif([E],[/]), E=1), Res),
     E == 1,
     Res = []
 )).
 
 test("dif#20",(
-    call_residual_goals((dif([a],B), B=[_|_], B=[b]), Res),
+    call_residual_goals(dif_tests:(dif([a],B), B=[_|_], B=[b]), Res),
     B == [b],
     Res = []
 )).
 
 test("dif#21",(
-    call_residual_goals((dif([],A), A = [_]), Res),
+    call_residual_goals(dif_tests:(dif([],A), A = [_]), Res),
     A = [_],
     Res = []
 )).
 
 test("dif#22",(
-    call_residual_goals((A = [_], dif([],A)), Res),
+    call_residual_goals(dif_tests:(A = [_], dif([],A)), Res),
     A = [_],
     Res = []
 )).
@@ -140,7 +162,7 @@ test("dif#t2",(
 
 test("dif#t3",(
     set_prolog_flag(occurs_check, false),
-    call_residual_goals((-X=X, dif(X,1)), Res),
+    call_residual_goals(dif_tests:(-X=X, dif(X,1)), Res),
     X == -X,
     Res = []
 )).
@@ -172,26 +194,26 @@ test("dif#o1",(
 
 test("dif#o2",(
     set_prolog_flag(occurs_check, true),
-    call_residual_goals((dif(-X,X)), Res),
+    call_residual_goals(dif_tests:(dif(-X,X)), Res),
     Res = []
 )).
 
 test("dif#o3",(
     set_prolog_flag(occurs_check, true),
-    call_residual_goals((dif(-X,Y), X=Y), Res),
+    call_residual_goals(dif_tests:(dif(-X,Y), X=Y), Res),
     X == Y,
     Res = []
 )).
 
 test("dif#12 but with multiple variables in the residuals",(
-    call_residual_goals((dif(X-Y-_, 1-2-3), X = Y), Res),
+    call_residual_goals(dif_tests:(dif(X-Y-_, 1-2-3), X = Y), Res),
     X == Y,
     Res = []
 )).
 
 % https://github.com/mthom/scryer-prolog/issues/1956
 test("scryer-prolog#1956",(
-    call_residue_vars((dif(a-a,X-_),X=b), Res),
+    call_residue_vars(dif_tests:(dif(a-a,X-_),X=b), Res),
     X == b,
     Res = []
 )).
@@ -213,65 +235,3 @@ test("scryer-prolog#2175",(
     A=_C*[],
     A=[]*D*B,D=[]
 )).
-
-main :-
-    findall(test(Name, Goal), test(Name, Goal), Tests),
-    run_tests(Tests, Failed),
-    show_failed(Failed),
-    halt.
-
-main_quiet :-
-    findall(test(Name, Goal), test(Name, Goal), Tests),
-    run_tests_quiet(Tests, Failed),
-    (   Failed = [] ->
-        format("All tests passed", [])
-    ;   format("Some tests failed", [])
-    ),
-    halt.
-
-portray_failed_([]) --> [].
-portray_failed_([F|Fs]) -->
-    "\"", F, "\"",  "\n", portray_failed_(Fs).
-
-portray_failed([]) --> [].
-portray_failed([F|Fs]) -->
-    "\n", "Failed tests:", "\n", portray_failed_([F|Fs]).
-
-show_failed(Failed) :-
-    phrase(portray_failed(Failed), F),
-    format("~s", [F]).
-
-run_tests([], []).
-run_tests([test(Name, Goal)|Tests], Failed) :-
-    format("Running test \"~s\"~n", [Name]),
-    (   call(Goal) ->
-        Failed = Failed1
-    ;   format("Failed test \"~s\"~n", [Name]),
-        Failed = [Name|Failed1]
-    ),
-    run_tests(Tests, Failed1).
-
-run_tests_quiet([], []).
-run_tests_quiet([test(Name, Goal)|Tests], Failed) :-
-    (   call(Goal) ->
-        Failed = Failed1
-    ;   Failed = [Name|Failed1]
-    ),
-    run_tests_quiet(Tests, Failed1).
-
-assert_p(A, B) :-
-    phrase(portray_clause_(A), Portrayed),
-    phrase((B, ".\n"), Portrayed).
-
-call_residual_goals(Goal, ResidualGoals) :-
-    call_residue_vars(Goal, Vars),
-    variables_residual_goals(Vars, ResidualGoals).
-
-variables_residual_goals(Vars, Goals) :-
-    phrase(variables_residual_goals(Vars), Goals).
-
-variables_residual_goals([]) --> [].
-variables_residual_goals([Var|Vars]) -->
-    dif:attribute_goals(Var),
-    variables_residual_goals(Vars).
-
index 09c398c00c7430612d65c29b0833c59e2537bff8..beacdd657a8cbc87a20ad3e2a7e16852cdd10e8a 100644 (file)
@@ -1,11 +1,11 @@
 /**/
 
-:- use_module(library(format)).
-:- use_module(library(dcgs)).
-:- use_module(library(lists)).
-:- use_module(library(debug)).
+:- module(ground_tests, []).
+
 :- use_module(library(atts)).
 
+:- use_module(test_framework).
+
 :- attribute a/1.
 
 a(Var) :- put_atts(Var, +a(hello)).
@@ -36,48 +36,3 @@ test("ground#2075",(
     _=_B*_,_D=_B*_A,_B=_B*_D,\+ ground(_B),
     A=[A|B],B=A*B,ground(A)
 )).
-
-main :-
-    findall(test(Name, Goal), test(Name, Goal), Tests),
-    run_tests(Tests, Failed),
-    show_failed(Failed),
-    halt.
-
-main_quiet :-
-    findall(test(Name, Goal), test(Name, Goal), Tests),
-    run_tests_quiet(Tests, Failed),
-    (   Failed = [] ->
-        format("All tests passed", [])
-    ;   format("Some tests failed", [])
-    ),
-    halt.
-
-run_tests([], []).
-run_tests([test(Name, Goal)|Tests], Failed) :-
-    format("Running test \"~s\"~n", [Name]),
-    (   call(Goal) ->
-        Failed = Failed1
-    ;   format("Failed test \"~s\"~n", [Name]),
-        Failed = [Name|Failed1]
-    ),
-    run_tests(Tests, Failed1).
-
-run_tests_quiet([], []).
-run_tests_quiet([test(Name, Goal)|Tests], Failed) :-
-    (   call(Goal) ->
-        Failed = Failed1
-    ;   Failed = [Name|Failed1]
-    ),
-    run_tests_quiet(Tests, Failed1).
-
-portray_failed_([]) --> [].
-portray_failed_([F|Fs]) -->
-    "\"", F, "\"",  "\n", portray_failed_(Fs).
-
-portray_failed([]) --> [].
-portray_failed([F|Fs]) -->
-    "\n", "Failed tests:", "\n", portray_failed_([F|Fs]).
-
-show_failed(Failed) :-
-    phrase(portray_failed(Failed), F),
-    format("~s", [F]).
index f3ef5b322009f1977a712271ff2de508dff2ef65..2fae094b9bd6e34868930d39bf9390437630cd2d 100644 (file)
@@ -1,9 +1,8 @@
 /**/
 
-:- use_module(library(format)).
-:- use_module(library(dcgs)).
-:- use_module(library(lists)).
-:- use_module(library(debug)).
+:- module(term_variables_tests, []).
+
+:- use_module(test_framework).
 
 test("term_variables#1400", (
     term_variables(A+B*C/B-D, Vars),
@@ -70,48 +69,3 @@ termt3(T) :-
    T4 = [A|_],
    T3 = A,
    T0 = A.
-
-main :-
-    findall(test(Name, Goal), test(Name, Goal), Tests),
-    run_tests(Tests, Failed),
-    show_failed(Failed),
-    halt.
-
-main_quiet :-
-    findall(test(Name, Goal), test(Name, Goal), Tests),
-    run_tests_quiet(Tests, Failed),
-    (   Failed = [] ->
-        format("All tests passed", [])
-    ;   format("Some tests failed", [])
-    ),
-    halt.
-
-run_tests([], []).
-run_tests([test(Name, Goal)|Tests], Failed) :-
-    format("Running test \"~s\"~n", [Name]),
-    (   call(Goal) ->
-        Failed = Failed1
-    ;   format("Failed test \"~s\"~n", [Name]),
-        Failed = [Name|Failed1]
-    ),
-    run_tests(Tests, Failed1).
-
-run_tests_quiet([], []).
-run_tests_quiet([test(Name, Goal)|Tests], Failed) :-
-    (   call(Goal) ->
-        Failed = Failed1
-    ;   Failed = [Name|Failed1]
-    ),
-    run_tests_quiet(Tests, Failed1).
-
-portray_failed_([]) --> [].
-portray_failed_([F|Fs]) -->
-    "\"", F, "\"",  "\n", portray_failed_(Fs).
-
-portray_failed([]) --> [].
-portray_failed([F|Fs]) -->
-    "\n", "Failed tests:", "\n", portray_failed_([F|Fs]).
-
-show_failed(Failed) :-
-    phrase(portray_failed(Failed), F),
-    format("~s", [F]).
diff --git a/src/tests/test_framework.pl b/src/tests/test_framework.pl
new file mode 100644 (file)
index 0000000..58a522a
--- /dev/null
@@ -0,0 +1,49 @@
+:- module(test_framework, [main/1, main_quiet/1]).
+
+:- use_module(library(dcgs)).
+:- use_module(library(format)).
+
+main(TestModule) :-
+    findall(test(Name, TestModule:Goal), TestModule:test(Name, Goal), Tests),
+    run_tests(Tests, Failed),
+    show_failed(Failed),
+    halt.
+
+main_quiet(TestModule) :-
+    findall(test(Name, TestModule:Goal), TestModule:test(Name, Goal), Tests),
+    run_tests_quiet(Tests, Failed),
+    (   Failed = [] ->
+        format("All tests passed", [])
+    ;   format("Some tests failed", [])
+    ),
+    halt.
+
+portray_failed_([]) --> [].
+portray_failed_([F|Fs]) -->
+    "\"", F, "\"",  "\n", portray_failed_(Fs).
+
+portray_failed([]) --> [].
+portray_failed([F|Fs]) -->
+    "\n", "Failed tests:", "\n", portray_failed_([F|Fs]).
+
+show_failed(Failed) :-
+    phrase(portray_failed(Failed), F),
+    format("~s", [F]).
+
+run_tests([], []).
+run_tests([test(Name, Goal)|Tests], Failed) :-
+    format("Running test \"~s\"~n", [Name]),
+    (   call(Goal) ->
+        Failed = Failed1
+    ;   format("Failed test \"~s\"~n", [Name]),
+        Failed = [Name|Failed1]
+    ),
+    run_tests(Tests, Failed1).
+
+run_tests_quiet([], []).
+run_tests_quiet([test(Name, Goal)|Tests], Failed) :-
+    (   call(Goal) ->
+        Failed = Failed1
+    ;   Failed = [Name|Failed1]
+    ),
+    run_tests_quiet(Tests, Failed1).
index 7356e42ee17dd32c79e9fa0fa67d456640b4fc0e..20e0600c479f7efa9e4bebb9338c01d471adbaaf 100644 (file)
@@ -1,13 +1,11 @@
 /**/
 
-:- use_module(library(iso_ext)).
-:- use_module(library(format)).
-:- use_module(library(dcgs)).
-:- use_module(library(lists)).
-:- use_module(library(debug)).
+:- module(when_tests, []).
 
 :- use_module(library(when)).
 
+:- use_module(test_framework).
+
 test("condition true before ground/1",(
     A = 1,
     when(ground(A), Run = true),
@@ -81,65 +79,3 @@ test("multiple when/2 on same variable",(
     B = 1,
     Run2 == true
 )).
-
-main :-
-    findall(test(Name, Goal), test(Name, Goal), Tests),
-    run_tests(Tests, Failed),
-    show_failed(Failed),
-    halt.
-
-main_quiet :-
-    findall(test(Name, Goal), test(Name, Goal), Tests),
-    run_tests_quiet(Tests, Failed),
-    (   Failed = [] ->
-        format("All tests passed", [])
-    ;   format("Some tests failed", [])
-    ),
-    halt.
-
-portray_failed_([]) --> [].
-portray_failed_([F|Fs]) -->
-    "\"", F, "\"",  "\n", portray_failed_(Fs).
-
-portray_failed([]) --> [].
-portray_failed([F|Fs]) -->
-    "\n", "Failed tests:", "\n", portray_failed_([F|Fs]).
-
-show_failed(Failed) :-
-    phrase(portray_failed(Failed), F),
-    format("~s", [F]).
-
-run_tests([], []).
-run_tests([test(Name, Goal)|Tests], Failed) :-
-    format("Running test \"~s\"~n", [Name]),
-    (   call(Goal) ->
-        Failed = Failed1
-    ;   format("Failed test \"~s\"~n", [Name]),
-        Failed = [Name|Failed1]
-    ),
-    run_tests(Tests, Failed1).
-
-run_tests_quiet([], []).
-run_tests_quiet([test(Name, Goal)|Tests], Failed) :-
-    (   call(Goal) ->
-        Failed = Failed1
-    ;   Failed = [Name|Failed1]
-    ),
-    run_tests_quiet(Tests, Failed1).
-
-assert_p(A, B) :-
-    phrase(portray_clause_(A), Portrayed),
-    phrase((B, ".\n"), Portrayed).
-
-call_residual_goals(Goal, ResidualGoals) :-
-    call_residue_vars(Goal, Vars),
-    variables_residual_goals(Vars, ResidualGoals).
-
-variables_residual_goals(Vars, Goals) :-
-    phrase(variables_residual_goals(Vars), Goals).
-
-variables_residual_goals([]) --> [].
-variables_residual_goals([Var|Vars]) -->
-    dif_:attribute_goals(Var),
-    variables_residual_goals(Vars).
-
index 62665be2cc659872364b858850a8bd1915e58712..cc537bcb8fa2d44555dc87e96a77919cd1aa4f80 100644 (file)
@@ -1 +1 @@
-args = ["-f", "--no-add-history", "src/tests/dif.pl", "-f", "-g", "main_quiet"]
+args = ["-f", "--no-add-history", "src/tests/dif.pl", "-f", "-g", "use_module(library(dif_tests)), dif_tests:main_quiet(dif_tests)"]
index d7925bb78c943b580bcc2950b6da6c0bed42a2a2..9cbb3c3f2310ecaaef98745896f38542c34a4b18 100644 (file)
@@ -1 +1 @@
-args = ["-f", "--no-add-history", "src/tests/ground.pl", "-f", "-g", "main_quiet"]
+args = ["-f", "--no-add-history", "src/tests/ground.pl", "-f", "-g", "use_module(library(ground_tests)), ground_tests:main_quiet(ground_tests)"]
index 6d75921e71106a41fe24a84efe8f15fb3dc7c607..2b3291bf71d5c674c8c953087ab207309661bc41 100644 (file)
@@ -1 +1 @@
-args = ["-f", "--no-add-history", "src/tests/term_variables.pl", "-f", "-g", "main_quiet"]
+args = ["-f", "--no-add-history", "src/tests/term_variables.pl", "-f", "-g", "use_module(library(term_variables_tests)),term_variables_tests:main_quiet(term_variables_tests)"]
index ff0a53300bacc5fb61b728e9f170608394c20756..1b57e457f50d67b89b58406401c5a329155bd08f 100644 (file)
@@ -1 +1 @@
-args = ["-f", "--no-add-history", "src/tests/when.pl", "-f", "-g", "main_quiet"]
+args = ["-f", "--no-add-history", "src/tests/when.pl", "-f", "-g", "use_module(library(when_tests)), when_tests:main_quiet(when_tests)"]