Skip to content

Commit 25d9c6e

Browse files
committed
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
1 parent dd7f361 commit 25d9c6e

File tree

3 files changed

+11
-14
lines changed

3 files changed

+11
-14
lines changed

src/tests/custom_toplevel.pl

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@
1515
format("Test predicate executed~n", []).
1616

1717
% Test predicates for g_caused_exception/2
18-
:- dynamic(g_caused_exception/2).
19-
2018
check_for_exception :-
21-
( g_caused_exception(_Goal, Exception) ->
19+
( '$toplevel':g_caused_exception(_Goal, Exception) ->
2220
format("Exception occurred: ~w~n", [Exception]),
2321
halt(1)
2422
; format("No exception~n", []),
@@ -31,15 +29,15 @@
3129
)).
3230

3331
test("g_caused_exception/2 is not asserted when no exception occurs", (
34-
retractall(g_caused_exception(_, _)),
35-
\+ g_caused_exception(_, _)
32+
retractall('$toplevel':g_caused_exception(_, _)),
33+
\+ '$toplevel':g_caused_exception(_, _)
3634
)).
3735

3836
test("g_caused_exception/2 can be checked from custom toplevel", (
3937
% This tests the predicate structure; actual exception handling
4038
% is tested via CLI tests since it requires -g and -t flags
41-
retractall(g_caused_exception(_, _)),
42-
asserta(g_caused_exception(test_goal, test_error)),
43-
g_caused_exception(test_goal, test_error),
44-
retractall(g_caused_exception(_, _))
39+
retractall('$toplevel':g_caused_exception(_, _)),
40+
asserta('$toplevel':g_caused_exception(test_goal, test_error)),
41+
'$toplevel':g_caused_exception(test_goal, test_error),
42+
retractall('$toplevel':g_caused_exception(_, _))
4543
)).

src/toplevel.pl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
:- dynamic(disabled_init_file/0).
1818
:- dynamic(started/0).
1919
:- dynamic(custom_toplevel/1).
20+
:- dynamic(g_caused_exception/2).
2021

2122
load_scryerrc :-
2223
( '$home_directory'(HomeDir) ->
@@ -180,7 +181,7 @@
180181
( write_term(Goal, [variable_names(VNs),double_quotes(DQ)]),
181182
write(' causes: '),
182183
write_term(Exception, [double_quotes(DQ)]), nl,
183-
asserta(user:g_caused_exception(Goal, Exception))
184+
asserta(g_caused_exception(Goal, Exception))
184185
)
185186
) -> true
186187
; write('% Warning: initialization failed for: '),

tests/scryer/cli/fixtures/toplevel_test_helper.pl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,8 @@
2929
format("Helper predicate works~n", []).
3030

3131
% g_caused_exception/2 testing predicates
32-
:- dynamic(g_caused_exception/2).
33-
3432
check_exception_halt_1 :-
35-
( g_caused_exception(Goal, Exception) ->
33+
( '$toplevel':g_caused_exception(Goal, Exception) ->
3634
format("EXCEPTION_CAUGHT~n", []),
3735
format("Goal: ~w~n", [Goal]),
3836
format("Exception: ~w~n", [Exception]),
@@ -42,7 +40,7 @@
4240
).
4341

4442
check_exception_halt_0 :-
45-
( g_caused_exception(_, _) ->
43+
( '$toplevel':g_caused_exception(_, _) ->
4644
format("UNEXPECTED_EXCEPTION~n", []),
4745
halt(1)
4846
; format("SUCCESS_NO_EXCEPTION~n", []),

0 commit comments

Comments
 (0)