2020-09-08 15:39:19 +04:30
|
|
|
#!/bin/sh
|
|
|
|
|
2021-01-24 21:42:30 -07:00
|
|
|
source $(dirname "$0")/test-commons.inc
|
2021-01-18 10:08:30 +03:30
|
|
|
|
2020-09-08 15:39:19 +04:30
|
|
|
setopt --verbose
|
|
|
|
|
2021-05-21 04:44:11 -06:00
|
|
|
rm -rf /tmp/shell-test 2> /dev/null
|
|
|
|
mkdir -p /tmp/shell-test
|
|
|
|
pushd /tmp/shell-test
|
2020-09-08 15:39:19 +04:30
|
|
|
|
|
|
|
touch a b c
|
|
|
|
|
|
|
|
# Can we do logical stuff with control structures?
|
|
|
|
ls && for $(seq 1) { echo yes > listing }
|
2021-01-18 10:08:30 +03:30
|
|
|
if not test "$(cat listing)" = "yes" { fail for cannot appear as second part of '&&' }
|
2020-09-08 15:39:19 +04:30
|
|
|
rm listing
|
|
|
|
|
2021-01-18 10:08:30 +03:30
|
|
|
# FIXME: These should work!
|
|
|
|
|
2020-09-08 15:39:19 +04:30
|
|
|
# for $(seq 1) { echo yes > listing } && echo HELLO!
|
2021-01-18 10:08:30 +03:30
|
|
|
# if not test "$(cat listing)" = "yes" { echo for cannot appear as first part of '&&' }
|
2020-09-08 15:39:19 +04:30
|
|
|
# rm listing
|
|
|
|
|
|
|
|
# Can we pipe things into and from control structures?
|
2021-01-18 10:08:30 +03:30
|
|
|
# ls | if true { cat > listing }
|
|
|
|
# if not test "$(cat listing)" = "a b c" { fail if cannot be correctly redirected to }
|
|
|
|
# rm listing
|
2020-09-08 15:39:19 +04:30
|
|
|
|
2021-01-18 10:08:30 +03:30
|
|
|
# ls | for $(seq 1) { cat > listing }
|
|
|
|
# if not test "$(cat listing)" = "a b c" { fail for cannot be correctly redirected to }
|
|
|
|
# rm listing
|
2020-09-08 15:39:19 +04:30
|
|
|
|
|
|
|
for $(seq 4) { echo $it } | cat > listing
|
2021-01-18 10:08:30 +03:30
|
|
|
if not test "$(cat listing)" = "1 2 3 4" { fail for cannot be correctly redirected from }
|
2020-09-08 15:39:19 +04:30
|
|
|
rm listing
|
|
|
|
|
|
|
|
if true { echo TRUE! } | cat > listing
|
2021-01-18 10:08:30 +03:30
|
|
|
if not test "$(cat listing)" = "TRUE!" { fail if cannot be correctly redirected from }
|
2020-09-08 15:39:19 +04:30
|
|
|
rm listing
|
|
|
|
|
2021-05-21 04:44:11 -06:00
|
|
|
popd
|
|
|
|
rm -rf /tmp/shell-test
|
2021-01-18 10:08:30 +03:30
|
|
|
|
|
|
|
echo PASS
|