hush: add "heredoc.tests" from ash, tweak ash "is a function" message
authorDenys Vlasenko <vda.linux@googlemail.com>
Tue, 24 Jul 2018 15:08:04 +0000 (17:08 +0200)
committerDenys Vlasenko <vda.linux@googlemail.com>
Tue, 24 Jul 2018 15:10:18 +0000 (17:10 +0200)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
shell/ash.c
shell/ash_test/ash-heredoc/heredoc.right
shell/hush_test/hush-heredoc/heredoc.right [new file with mode: 0644]
shell/hush_test/hush-heredoc/heredoc.tests [new file with mode: 0755]

index 051cc671fcef4a21d68a36ccea38c8251ce476fc..03fbbee53eb2f64dd80eadd5acafae23a15a6ad0 100644 (file)
@@ -8512,7 +8512,8 @@ describe_command(char *command, const char *path, int describe_command_verbose)
 
        case CMDFUNCTION:
                if (describe_command_verbose) {
-                       out1str(" is a shell function");
+                       /*out1str(" is a shell function");*/
+                       out1str(" is a function"); /* bash says this */
                } else {
                        out1str(command);
                }
index baf11516638b6c670e44a1f2b6c68aed5db13965..85d36dae950901322a30c62b4bd6b8ea135b9871 100644 (file)
@@ -16,6 +16,6 @@ tab 3
 abc
 def ghi
 jkl mno
-fff is a shell function
+fff is a function
 hi
 there
diff --git a/shell/hush_test/hush-heredoc/heredoc.right b/shell/hush_test/hush-heredoc/heredoc.right
new file mode 100644 (file)
index 0000000..9b9e2aa
--- /dev/null
@@ -0,0 +1,20 @@
+there
+one - alpha
+two - beta
+three - gamma
+hi\
+there$a
+stuff
+hi\
+there
+EO\
+F
+hi
+hi
+tab 1
+tab 2
+tab 3
+abc
+def ghi
+jkl mno
+fff is a function
diff --git a/shell/hush_test/hush-heredoc/heredoc.tests b/shell/hush_test/hush-heredoc/heredoc.tests
new file mode 100755 (executable)
index 0000000..39345c5
--- /dev/null
@@ -0,0 +1,97 @@
+# check order and content of multiple here docs
+
+cat << EOF1 << EOF2
+hi
+EOF1
+there
+EOF2
+
+while read line1; do
+       read line2 <&3
+       echo $line1 - $line2
+done <<EOF1 3<<EOF2
+one
+two
+three
+EOF1
+alpha
+beta
+gamma
+EOF2
+
+
+# check quoted here-doc is protected
+
+a=foo
+cat << 'EOF'
+hi\
+there$a
+stuff
+EOF
+
+# check that quoted here-documents don't have \newline processing done
+
+cat << 'EOF'
+hi\
+there
+EO\
+F
+EOF
+true
+
+# check that \newline is removed at start of here-doc
+cat << EO\
+F
+hi
+EOF
+
+# check that \newline removal works for here-doc delimiter
+cat << EOF
+hi
+EO\
+F
+
+# check operation of tab removal in here documents
+cat <<- EOF
+       tab 1
+       tab 2
+       tab 3
+       EOF
+
+# check appending of text to file from here document
+rm -f /tmp/bash-zzz
+cat > /tmp/bash-zzz << EOF
+abc
+EOF
+cat >> /tmp/bash-zzz << EOF
+def ghi
+jkl mno
+EOF
+cat /tmp/bash-zzz
+rm -f /tmp/bash-zzz
+
+# make sure command printing puts the here-document as the last redirection
+# on the line, and the function export code preserves syntactic correctness
+fff()
+{
+  ed /tmp/foo <<ENDOFINPUT >/dev/null
+/^name/d
+w
+q
+ENDOFINPUT
+aa=1
+}
+
+type fff
+#ash# export -f fff
+#ash# ${THIS_SH} -c 'type fff'
+
+#hush# bash warns: "here-document at line N delimited by end-of-file",
+#hush# ash allows it,
+#hush# hush errors out for now:
+#hush# # check that end of file delimits a here-document
+#hush# # THIS MUST BE LAST!
+#hush#
+#hush# cat << EOF
+#hush# hi
+#hush# there