Serenity Operating System
at master 95 lines 3.5 kB view raw
1#!/bin/Shell 2 3echo "Not running Shell-valid as it has a high failure rate on target #7336" 4echo PASS 5exit 0 6 7source $(dirname "$0")/test-commons.inc 8 9# Are comments ignored? 10# Sanity check: can we do && and || ? 11true || exit 2 12false 13 14# Can we chain &&'s? 15false && exit 2 && fail "can't chain &&'s" 16 17# Proper precedence between &&'s and ||'s 18false && exit 2 || true && false && fail Invalid precedence between '&&' and '||' 19 20 21# Sanity check: can we pass arguments to 'test'? 22if not test yes = yes { exit 2 } 23 24# Sanity check: can we use $(command)? 25if not test "$(echo yes)" = yes { exit 2 } 26# Redirections. 27if not test -z "$(echo foo > /dev/null)" { fail direct path redirection } 28if not test -z "$(echo foo 2> /dev/null 1>&2)" { fail indirect redirection } 29if not test -n "$(echo foo 2> /dev/null)" { fail fds interfere with each other } 30 31# Argument unpack 32if not test "$(echo (yes))" = yes { fail arguments inside bare lists } 33if not test "$(echo (no)() yes)" = yes { fail arguments inside juxtaposition: empty } 34if not test "$(echo (y)(es))" = yes { fail arguments inside juxtaposition: list } 35if not test "$(echo "y"es)" = yes { fail arguments inside juxtaposition: string } 36 37# String substitution 38foo=yes 39if not test "$(echo $foo)" = yes { fail simple string var lookup } 40if not test "$(echo "$foo")" = yes { fail stringified string var lookup } 41 42# List substitution 43foo=(yes) 44# Static lookup, as list 45if not test "$(echo $foo)" = yes { fail simple list var lookup } 46# Static lookup, stringified 47if not test "$(echo "$foo")" = yes { fail stringified list var lookup } 48# Dynamic lookup through static expression 49if not test "$(echo $'foo')" = yes { fail dynamic lookup through static exp } 50# Dynamic lookup through dynamic expression 51ref_to_foo=foo 52if not test "$(echo $"$ref_to_foo")" = yes { fail dynamic lookup through dynamic exp } 53 54# More redirections 55echo test > /tmp/sh-test 56if not test "$(cat /tmp/sh-test)" = test { fail simple path redirect } 57rm /tmp/sh-test 58 59# 'brace' expansions 60if not test "$(echo x(yes no))" = "xyes xno" { fail simple juxtaposition expansion } 61if not test "$(echo (y n)(es o))" = "yes yo nes no" { fail list-list juxtaposition expansion } 62if not test "$(echo ()(foo bar baz))" = "" { fail empty expansion } 63 64# Variables inside commands 65to_devnull=(>/dev/null) 66if not test "$(echo hewwo $to_devnull)" = "" { fail variable containing simple command } 67 68word_count=(() | wc -w) 69if not test "$(echo well hello friends $word_count)" -eq 3 { fail variable containing pipeline } 70 71# Globs 72rm -fr /tmp/sh-test 2> /dev/null 73mkdir -p /tmp/sh-test 74pushd /tmp/sh-test 75 touch (a b c)(d e f) 76 if not test "$(echo a*)" = "ad ae af" { fail '*' glob expansion } 77 if not test "$(echo a?)" = "ad ae af" { fail '?' glob expansion } 78 79 glob_in_var='*' 80 if not test "$(echo $glob_in_var)" = '*' { fail substituted string acts as glob } 81 82 if not test "$(echo (a*))" = "ad ae af" { fail globs in lists resolve wrong } 83 if not test "$(echo x(a*))" = "xad xae xaf" { fail globs in lists do not resolve to lists } 84 if not test "$(echo "foo"a*)" = "fooad fooae fooaf" { fail globs join to dquoted strings } 85popd 86rm -fr /tmp/sh-test 87 88# Setopt 89setopt --inline_exec_keep_empty_segments 90if not test "$(echo -n "a\n\nb")" = "a b" { fail inline_exec_keep_empty_segments has no effect } 91 92setopt --no_inline_exec_keep_empty_segments 93if not test "$(echo -n "a\n\nb")" = "a b" { fail cannot unset inline_exec_keep_empty_segments } 94 95echo PASS