Move g_caused_exception/2 dynamic directive to toplevel.pl
- Add dynamic directive in toplevel.pl with other module-level directives - Update test files to reference it as '':g_caused_exception/2 - Remove redundant dynamic directives from test files - All tests passing
This commit is contained in:
@@ -15,10 +15,8 @@ test_predicate :-
|
|||||||
format("Test predicate executed~n", []).
|
format("Test predicate executed~n", []).
|
||||||
|
|
||||||
% Test predicates for g_caused_exception/2
|
% Test predicates for g_caused_exception/2
|
||||||
:- dynamic(g_caused_exception/2).
|
|
||||||
|
|
||||||
check_for_exception :-
|
check_for_exception :-
|
||||||
( g_caused_exception(_Goal, Exception) ->
|
( '$toplevel':g_caused_exception(_Goal, Exception) ->
|
||||||
format("Exception occurred: ~w~n", [Exception]),
|
format("Exception occurred: ~w~n", [Exception]),
|
||||||
halt(1)
|
halt(1)
|
||||||
; format("No exception~n", []),
|
; format("No exception~n", []),
|
||||||
@@ -31,15 +29,15 @@ test("custom toplevel functionality is tested via CLI tests", (
|
|||||||
)).
|
)).
|
||||||
|
|
||||||
test("g_caused_exception/2 is not asserted when no exception occurs", (
|
test("g_caused_exception/2 is not asserted when no exception occurs", (
|
||||||
retractall(g_caused_exception(_, _)),
|
retractall('$toplevel':g_caused_exception(_, _)),
|
||||||
\+ g_caused_exception(_, _)
|
\+ '$toplevel':g_caused_exception(_, _)
|
||||||
)).
|
)).
|
||||||
|
|
||||||
test("g_caused_exception/2 can be checked from custom toplevel", (
|
test("g_caused_exception/2 can be checked from custom toplevel", (
|
||||||
% This tests the predicate structure; actual exception handling
|
% This tests the predicate structure; actual exception handling
|
||||||
% is tested via CLI tests since it requires -g and -t flags
|
% is tested via CLI tests since it requires -g and -t flags
|
||||||
retractall(g_caused_exception(_, _)),
|
retractall('$toplevel':g_caused_exception(_, _)),
|
||||||
asserta(g_caused_exception(test_goal, test_error)),
|
asserta('$toplevel':g_caused_exception(test_goal, test_error)),
|
||||||
g_caused_exception(test_goal, test_error),
|
'$toplevel':g_caused_exception(test_goal, test_error),
|
||||||
retractall(g_caused_exception(_, _))
|
retractall('$toplevel':g_caused_exception(_, _))
|
||||||
)).
|
)).
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
:- dynamic(disabled_init_file/0).
|
:- dynamic(disabled_init_file/0).
|
||||||
:- dynamic(started/0).
|
:- dynamic(started/0).
|
||||||
:- dynamic(custom_toplevel/1).
|
:- dynamic(custom_toplevel/1).
|
||||||
|
:- dynamic(g_caused_exception/2).
|
||||||
|
|
||||||
load_scryerrc :-
|
load_scryerrc :-
|
||||||
( '$home_directory'(HomeDir) ->
|
( '$home_directory'(HomeDir) ->
|
||||||
@@ -180,7 +181,7 @@ run_goals([g(Gs0)|Goals]) :- !,
|
|||||||
( write_term(Goal, [variable_names(VNs),double_quotes(DQ)]),
|
( write_term(Goal, [variable_names(VNs),double_quotes(DQ)]),
|
||||||
write(' causes: '),
|
write(' causes: '),
|
||||||
write_term(Exception, [double_quotes(DQ)]), nl,
|
write_term(Exception, [double_quotes(DQ)]), nl,
|
||||||
asserta(user:g_caused_exception(Goal, Exception))
|
asserta(g_caused_exception(Goal, Exception))
|
||||||
)
|
)
|
||||||
) -> true
|
) -> true
|
||||||
; write('% Warning: initialization failed for: '),
|
; write('% Warning: initialization failed for: '),
|
||||||
|
|||||||
@@ -29,10 +29,8 @@ helper_predicate :-
|
|||||||
format("Helper predicate works~n", []).
|
format("Helper predicate works~n", []).
|
||||||
|
|
||||||
% g_caused_exception/2 testing predicates
|
% g_caused_exception/2 testing predicates
|
||||||
:- dynamic(g_caused_exception/2).
|
|
||||||
|
|
||||||
check_exception_halt_1 :-
|
check_exception_halt_1 :-
|
||||||
( g_caused_exception(Goal, Exception) ->
|
( '$toplevel':g_caused_exception(Goal, Exception) ->
|
||||||
format("EXCEPTION_CAUGHT~n", []),
|
format("EXCEPTION_CAUGHT~n", []),
|
||||||
format("Goal: ~w~n", [Goal]),
|
format("Goal: ~w~n", [Goal]),
|
||||||
format("Exception: ~w~n", [Exception]),
|
format("Exception: ~w~n", [Exception]),
|
||||||
@@ -42,7 +40,7 @@ check_exception_halt_1 :-
|
|||||||
).
|
).
|
||||||
|
|
||||||
check_exception_halt_0 :-
|
check_exception_halt_0 :-
|
||||||
( g_caused_exception(_, _) ->
|
( '$toplevel':g_caused_exception(_, _) ->
|
||||||
format("UNEXPECTED_EXCEPTION~n", []),
|
format("UNEXPECTED_EXCEPTION~n", []),
|
||||||
halt(1)
|
halt(1)
|
||||||
; format("SUCCESS_NO_EXCEPTION~n", []),
|
; format("SUCCESS_NO_EXCEPTION~n", []),
|
||||||
|
|||||||
Reference in New Issue
Block a user