From 9a05ca0667427a3494f31f0041742c5a098fd8bd Mon Sep 17 00:00:00 2001 From: Skgland Date: Tue, 2 Jan 2024 19:51:09 +0100 Subject: [PATCH 01/10] add failing test for os:argv issue See https://github.com/mthom/scryer-prolog/pull/2263#issuecomment-1874400820 --- tests/scryer/cli/issues/os_argv.stderr | 0 tests/scryer/cli/issues/os_argv.stdin | 4 ++++ tests/scryer/cli/issues/os_argv.stdout | 4 ++++ tests/scryer/cli/issues/os_argv.toml | 2 ++ 4 files changed, 10 insertions(+) create mode 100644 tests/scryer/cli/issues/os_argv.stderr create mode 100644 tests/scryer/cli/issues/os_argv.stdin create mode 100644 tests/scryer/cli/issues/os_argv.stdout create mode 100644 tests/scryer/cli/issues/os_argv.toml diff --git a/tests/scryer/cli/issues/os_argv.stderr b/tests/scryer/cli/issues/os_argv.stderr new file mode 100644 index 000000000..e69de29bb diff --git a/tests/scryer/cli/issues/os_argv.stdin b/tests/scryer/cli/issues/os_argv.stdin new file mode 100644 index 000000000..c19efbcdb --- /dev/null +++ b/tests/scryer/cli/issues/os_argv.stdin @@ -0,0 +1,4 @@ +os:argv(V). +os:argv(["test1"|_]). +os:argv(["--"|_]). +os:argv(["test2"|_]). diff --git a/tests/scryer/cli/issues/os_argv.stdout b/tests/scryer/cli/issues/os_argv.stdout new file mode 100644 index 000000000..d62a739dc --- /dev/null +++ b/tests/scryer/cli/issues/os_argv.stdout @@ -0,0 +1,4 @@ + V = ["test1","--","test2"]. + true. + false. + false. diff --git a/tests/scryer/cli/issues/os_argv.toml b/tests/scryer/cli/issues/os_argv.toml new file mode 100644 index 000000000..831d0fddd --- /dev/null +++ b/tests/scryer/cli/issues/os_argv.toml @@ -0,0 +1,2 @@ +# https://github.com/mthom/scryer-prolog/pull/2263#issuecomment-1874400820 +args = ["-f", "--no-add-history", "--", "test1", "--", "test2"] From 91df5338342110e929b0ac124f527311f3c54b7c Mon Sep 17 00:00:00 2001 From: Skgland Date: Tue, 2 Jan 2024 19:55:27 +0100 Subject: [PATCH 02/10] fix os:argv/1 --- src/lib/os.pl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/lib/os.pl b/src/lib/os.pl index a991bd6c0..e3c287e68 100644 --- a/src/lib/os.pl +++ b/src/lib/os.pl @@ -137,7 +137,8 @@ argv(Argv) :- can_be(list, Argv), '$argv'(Argv0), - ( append(_, ["--"|Argv], Argv0) -> + ( append(Argv1, ["--"|Argv], Argv0) -> + \+ member("--", Argv1), true ; Argv = [] ). From 38f25af47de61b43810e1855d6f35cede8980984 Mon Sep 17 00:00:00 2001 From: Skgland Date: Tue, 2 Jan 2024 20:23:53 +0100 Subject: [PATCH 03/10] cover trailing `--` and `os:argv([])` in os_argv test --- tests/scryer/cli/issues/os_argv.stdin | 1 + tests/scryer/cli/issues/os_argv.stdout | 3 ++- tests/scryer/cli/issues/os_argv.toml | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/scryer/cli/issues/os_argv.stdin b/tests/scryer/cli/issues/os_argv.stdin index c19efbcdb..e6f56a723 100644 --- a/tests/scryer/cli/issues/os_argv.stdin +++ b/tests/scryer/cli/issues/os_argv.stdin @@ -2,3 +2,4 @@ os:argv(V). os:argv(["test1"|_]). os:argv(["--"|_]). os:argv(["test2"|_]). +os:argv([]). diff --git a/tests/scryer/cli/issues/os_argv.stdout b/tests/scryer/cli/issues/os_argv.stdout index d62a739dc..c07dff8ec 100644 --- a/tests/scryer/cli/issues/os_argv.stdout +++ b/tests/scryer/cli/issues/os_argv.stdout @@ -1,4 +1,5 @@ - V = ["test1","--","test2"]. + V = ["test1","--","test2","--"]. true. false. false. + false. diff --git a/tests/scryer/cli/issues/os_argv.toml b/tests/scryer/cli/issues/os_argv.toml index 831d0fddd..62b83a7ae 100644 --- a/tests/scryer/cli/issues/os_argv.toml +++ b/tests/scryer/cli/issues/os_argv.toml @@ -1,2 +1,2 @@ # https://github.com/mthom/scryer-prolog/pull/2263#issuecomment-1874400820 -args = ["-f", "--no-add-history", "--", "test1", "--", "test2"] +args = ["-f", "--no-add-history", "--", "test1", "--", "test2", "--"] From 6fc340c4dbf28aebe1e5f18074ac17d2601541e4 Mon Sep 17 00:00:00 2001 From: Skgland Date: Tue, 2 Jan 2024 20:27:14 +0100 Subject: [PATCH 04/10] remove unnecessary `true` --- src/lib/os.pl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/lib/os.pl b/src/lib/os.pl index e3c287e68..152077aea 100644 --- a/src/lib/os.pl +++ b/src/lib/os.pl @@ -138,7 +138,6 @@ can_be(list, Argv), '$argv'(Argv0), ( append(Argv1, ["--"|Argv], Argv0) -> - \+ member("--", Argv1), - true + \+ member("--", Argv1) ; Argv = [] ). From 7537686d8f336f6c7849c71c8bcfcd99ff07f93b Mon Sep 17 00:00:00 2001 From: Skgland Date: Tue, 2 Jan 2024 20:48:38 +0100 Subject: [PATCH 05/10] cover both args ending in `--` and args not ending in `--` for `os:argv/1` test --- tests/scryer/cli/issues/os_argv-no-final--.stderr | 0 tests/scryer/cli/issues/os_argv-no-final--.stdin | 5 +++++ tests/scryer/cli/issues/os_argv-no-final--.stdout | 5 +++++ tests/scryer/cli/issues/os_argv-no-final--.toml | 2 ++ 4 files changed, 12 insertions(+) create mode 100644 tests/scryer/cli/issues/os_argv-no-final--.stderr create mode 100644 tests/scryer/cli/issues/os_argv-no-final--.stdin create mode 100644 tests/scryer/cli/issues/os_argv-no-final--.stdout create mode 100644 tests/scryer/cli/issues/os_argv-no-final--.toml diff --git a/tests/scryer/cli/issues/os_argv-no-final--.stderr b/tests/scryer/cli/issues/os_argv-no-final--.stderr new file mode 100644 index 000000000..e69de29bb diff --git a/tests/scryer/cli/issues/os_argv-no-final--.stdin b/tests/scryer/cli/issues/os_argv-no-final--.stdin new file mode 100644 index 000000000..e6f56a723 --- /dev/null +++ b/tests/scryer/cli/issues/os_argv-no-final--.stdin @@ -0,0 +1,5 @@ +os:argv(V). +os:argv(["test1"|_]). +os:argv(["--"|_]). +os:argv(["test2"|_]). +os:argv([]). diff --git a/tests/scryer/cli/issues/os_argv-no-final--.stdout b/tests/scryer/cli/issues/os_argv-no-final--.stdout new file mode 100644 index 000000000..7e9741340 --- /dev/null +++ b/tests/scryer/cli/issues/os_argv-no-final--.stdout @@ -0,0 +1,5 @@ + V = ["test1","--","test2"]. + true. + false. + false. + false. diff --git a/tests/scryer/cli/issues/os_argv-no-final--.toml b/tests/scryer/cli/issues/os_argv-no-final--.toml new file mode 100644 index 000000000..831d0fddd --- /dev/null +++ b/tests/scryer/cli/issues/os_argv-no-final--.toml @@ -0,0 +1,2 @@ +# https://github.com/mthom/scryer-prolog/pull/2263#issuecomment-1874400820 +args = ["-f", "--no-add-history", "--", "test1", "--", "test2"] From 76b1167842233ffad7f659e391f219810cabf34c Mon Sep 17 00:00:00 2001 From: Skgland Date: Tue, 2 Jan 2024 20:54:37 +0100 Subject: [PATCH 06/10] fix os:argv --- src/lib/os.pl | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/lib/os.pl b/src/lib/os.pl index 152077aea..8b0087a4b 100644 --- a/src/lib/os.pl +++ b/src/lib/os.pl @@ -137,7 +137,9 @@ argv(Argv) :- can_be(list, Argv), '$argv'(Argv0), - ( append(Argv1, ["--"|Argv], Argv0) -> - \+ member("--", Argv1) - ; Argv = [] + ( member("--", Argv0) -> + append(Argv1, ["--"|Argv], Argv0), + \+ member("--", Argv1) + ; + Argv = [] ). From 8bd0317e9c331c5d7e04923e2cf040c197154224 Mon Sep 17 00:00:00 2001 From: Skgland Date: Tue, 2 Jan 2024 21:43:38 +0100 Subject: [PATCH 07/10] fix `os:argv(V)` not completing --- src/lib/os.pl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/lib/os.pl b/src/lib/os.pl index 8b0087a4b..00c3e914b 100644 --- a/src/lib/os.pl +++ b/src/lib/os.pl @@ -139,7 +139,8 @@ '$argv'(Argv0), ( member("--", Argv0) -> append(Argv1, ["--"|Argv], Argv0), - \+ member("--", Argv1) + \+ member("--", Argv1), + ! ; Argv = [] ). From e66e7c50341fd22ad893d987597d6064d2e255d8 Mon Sep 17 00:00:00 2001 From: Skgland Date: Thu, 4 Jan 2024 18:12:38 +0100 Subject: [PATCH 08/10] add another test case for os:argv/1 --- tests/scryer/cli/issues/os_argv-no-final--.stdin | 1 + tests/scryer/cli/issues/os_argv-no-final--.stdout | 1 + tests/scryer/cli/issues/os_argv.stdin | 1 + tests/scryer/cli/issues/os_argv.stdout | 1 + 4 files changed, 4 insertions(+) diff --git a/tests/scryer/cli/issues/os_argv-no-final--.stdin b/tests/scryer/cli/issues/os_argv-no-final--.stdin index e6f56a723..59ba556c8 100644 --- a/tests/scryer/cli/issues/os_argv-no-final--.stdin +++ b/tests/scryer/cli/issues/os_argv-no-final--.stdin @@ -1,5 +1,6 @@ os:argv(V). os:argv(["test1"|_]). os:argv(["--"|_]). +os:argv([V, "--"|_]). os:argv(["test2"|_]). os:argv([]). diff --git a/tests/scryer/cli/issues/os_argv-no-final--.stdout b/tests/scryer/cli/issues/os_argv-no-final--.stdout index 7e9741340..9558ca7f4 100644 --- a/tests/scryer/cli/issues/os_argv-no-final--.stdout +++ b/tests/scryer/cli/issues/os_argv-no-final--.stdout @@ -1,5 +1,6 @@ V = ["test1","--","test2"]. true. false. + V = "test1". false. false. diff --git a/tests/scryer/cli/issues/os_argv.stdin b/tests/scryer/cli/issues/os_argv.stdin index e6f56a723..59ba556c8 100644 --- a/tests/scryer/cli/issues/os_argv.stdin +++ b/tests/scryer/cli/issues/os_argv.stdin @@ -1,5 +1,6 @@ os:argv(V). os:argv(["test1"|_]). os:argv(["--"|_]). +os:argv([V, "--"|_]). os:argv(["test2"|_]). os:argv([]). diff --git a/tests/scryer/cli/issues/os_argv.stdout b/tests/scryer/cli/issues/os_argv.stdout index c07dff8ec..2916310ce 100644 --- a/tests/scryer/cli/issues/os_argv.stdout +++ b/tests/scryer/cli/issues/os_argv.stdout @@ -1,5 +1,6 @@ V = ["test1","--","test2","--"]. true. false. + V = "test1". false. false. From ea0130d114711f1688ad947c1a46e38126d11bc5 Mon Sep 17 00:00:00 2001 From: Skgland Date: Thu, 4 Jan 2024 18:14:32 +0100 Subject: [PATCH 09/10] use once to limit solutions instead of cut --- src/lib/os.pl | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/lib/os.pl b/src/lib/os.pl index 00c3e914b..cf3033943 100644 --- a/src/lib/os.pl +++ b/src/lib/os.pl @@ -138,9 +138,8 @@ can_be(list, Argv), '$argv'(Argv0), ( member("--", Argv0) -> - append(Argv1, ["--"|Argv], Argv0), - \+ member("--", Argv1), - ! + once(append(Argv1, ["--"|Argv], Argv0)), + \+ member("--", Argv1) ; Argv = [] ). From 78b83ca1e1a034e602f0b8f5e90ff664da92839b Mon Sep 17 00:00:00 2001 From: Skgland Date: Thu, 4 Jan 2024 19:26:10 +0100 Subject: [PATCH 10/10] simplify os:argv/1 fix --- src/lib/os.pl | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/lib/os.pl b/src/lib/os.pl index cf3033943..c9db15f45 100644 --- a/src/lib/os.pl +++ b/src/lib/os.pl @@ -137,9 +137,8 @@ argv(Argv) :- can_be(list, Argv), '$argv'(Argv0), - ( member("--", Argv0) -> - once(append(Argv1, ["--"|Argv], Argv0)), - \+ member("--", Argv1) + ( append(_, ["--"|Argv1], Argv0) -> + Argv = Argv1 ; Argv = [] ).