summaryrefslogtreecommitdiffstats
path: root/test/evaltest.sh
blob: 1dd6394e5f222a127df13f4de90a56e23372f06d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/bin/bash
# Copyright (C) 2007 Dejan Muhamedagic <dejan@suse.de>
# See COPYING for license information.

: ${TESTDIR:=testcases}
: ${CRM:=crm}
CRM_NO_REG="$CRM"
CRM="$CRM -R"
export PYTHONUNBUFFERED=1
export CRMSH_REGRESSION_TEST=1

if [ "$1" = prof ]; then
	CRM="$CRM -X regtest.profile"
fi

. ./defaults
. ./crm-interface
. ./descriptions

resetvars() {
	unset args
	unset extcheck
}

#
# special operations squad
#
specopt_setenv() {
	eval $rest
}
specopt_ext() {
	eval $rest
}
specopt_extcheck() {
	extcheck="$rest"
	set $extcheck
	which "$1" >/dev/null 2>&1 ||  # a program in the PATH
		extcheck="$TESTDIR/$extcheck"  # or our script
}
specopt_repeat() {
	repeat_limit=$rest
}
specopt() {
	cmd=$(echo $cmd | sed 's/%//')  # strip leading '%'
	echo ".$(echo "$cmd" | tr "[:lower:]" "[:upper:]") $rest"  # show what we got
	"specopt_$cmd"  # do what they asked for
}

#
# substitute variables in the test line
#
substvars() {
	sed "
	s/%t/$test_cnt/g
	s/%l/$line/g
	s/%i/$repeat_cnt/g
	"
}

dotest_session() {
	echo -n "." >&3
	test_cnt=$(($test_cnt+1))
	"describe_$cmd" "$*"  # show what we are about to do
	"crm_$cmd" |  # and execute the command
		{ [ "$extcheck" ] && $extcheck || cat;}
}
dotest_single() {
	echo -n "." >&3
	test_cnt=$(($test_cnt+1))
	describe_single "$*" # show what we are about to do
	crm_single "$*" |  # and execute the command
		{ [ "$extcheck" ] && $extcheck || cat;}
	if [ "$showobj" ]; then
		crm_showobj $showobj
	fi
}
runtest_session() {
	while read line; do
		if [ "$line" = . ]; then
			break
		fi
		echo "$line"
	done | dotest_session $*
}
runtest_single() {
	while [ $repeat_cnt -le $repeat_limit ]; do
		dotest_single "$*"
		resetvars  # unset all variables
		repeat_cnt=$(($repeat_cnt+1))
	done
	repeat_limit=1 repeat_cnt=1
}

#
# run the tests
#
repeat_limit=1 repeat_cnt=1
line=1
test_cnt=1

crm_setup
crm_mksample
while read cmd rest; do
	case "$cmd" in
		"") : empty ;;
		"#"*) : a comment ;;
		"%stop") break ;;
		"%"*) specopt ;;
		show|showxml|session|filesession) runtest_session $rest ;;
		*) runtest_single $cmd $rest ;;
	esac
	line=$(($line+1))
done