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