Update tests to use format/2 instead of write/1

This commit is contained in:
J.J. Tolton
2025-11-09 12:05:23 -05:00
parent b91ce76052
commit 95abc4017e
2 changed files with 18 additions and 18 deletions

View File

@@ -4,24 +4,24 @@
% Helper predicates for CLI testing % Helper predicates for CLI testing
custom_halt :- custom_halt :-
write('Custom toplevel executed'), nl, format("Custom toplevel executed~n", []),
halt(0). halt(0).
custom_halt_with_code :- custom_halt_with_code :-
write('Custom toplevel with exit code'), nl, format("Custom toplevel with exit code~n", []),
halt(42). halt(42).
test_predicate :- test_predicate :-
write('Test predicate executed'), nl. format("Test predicate executed~n", []).
% Test predicates for g_caused_exception/2 % Test predicates for g_caused_exception/2
:- dynamic(g_caused_exception/2). :- dynamic(g_caused_exception/2).
check_for_exception :- check_for_exception :-
( g_caused_exception(_Goal, Exception) -> ( g_caused_exception(_Goal, Exception) ->
write('Exception occurred: '), write(Exception), nl, format("Exception occurred: ~w~n", [Exception]),
halt(1) halt(1)
; write('No exception'), nl, ; format("No exception~n", []),
halt(0) halt(0)
). ).

View File

@@ -1,50 +1,50 @@
% Helper predicates for testing custom toplevel functionality % Helper predicates for testing custom toplevel functionality
success_toplevel :- success_toplevel :-
write('SUCCESS_TOPLEVEL_EXECUTED'), nl, format("SUCCESS_TOPLEVEL_EXECUTED~n", []),
halt(0). halt(0).
failure_toplevel :- failure_toplevel :-
write('FAILURE_TOPLEVEL_EXECUTED'), nl, format("FAILURE_TOPLEVEL_EXECUTED~n", []),
halt(1). halt(1).
exit_code_42 :- exit_code_42 :-
write('EXIT_CODE_42'), nl, format("EXIT_CODE_42~n", []),
halt(42). halt(42).
write_and_exit :- write_and_exit :-
write('Output from custom toplevel'), nl, format("Output from custom toplevel~n", []),
halt(0). halt(0).
% This one doesn't halt - to test what happens if toplevel doesn't halt % This one doesn't halt - to test what happens if toplevel doesn't halt
non_halting_toplevel :- non_halting_toplevel :-
write('NON_HALTING_TOPLEVEL'), nl. format("NON_HALTING_TOPLEVEL~n", []).
% Test that toplevel can access loaded predicates % Test that toplevel can access loaded predicates
test_file_loaded :- test_file_loaded :-
write('LOADED_PREDICATE_CALLED'), nl, format("LOADED_PREDICATE_CALLED~n", []),
halt(0). halt(0).
helper_predicate :- helper_predicate :-
write('Helper predicate works'), nl. format("Helper predicate works~n", []).
% g_caused_exception/2 testing predicates % g_caused_exception/2 testing predicates
:- dynamic(g_caused_exception/2). :- dynamic(g_caused_exception/2).
check_exception_halt_1 :- check_exception_halt_1 :-
( g_caused_exception(Goal, Exception) -> ( g_caused_exception(Goal, Exception) ->
write('EXCEPTION_CAUGHT'), nl, format("EXCEPTION_CAUGHT~n", []),
write('Goal: '), write(Goal), nl, format("Goal: ~w~n", [Goal]),
write('Exception: '), write(Exception), nl, format("Exception: ~w~n", [Exception]),
halt(1) halt(1)
; write('NO_EXCEPTION'), nl, ; format("NO_EXCEPTION~n", []),
halt(0) halt(0)
). ).
check_exception_halt_0 :- check_exception_halt_0 :-
( g_caused_exception(_, _) -> ( g_caused_exception(_, _) ->
write('UNEXPECTED_EXCEPTION'), nl, format("UNEXPECTED_EXCEPTION~n", []),
halt(1) halt(1)
; write('SUCCESS_NO_EXCEPTION'), nl, ; format("SUCCESS_NO_EXCEPTION~n", []),
halt(0) halt(0)
). ).