summaryrefslogtreecommitdiffstats
path: root/tests/heredoc.tests
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 15:38:56 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 15:38:56 +0000
commit6c20c8ed2cb9ab69a1a57ccb2b9b79969a808321 (patch)
treef63ce19d57fad3ac4a15bc26dbfbfa2b834111b5 /tests/heredoc.tests
parentInitial commit. (diff)
downloadbash-6c20c8ed2cb9ab69a1a57ccb2b9b79969a808321.tar.xz
bash-6c20c8ed2cb9ab69a1a57ccb2b9b79969a808321.zip
Adding upstream version 5.2.15.upstream/5.2.15upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/heredoc.tests')
-rw-r--r--tests/heredoc.tests156
1 files changed, 156 insertions, 0 deletions
diff --git a/tests/heredoc.tests b/tests/heredoc.tests
new file mode 100644
index 0000000..d10a7c1
--- /dev/null
+++ b/tests/heredoc.tests
@@ -0,0 +1,156 @@
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+# basics
+cat <<EOF
+a
+b
+c
+EOF
+read x <<EOF
+a
+b
+c
+EOF
+echo "$x"
+read x y <<\EOF
+$PS4
+EOF
+echo "$x"
+
+# empty here-documents
+read x <<EOF
+EOF
+echo "$x"
+read x <<\EOF
+EOF
+echo "$x"
+read x <<EOF
+$empty
+EOF
+echo "$x"
+
+# 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 ${TMPDIR}/bash-zzz
+cat > ${TMPDIR}/bash-zzz << EOF
+abc
+EOF
+cat >> ${TMPDIR}/bash-zzz << EOF
+def ghi
+jkl mno
+EOF
+cat ${TMPDIR}/bash-zzz
+rm -f ${TMPDIR}/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 ${TMPDIR}/foo <<ENDOFINPUT >/dev/null
+/^name/d
+w
+q
+ENDOFINPUT
+aa=1
+}
+
+type fff
+export -f fff
+${THIS_SH} -c 'type fff'
+
+${THIS_SH} ./heredoc1.sub
+
+# test heredocs in command substitutions
+${THIS_SH} ./heredoc2.sub
+${THIS_SH} ./heredoc3.sub
+${THIS_SH} ./heredoc4.sub
+
+# heredoc tests that use different size documents to test pipe implementation
+${THIS_SH} ./heredoc5.sub
+
+# test $'...' and $"..." quoted strings in here-documents
+${THIS_SH} ./heredoc6.sub
+
+# interaction between here-documents and command substitutions
+${THIS_SH} ./heredoc7.sub
+
+
+echo $(
+ cat <<< "comsub here-string"
+)
+
+# check that end of file delimits a here-document
+# THIS MUST BE LAST!
+
+cat << EOF
+hi
+there