xref: /titanic_50/usr/src/lib/libshell/common/tests/shtests (revision 75ce41a57ff334bd8fe2cb9ed51eea835892f944)
1# This program runs ksh regression tests
2# shtests [ name=value ... ] [ --all | --compile ] [ --time ] [ a.sh b.sh ... ]
3
4unset DISPLAY ENV FIGNORE
5LANG=C
6LC_ALL=C
7compile=1
8script=1
9time=1
10vmdebug=1
11while	:
12do	case $1 in
13	-a|--a*)compile=2
14		script=2
15		;;
16	-c|--c*)compile=2
17		script=
18		;;
19	-s|--s*)compile=
20		script=2
21		;;
22	-t|--not*)time=
23		;;
24	-v|--nov*)vmdebug=
25		;;
26	-*)	echo $0: $1: invalid option >&2
27		exit 2
28		;;
29	*=*)	n=${1%%=*}
30		v=${1#*=}
31		eval $n=\'$v\'
32		export $n
33		;;
34	*)	break
35		;;
36	esac
37	shift
38done
39if	[[ ! $vmdebug ]]
40then	unset VMDEBUG
41elif	[[ ! $VMDEBUG ]]
42then	export VMDEBUG=a
43fi
44export LANG LC_ALL PATH PWD SHELL
45PWD=`pwd`
46SHELL=${SHELL-ksh}
47case $0 in
48/*)	d=`dirname $0`;;
49*/*)	d=$PWD/`dirname $0`;;
50*)	d=$PWD;;
51esac
52case $SHELL in
53/*)	;;
54*/*)	SHELL=$d/$SHELL;;
55*)	SHELL=$(whence $SHELL);;
56esac
57PATH=/bin:/usr/bin
58if	[[ -d /usr/ucb ]]
59then	PATH=$PATH:/usr/ucb
60fi
61PATH=$PATH:$d
62if	[[ $INSTALLROOT && -r $INSTALLROOT/bin/.paths ]]
63then	PATH=$INSTALLROOT/bin:$PATH
64fi
65if	[[ $compile ]]
66then	SHCOMP=${SHCOMP:-shcomp}
67	if	whence $SHCOMP > /dev/null
68	then	tmp=/tmp/ksh-$$
69		trap 'rm -rf $tmp' EXIT
70		mkdir $tmp || exit
71	elif	[[ $compile != 1 ]]
72	then	echo $0: --compile: $SHCOMP not found >&2
73		exit 1
74	else	compile=
75	fi
76fi
77typeset -A tests
78for i in ${*-*.sh}
79do	t=$(grep -c err_exit $i)
80	if	(( $t > 2 ))
81	then	(( t = $t - 2 ))
82	fi
83	tests[$i]=$t
84	T=test
85	if	(( $t != 1 ))
86	then	T=${T}s
87	fi
88	E=error
89	if	[[ $script ]]
90	then	echo test $i begins ${time:+"at $(date +%Y-%m-%d+%H:%M:%S)"}
91		if	$SHELL $i
92		then	echo test $i passed ${time:+"at $(date +%Y-%m-%d+%H:%M:%S)"} "[ $t $T 0 ${E}s ]"
93		else	e=$?
94			if	(( e > 256 ))
95			then	e=1
96				E=signal
97			fi
98			if	(( $e != 1 ))
99			then	E=${E}s
100			fi
101			echo test $i failed ${time:+"at $(date +%Y-%m-%d+%H:%M:%S)"} with exit code $e "[ $t $T $e $E ]"
102		fi
103	fi
104done
105if	[[ $compile ]]
106then	for i in ${*-*.sh}
107	do	t=${tests[$i]}
108		T=test
109		if	(( $t != 1 ))
110		then	T=${T}s
111		fi
112		o=${i##*/}
113		o=shcomp-${o%.sh}.ksh
114		echo test $o begins ${time:+"at $(date +%Y-%m-%d+%H:%M:%S)"}
115		E=error
116		if	$SHCOMP $i > $tmp/$o
117		then	if	$SHELL $tmp/$o
118			then	echo test $o passed ${time:+"at $(date +%Y-%m-%d+%H:%M:%S)"} "[ $t $T 0 ${E}s ]"
119			else	e=$?
120				if	(( e > 256 ))
121				then	e=1
122					E=signal
123				fi
124				if	(( $e != 1 ))
125				then	E=${E}s
126				fi
127				echo test $o failed ${time:+"at $(date +%Y-%m-%d+%H:%M:%S)"} with exit code $e "[ $t $T $e $E ]"
128			fi
129		else	e=$?
130			t=1
131			T=test
132			echo test $o failed to compile ${time:+"at $(date +%Y-%m-%d+%H:%M:%S)"} with exit code $e "[ $t $T 1 $E ]"
133		fi
134	done
135fi
136