From 3074e65693cf8a654961e1ea62c616a063ae8a47 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Sun, 28 May 2023 12:58:39 -0500 Subject: [PATCH] Wire up "local" builtin, with test. And fix typo. --- tests/sh.test | 9 ++++++--- toys/pending/sh.c | 1 + 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/sh.test b/tests/sh.test index b36966d6..e435d26d 100644 --- a/tests/sh.test +++ b/tests/sh.test @@ -121,9 +121,12 @@ testing "eval0" "$SH -c 'eval echo \$*' one two three" "two three\n" "" "" # Change EVAL to call sh -c for us, using "bash" explicitly for the host. export EVAL="timeout 10 $SH -c" -testing 'test return code' 'if false; then echo true; fi; echo $?' '0\n' '' '' -testing 'test return code 2' 'if true; the false; fi; echo $?' '1\n' '' '' -testing 'test return code 3' 'x=0; while [ $((x++)) -lt 2 ]; do echo $x; done; echo $?' '1\n2\n0\n' '' '' +testing 'return code' 'if false; then echo true; fi; echo $?' '0\n' '' '' +testing 'return code 2' 'if true; then false; fi; echo $?' '1\n' '' '' +testing 'return code 3' 'x=0; while [ $((x++)) -lt 2 ]; do echo $x; done; echo $?' '1\n2\n0\n' '' '' +testing 'local var +whiteout' \ + 'l=X;x(){ local l=47; echo $l;unset l; echo l=$l;};x;echo $l' '47\nl=\nX\n' \ + '' '' testing 'trailing $ is literal' 'echo $' '$\n' '' '' # TODO testing 'empty +() is literal' 'echo +()' '+()\n' '' '' diff --git a/toys/pending/sh.c b/toys/pending/sh.c index 9272631b..ed2b6912 100644 --- a/toys/pending/sh.c +++ b/toys/pending/sh.c @@ -51,6 +51,7 @@ USE_SH(NEWTOY(exec, "^cla:", TOYFLAG_NOFORK)) USE_SH(NEWTOY(exit, 0, TOYFLAG_NOFORK)) USE_SH(NEWTOY(export, "np", TOYFLAG_NOFORK)) USE_SH(NEWTOY(jobs, "lnprs", TOYFLAG_NOFORK)) +USE_SH(NEWTOY(local, 0, TOYFLAG_NOFORK)) USE_SH(NEWTOY(set, 0, TOYFLAG_NOFORK)) USE_SH(NEWTOY(shift, ">1", TOYFLAG_NOFORK)) USE_SH(NEWTOY(source, "<1", TOYFLAG_NOFORK)) -- 2.39.2