Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/cmd/ksh93/tests/case.sh
1810 views
1
########################################################################
2
# #
3
# This software is part of the ast package #
4
# Copyright (c) 1982-2011 AT&T Intellectual Property #
5
# and is licensed under the #
6
# Eclipse Public License, Version 1.0 #
7
# by AT&T Intellectual Property #
8
# #
9
# A copy of the License is available at #
10
# http://www.eclipse.org/org/documents/epl-v10.html #
11
# (with md5 checksum b35adb5213ca9657e911e9befb180842) #
12
# #
13
# Information and Software Systems Research #
14
# AT&T Research #
15
# Florham Park NJ #
16
# #
17
# David Korn <[email protected]> #
18
# #
19
########################################################################
20
function err_exit
21
{
22
print -u2 -n "\t"
23
print -u2 -r ${Command}[$1]: "${@:2}"
24
let Errors+=1
25
}
26
alias err_exit='err_exit $LINENO'
27
28
Command=${0##*/}
29
integer Errors=0
30
31
bar=foo2
32
bam=foo[3]
33
for i in foo1 foo2 foo3 foo4 foo5 foo6
34
do foo=0
35
case $i in
36
foo1) foo=1;;
37
$bar) foo=2;;
38
$bam) foo=3;;
39
foo[4]) foo=4;;
40
${bar%?}5)
41
foo=5;;
42
"${bar%?}6")
43
foo=6;;
44
esac
45
if [[ $i != foo$foo ]]
46
then err_exit "$i not matching correct pattern"
47
fi
48
done
49
f="[ksh92]"
50
case $f in
51
\[*\]) ;;
52
*) err_exit "$f does not match \[*\]";;
53
esac
54
55
if [[ $($SHELL -c '
56
x=$(case abc {
57
abc) { print yes;};;
58
*) print no;;
59
}
60
)
61
print -r -- "$x"' 2> /dev/null) != yes ]]
62
then err_exit 'case abc {...} not working'
63
fi
64
[[ $($SHELL -c 'case a in
65
a) print -n a > /dev/null ;&
66
b) print b;;
67
esac') != b ]] && err_exit 'bug in ;& at end of script'
68
[[ $(VMDEBUG=1 $SHELL -c '
69
tmp=foo
70
for i in a b
71
do case $i in
72
a) : tmp=$tmp tmp.h=$tmp.h;;
73
b) ( tmp=bar )
74
for j in a
75
do print -r -- $tmp.h
76
done
77
;;
78
esac
79
done
80
') == foo.h ]] || err_exit "optimizer bug"
81
82
x=$($SHELL -ec 'case a in a) echo 1; false; echo 2 ;& b) echo 3;; esac')
83
[[ $x == 1 ]] || err_exit 'set -e ignored on case fail through'
84
85
exit $((Errors<125?Errors:125))
86
87