Add comprehensive tests for g_caused_exception/2
Following TESTING_GUIDE.md, added tests at layers 2 and 3: Layer 2 - Prolog Integration Tests (src/tests/custom_toplevel.pl): - Test that g_caused_exception/2 is not asserted when no exception occurs - Test that g_caused_exception/2 can be checked from custom toplevel - Added check_for_exception/0 helper predicate for testing Layer 3 - CLI Tests (tests/scryer/cli/src_tests/custom_toplevel.md): - Test g_caused_exception/2 with exception thrown - Test g_caused_exception/2 with no exception - Test g_caused_exception/2 with error/2 terms - Added test helper predicates in fixtures/toplevel_test_helper.pl All tests pass successfully. Co-Authored-By: J.J.'s Robot <jjtolton@gmail.com>
This commit is contained in:
50
tests/scryer/cli/fixtures/toplevel_test_helper.pl
Normal file
50
tests/scryer/cli/fixtures/toplevel_test_helper.pl
Normal file
@@ -0,0 +1,50 @@
|
||||
% Helper predicates for testing custom toplevel functionality
|
||||
|
||||
success_toplevel :-
|
||||
write('SUCCESS_TOPLEVEL_EXECUTED'), nl,
|
||||
halt(0).
|
||||
|
||||
failure_toplevel :-
|
||||
write('FAILURE_TOPLEVEL_EXECUTED'), nl,
|
||||
halt(1).
|
||||
|
||||
exit_code_42 :-
|
||||
write('EXIT_CODE_42'), nl,
|
||||
halt(42).
|
||||
|
||||
write_and_exit :-
|
||||
write('Output from custom toplevel'), nl,
|
||||
halt(0).
|
||||
|
||||
% This one doesn't halt - to test what happens if toplevel doesn't halt
|
||||
non_halting_toplevel :-
|
||||
write('NON_HALTING_TOPLEVEL'), nl.
|
||||
|
||||
% Test that toplevel can access loaded predicates
|
||||
test_file_loaded :-
|
||||
write('LOADED_PREDICATE_CALLED'), nl,
|
||||
halt(0).
|
||||
|
||||
helper_predicate :-
|
||||
write('Helper predicate works'), nl.
|
||||
|
||||
% g_caused_exception/2 testing predicates
|
||||
:- dynamic(g_caused_exception/2).
|
||||
|
||||
check_exception_halt_1 :-
|
||||
( g_caused_exception(Goal, Exception) ->
|
||||
write('EXCEPTION_CAUGHT'), nl,
|
||||
write('Goal: '), write(Goal), nl,
|
||||
write('Exception: '), write(Exception), nl,
|
||||
halt(1)
|
||||
; write('NO_EXCEPTION'), nl,
|
||||
halt(0)
|
||||
).
|
||||
|
||||
check_exception_halt_0 :-
|
||||
( g_caused_exception(_, _) ->
|
||||
write('UNEXPECTED_EXCEPTION'), nl,
|
||||
halt(1)
|
||||
; write('SUCCESS_NO_EXCEPTION'), nl,
|
||||
halt(0)
|
||||
).
|
||||
Reference in New Issue
Block a user