From 8bf3d4ea71f9b2603b0e8408203412c9eaa637ab Mon Sep 17 00:00:00 2001 From: Mark Thom Date: Sat, 9 Apr 2022 20:32:52 -0600 Subject: [PATCH] fix tests, use '$first_answer' to print indentation before errors (#1408) --- src/loader.pl | 9 ++++++++- src/machine/project_attributes.pl | 6 ++---- src/tests/clpz/test_clpz.pl | 2 +- src/toplevel.pl | 6 +++--- tests/scryer/issues.rs | 9 ++------- tests/scryer/src_tests.rs | 2 +- 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/loader.pl b/src/loader.pl index 9a130375..ebc81d6c 100644 --- a/src/loader.pl +++ b/src/loader.pl @@ -18,7 +18,14 @@ write_error(Error) :- - write(' '), + % '$fetch_global_var' is the core system call of bb_get/2, but + % bb_get may not exist when write_error is first called, so fall + % back on '$fetch_global_var'. + ( '$fetch_global_var'('$first_answer', false) -> + true + ; write(' ') % if '$first_answer' isn't defined yet or true, + % print indentation. + ), ( nonvar(Error), functor(Error, error, 2) -> writeq(Error) diff --git a/src/machine/project_attributes.pl b/src/machine/project_attributes.pl index e62b2278..ae2054e3 100644 --- a/src/machine/project_attributes.pl +++ b/src/machine/project_attributes.pl @@ -10,8 +10,7 @@ project_attributes(QueryVars, AttrVars) :- ; E = error(evaluation_error((Module:project_attributes)/2), _) ) -> true - ; write_term('caught: ', [quoted(false)]), - writeq(E), + ; loader:write_error(E), nl ). @@ -34,8 +33,7 @@ call_attribute_goals([Module|Modules], GoalCaller, AttrVars) :- '$print_attribute_goals_exception'(Module, E) :- ( E = error(evaluation_error((Module:attribute_goals)/3), attribute_goals/3) -> true - ; write_term('caught: ', [quoted(false)]), - writeq(E), + ; loader:write_error(E), nl ). diff --git a/src/tests/clpz/test_clpz.pl b/src/tests/clpz/test_clpz.pl index 98fd827b..9b55bfd5 100644 --- a/src/tests/clpz/test_clpz.pl +++ b/src/tests/clpz/test_clpz.pl @@ -100,7 +100,7 @@ run :- Dss ), E, - ( write('caught: '), write(E), nl, + ( loader:write_error(E), nl, portray_clause([N, Settings, Vs, Gs4, Dss]), nl, false ) diff --git a/src/toplevel.pl b/src/toplevel.pl index a6b14e1d..171b76d5 100644 --- a/src/toplevel.pl +++ b/src/toplevel.pl @@ -134,6 +134,7 @@ run_goals([Goal|_]) :- halt. repl :- + bb_put('$first_answer', true), catch(read_and_match, E, print_exception(E)), false. %% this is for GC, until we get actual GC. repl :- @@ -198,9 +199,8 @@ submit_query_and_print_results(Term0, VarList) :- % in the first argument, which is done by call/N ; expand_goal(Term0, user, Term) ), - setup_call_cleanup(bb_put('$first_answer', true), - submit_query_and_print_results_(Term, VarList), - bb_put('$first_answer', false)). + bb_put('$first_answer', true), + submit_query_and_print_results_(Term, VarList). needs_bracketing(Value, Op) :- diff --git a/tests/scryer/issues.rs b/tests/scryer/issues.rs index 12440851..2db08402 100644 --- a/tests/scryer/issues.rs +++ b/tests/scryer/issues.rs @@ -29,12 +29,7 @@ fn do_not_duplicate_path_components() { ['tests-pl/issue852-throw_e.pl'].\n\ halt.\n\ ", - "\ - caught: e\n \ - false.\n\ - caught: e\n \ - false.\n\ - ", + " throw(e)\n false.\n throw(e)\n false.\n", ); } @@ -170,6 +165,6 @@ fn ignored_constraint() { fn call_0() { load_module_test( "tests-pl/issue831-call0.pl", - "caught: error(existence_error(procedure,call/0),call/0)\n", + " error(existence_error(procedure,call/0),call/0)\n", ); } diff --git a/tests/scryer/src_tests.rs b/tests/scryer/src_tests.rs index 2b6adbd5..3dcd6560 100644 --- a/tests/scryer/src_tests.rs +++ b/tests/scryer/src_tests.rs @@ -30,7 +30,7 @@ fn hello_world() { fn syntax_error() { load_module_test( "tests-pl/syntax_error.pl", - "caught: error(syntax_error(incomplete_reduction),read_term/3:6)\n", + " error(syntax_error(incomplete_reduction),read_term/3:6)\n", ); } -- 2.54.0