summaryrefslogtreecommitdiff
path: root/Userland/Shell
diff options
context:
space:
mode:
authorAli Mohammad Pur <ali.mpfard@gmail.com>2021-04-29 07:24:33 +0430
committerAndreas Kling <kling@serenityos.org>2021-04-29 20:25:56 +0200
commitd70f25bbe5cf2061f9888822ce148d7040c433bd (patch)
tree29b178d9e737bd50179da63b9865f3ec6fece053 /Userland/Shell
parent3048274f5efdb5a02407d021338faa6770ac5280 (diff)
downloadserenity-d70f25bbe5cf2061f9888822ce148d7040c433bd.zip
Shell: Add some tests for heredocs
Diffstat (limited to 'Userland/Shell')
-rw-r--r--Userland/Shell/Tests/heredocs.sh74
1 files changed, 74 insertions, 0 deletions
diff --git a/Userland/Shell/Tests/heredocs.sh b/Userland/Shell/Tests/heredocs.sh
new file mode 100644
index 0000000000..c1c4c6b376
--- /dev/null
+++ b/Userland/Shell/Tests/heredocs.sh
@@ -0,0 +1,74 @@
+#!/bin/sh
+
+source $(dirname "$0")/test-commons.inc
+
+# Simple usage, single doc
+echo <<-test > sh.doc.test
+this is a test
+test
+if test "$(cat sh.doc.test)" != "this is a test" {
+ fail "Could not use normal interpolated heredoc"
+}
+
+echo <<-'test' > sh.doc.test
+this is a test
+test
+if test "$(cat sh.doc.test)" != "this is a test" {
+ fail "Could not use normal non-interpolated heredoc"
+}
+
+echo <<~test > sh.doc.test
+ this is a test
+test
+if test "$(cat sh.doc.test)" != "this is a test" {
+ fail "Could not use normal dedented heredoc"
+}
+
+echo <<~'test' > sh.doc.test
+ this is a test
+test
+if test "$(cat sh.doc.test)" != "this is a test" {
+ fail "Could not use normal non-interpolated dedented heredoc"
+}
+
+var=test
+echo <<-test > sh.doc.test
+this is a $var
+test
+if test "$(cat sh.doc.test)" != "this is a test" {
+ fail "Could not use interpolated heredoc with interpolation"
+}
+
+echo <<~test > sh.doc.test
+ this is a $var
+test
+if test "$(cat sh.doc.test)" != "this is a test" {
+ fail "Could not use dedented interpolated heredoc with interpolation"
+}
+
+# Multiple heredocs
+echo <<-test <<-test2 > sh.doc.test
+contents for test
+test
+contents for test2
+test2
+if test "$(cat sh.doc.test)" != "contents for test contents for test2" {
+ fail "Could not use two heredocs"
+}
+
+# Why would you do this you crazy person?
+if test "$(echo <<~text)" != "test" {
+ test
+ text
+ fail "Could not use heredocs in a weird place"
+}
+
+# Now let's try something _really_ weird!
+if test "$(echo <<~test1)" != "$(echo <<~test2)" { fail "The parser forgot about heredocs after a block, oops" }
+test
+test1
+test
+test2
+
+rm -f sh.doc.test
+pass