aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2020-10-19 18:56:59 -0500
committerRob Landley <rob@landley.net>2020-10-19 18:56:59 -0500
commitd0d4107534ac1b7c6ebf8d1e194d7c58ed0e5c52 (patch)
tree5caa353a5918ab275eea1bdc169fc73d1f7f8f04
parent273c9e72c1a578915cc4db6a83ca5e0f6a1771f4 (diff)
downloadtoybox-d0d4107534ac1b7c6ebf8d1e194d7c58ed0e5c52.tar.gz
More tests, and a workaround to pass one of them.
(The bug is that "echo hello \" followed by just enter should end the $PS2 state but it persists when the line is empty because resulting collated line still ends with \ so it wants another line.)
-rw-r--r--tests/sh.test7
-rw-r--r--toys/pending/sh.c2
2 files changed, 7 insertions, 2 deletions
diff --git a/tests/sh.test b/tests/sh.test
index 516e0c82..67921c1a 100644
--- a/tests/sh.test
+++ b/tests/sh.test
@@ -197,7 +197,8 @@ testing "case" 'for i in A C J B; do case "$i" in A) echo got A ;; B) echo and B
testing "case newlines" \
$'case i\n\nin\n\na) echo one\n\n;;\n\ni)\n\necho two\n\n;;\n\nesac' \
"two\n" "" ""
-
+testing 'loop in && ||' \
+ 'false && for i in a b c; do echo $i; done || echo no' 'no\n' '' ''
testing "continue" 'for i in a b c; do for j in d e f; do echo $i $j; continue 2; done; done' \
"a d\nb d\nc d\n" "" ""
@@ -475,6 +476,10 @@ shxpect '[+(]) overlap priority' I$'shopt -s extglob\n' E"$P" \
shxpect '${a?b} sets err, stops cmdline eval' \
I$': ${a?b} ${c:=d}\n' E E"$P" I$'echo $?$c\n' O$'1\n'
+testing 'source file' 'source input' 'hello\n' 'echo hello \\\n' ''
+testing '. file' '. input' 'hello\n' 'echo hello \\\n' ''
+testing 'source no newline' 'source input' 'hello \\\n' 'echo hello \\' ''
+
# TODO finish variable list from shell init
# $# $? $- $$ $! $0
diff --git a/toys/pending/sh.c b/toys/pending/sh.c
index 5590812a..784c7a01 100644
--- a/toys/pending/sh.c
+++ b/toys/pending/sh.c
@@ -3560,7 +3560,7 @@ void source_main(void)
break;
}
- if (1!=(prompt = parse_line(new ? : "", &scratch))) {
+ if (1!=(prompt = parse_line(new ? : " ", &scratch))) {
if (!prompt) run_function(scratch.pipeline);
free_function(&scratch);
if (!new) {