From 673329ddb7cfd1f4e1ee45b65ec08078dcee970c Mon Sep 17 00:00:00 2001 From: Mark Date: Sat, 3 Feb 2024 11:49:26 -0700 Subject: [PATCH] fix reverted tests, ensure files are loaded before goals (#2315) --- src/toplevel.pl | 22 ++++++++++++++----- .../cli/issues/goals_compound_goal.toml | 2 +- .../cli/issues/goals_multiple_goals.toml | 2 +- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/toplevel.pl b/src/toplevel.pl index 86ba085f..67408cd2 100644 --- a/src/toplevel.pl +++ b/src/toplevel.pl @@ -40,10 +40,21 @@ load_scryerrc :- (\+ disabled_init_file -> load_scryerrc ; true), repl. +args_consults_goals([], [], []). +args_consults_goals([Arg|Args], Consults, Goals) :- + arg_consults_goals(Arg, Args, Consults, Goals). + +arg_consults_goals(c(Mod), Args, [c(Mod)|Consults], Goals) :- + args_consults_goals(Args, Consults, Goals). +arg_consults_goals(g(Goal), Args, Consults, [g(Goal)|Goals]) :- + args_consults_goals(Args, Consults, Goals). + delegate_task([], []). delegate_task([], Goals0) :- - reverse(Goals0, Goals), (\+ disabled_init_file -> load_scryerrc ; true), + reverse(Goals0, Goals1), + args_consults_goals(Goals1, Consults, Goals), + run_goals(Consults), run_goals(Goals), repl. @@ -57,7 +68,7 @@ delegate_task([Arg0|Args], Goals0) :- !, delegate_task(Args, Goals0) ; atom_chars(Mod, Arg0), - delegate_task(Args, [t(consult(Mod))|Goals0]) + delegate_task(Args, [c(Mod)|Goals0]) ). print_help :- @@ -98,6 +109,7 @@ ignore_machine_arg. arg_type(g). arg_type(t). +arg_type(c(_)). arg_type(g(_)). arg_type(t(_)). @@ -134,12 +146,12 @@ run_goals([g(Gs0)|Goals]) :- !, write_term(Goal, [variable_names(VNs),double_quotes(DQ)]), nl ), run_goals(Goals). -run_goals([t(Goal)|Goals]) :- !, - ( catch(user:Goal, E, print_exception(E)) -> +run_goals([c(Mod)|Goals]) :- !, + ( catch(consult(Mod), E, print_exception(E)) -> true ; write('% Warning: initialization failed for: '), double_quotes_option(DQ), - write_term(Goal, [double_quotes(DQ)]), nl + write_term(consult(Mod), [double_quotes(DQ)]), nl ), run_goals(Goals). run_goals([Goal|_]) :- diff --git a/tests/scryer/cli/issues/goals_compound_goal.toml b/tests/scryer/cli/issues/goals_compound_goal.toml index 6cc3d16c..4fd7d5ba 100644 --- a/tests/scryer/cli/issues/goals_compound_goal.toml +++ b/tests/scryer/cli/issues/goals_compound_goal.toml @@ -1,2 +1,2 @@ # issue 820 -args = ["-f", "--no-add-history", "goals.pl", "-g", "test,halt"] +args = ["-f", "--no-add-history", "-g", "test,halt", "goals.pl"] diff --git a/tests/scryer/cli/issues/goals_multiple_goals.toml b/tests/scryer/cli/issues/goals_multiple_goals.toml index 676c61dc..25e739dd 100644 --- a/tests/scryer/cli/issues/goals_multiple_goals.toml +++ b/tests/scryer/cli/issues/goals_multiple_goals.toml @@ -1,2 +1,2 @@ # issue 820 -args = ["-f", "--no-add-history", "goals.pl", "-g", "test", "-g", "halt"] +args = ["-f", "--no-add-history", "-g", "test", "-g", "halt", "goals.pl"] -- 2.54.0