sh: Add some parser tests.

case1.0 tests POSIX requirements and one more for keywords in case
statements. The others test very special cases of command substitution.

These also work on stable/8.
This commit is contained in:
jilles 2010-05-09 17:10:50 +00:00
parent 684507e744
commit c0ec19525d
3 changed files with 53 additions and 0 deletions

View File

@ -0,0 +1,14 @@
# $FreeBSD$
keywords='if then else elif fi while until for do done { } case esac ! in'
# Keywords can be used unquoted in case statements, except the keyword
# esac as the first pattern of a '|' alternation without a starting '('.
# (POSIX doesn't seem to require (esac) to work.)
for k in $keywords; do
eval "case $k in (foo|$k) ;; *) echo bad ;; esac"
eval "case $k in ($k) ;; *) echo bad ;; esac"
eval "case $k in foo|$k) ;; *) echo bad ;; esac"
[ "$k" = esac ] && continue
eval "case $k in $k) ;; *) echo bad ;; esac"
done

View File

@ -0,0 +1,32 @@
# $FreeBSD$
# Pretty much only ash derivatives can parse all of this.
f1() {
x=$(case x in
(x|esac) ;;
(*) echo bad >&2 ;;
esac)
}
f1
f2() {
x=$(case x in
(x|esac) ;;
(*) echo bad >&2
esac)
}
f2
f3() {
x=$(case x in
x|esac) ;;
*) echo bad >&2 ;;
esac)
}
f3
f4() {
x=$(case x in
x|esac) ;;
*) echo bad >&2
esac)
}
f4

View File

@ -0,0 +1,7 @@
# $FreeBSD$
# This may be expected to work, but pretty much only ash derivatives allow it.
test "$(cat <<EOF)" = "hi there"
hi there
EOF