summaryrefslogtreecommitdiff
path: root/Shell/Tests/control-structure-as-command.sh
diff options
context:
space:
mode:
authorAnotherTest <ali.mpfard@gmail.com>2020-09-08 15:39:19 +0430
committerAndreas Kling <kling@serenityos.org>2020-09-09 20:35:21 +0200
commit0fd8d5ad3d47e14c6b892b64528b628bf5c5a933 (patch)
tree16be3b54e7338b452f7f2de5ed403a2fc1c256a2 /Shell/Tests/control-structure-as-command.sh
parent54b453be578e7701ca842301e73ffb6b334e54f6 (diff)
downloadserenity-0fd8d5ad3d47e14c6b892b64528b628bf5c5a933.zip
Shell: Add a test for control structures as commands
Diffstat (limited to 'Shell/Tests/control-structure-as-command.sh')
-rw-r--r--Shell/Tests/control-structure-as-command.sh39
1 files changed, 39 insertions, 0 deletions
diff --git a/Shell/Tests/control-structure-as-command.sh b/Shell/Tests/control-structure-as-command.sh
new file mode 100644
index 0000000000..8bd31f01af
--- /dev/null
+++ b/Shell/Tests/control-structure-as-command.sh
@@ -0,0 +1,39 @@
+#!/bin/sh
+
+setopt --verbose
+
+rm -rf shell-test 2> /dev/null
+mkdir shell-test
+cd shell-test
+
+ touch a b c
+
+ # Can we do logical stuff with control structures?
+ ls && for $(seq 1) { echo yes > listing }
+ test "$(cat listing)" = "yes" || echo for cannot appear as second part of '&&' && exit 1
+ rm listing
+
+ # FIXME: This should work!
+ # for $(seq 1) { echo yes > listing } && echo HELLO!
+ # test "$(cat listing)" = "yes" || echo for cannot appear as first part of '&&' && exit 1
+ # rm listing
+
+ # Can we pipe things into and from control structures?
+ ls | if true { cat > listing }
+ test "$(cat listing)" = "a b c" || echo if cannot be correctly redirected to && exit 1
+ rm listing
+
+ ls | for $(seq 1) { cat > listing }
+ test "$(cat listing)" = "a b c" || echo for cannot be correctly redirected to && exit 1
+ rm listing
+
+ for $(seq 4) { echo $it } | cat > listing
+ test "$(cat listing)" = "1 2 3 4" || echo for cannot be correctly redirected from && exit 1
+ rm listing
+
+ if true { echo TRUE! } | cat > listing
+ test "$(cat listing)" = "TRUE!" || echo if cannot be correctly redirected from && exit 1
+ rm listing
+
+cd ..
+rm -rf shell-test