diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2023-11-22 09:50:41 +0100 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2023-11-22 09:50:41 +0100 |
commit | 11defdcf845b5ee74d4da5de581079f14c9d0729 (patch) | |
tree | 38dc0f39a271a8799d97fe0178c8ecddbd3dc296 /ip | |
parent | 5d27abfa7096a638892d40b381366cdad26b6382 (diff) | |
download | prolog-firewall-11defdcf845b5ee74d4da5de581079f14c9d0729.tar.gz prolog-firewall-11defdcf845b5ee74d4da5de581079f14c9d0729.tar.bz2 prolog-firewall-11defdcf845b5ee74d4da5de581079f14c9d0729.tar.xz prolog-firewall-11defdcf845b5ee74d4da5de581079f14c9d0729.zip |
wip
Diffstat (limited to 'ip')
-rw-r--r-- | ip/ip_test.pl | 65 | ||||
-rw-r--r-- | ip/test.pl | 62 |
2 files changed, 66 insertions, 61 deletions
diff --git a/ip/ip_test.pl b/ip/ip_test.pl index b2812f6..75d5117 100644 --- a/ip/ip_test.pl +++ b/ip/ip_test.pl @@ -2,6 +2,7 @@ :- use_module(library(clpz)). :- use_module(library(format)). +:- use_module(test). test("ip4", ( make_ip4(127, 0, 0, 1, Addr), @@ -64,64 +65,6 @@ test("ip_parse #3", ( )). main :- - consult(ip), - findall(test(Name, Goal), test(Name, Goal), Tests), - run_tests(Tests, Failed), - show_failed(Failed), - halt. - -main_quiet :- - consult(ip), - 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). + consult(ip), + findall(test(Name, Goal), test(Name, Goal), Tests), + test:test_main(Tests). @@ -0,0 +1,62 @@ +:- module(test, [ + test_main/0, + test_main/1]). + +:- use_module(library(format)). + +test_main :- + findall(test(Name, Goal), test(Name, Goal), Tests), + run_tests(Tests, Failed), + show_failed(Failed), + halt. + +test_main(Tests) :- + run_tests(Tests, Failed), + show_failed(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). |