File: testcontrol.sh

package info (click to toggle)
xdg-utils 1.0-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 1,268 kB
  • ctags: 321
  • sloc: sh: 7,394; perl: 274; makefile: 190; xml: 32
file content (121 lines) | stat: -rw-r--r-- 2,614 bytes parent folder | download | duplicates (11)
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
114
115
116
117
118
119
120
121

if [ -z "$IC_NUM" ] ; then
	declare -i IC_NUM=1
fi

run_test() {
## USAGE:
# run_test test_func

# if tests are being run with TET or the test runner
if [  ! -z "$USING_TET" -o ! -z "$USING_TEST_RUNNER" ]; then
	## The TET framework REQUIRES variables of the form $ic1 ... $icN
	## where each variable is a list of test functions. Here, there is only
	## one test function per $icN variable. Each $icN variable MUST be present 
	## in the $iclist
	export ic$IC_NUM="$1"
	export iclist="$iclist ic$IC_NUM"

	## The standalone test runner executes each function in $TEST_LIST
	export TEST_LIST="$TEST_LIST $1"

else # test is being run directly.
	test_setup
	
	## Subshell is necessary for containment
	( "$1" )
	test_cleanup
fi
IC_NUM=$(($IC_NUM+1))

}

repeat_test() {
## USAGE: 
# repeat_test test_func N var1 ... varN var1_value1 ... var1_valueM ... varN_valueM
# where N is the number of values to substiute and M is the number of 
# values each varable takes
# 
# EXAMPLE
# repeat_test copy_file 2 INPUT OUTPUT infile1 infile2 outfile1 outfile2
# 
# NOTE - all variables MUST have the same number of arguments

if [ "$#" -lt 4 ] ; then
	echo "TEST SYNTAX ERROR: repeat_test() requires at least 4 arguments!"
	exit 255
fi

FUNC="$1"
VARS="$2"
shift 2

## get list of variables
declare -i I=1
while [ "$I" -le "$VARS" ]; do
	eval "v$I=$1"
	shift 1

	eval "out=\$v$I"
	I=$(($I+1))
done

#echo "----"

## $LENGTH is the number of values each variable takes
declare -i LENGTH=$(( $# / $VARS ))
#echo "list size: $LENGTH"

## Main loop: create a test function for each set of values.
declare -i J=1
while [ "$J" -le "$LENGTH" ] ; do
	declare -i I=1
	## Begin test function string

	# it is only safe to use $IC_NUM since run_test is used later in this function.
	str="$FUNC-$J-$IC_NUM() {" 

	while [ "$I" -le "$VARS" ] ; do
		## Assign each value to appropriate variable
		eval "var=\$v$I"
		eval "value=\$$(( ($I-1)*$LENGTH+$J ))"
		#echo "$var: $value"
		str="$str
		$var=\"$value\""
	
		I=$(($I+1))
	done
	## Close the test function and load it
	str="$str
		$FUNC
	}"
	#echo "$str"
	eval "$str"
	run_test "$FUNC-$J-$IC_NUM"

	J=$(($J+1))
done

}

. "$XDG_TEST_DIR/include/tempfile.sh"

test_setup() {
	get_guid "xdgt"
	export XDG_TEST_ID="$GUID"
	get_tmpsubdir "$XDG_TEST_DIR/tmp"
	export XDG_TEST_TMPDIR="$TMPSUBDIR"
	cd "$XDG_TEST_TMPDIR"
	
	get_shortid "$XDG_TEST_DIR/tmp/shortid"
	export XDG_TEST_SHORTID="$SHORTID"
}

test_cleanup() {
	if [ -z "$XDG_TEST_DONT_CLEANUP" ] ; then
		cd "$XDG_TEST_DIR"
		# ALWAYS check what you pass to 'rm -rf'
		[ -d "$XDG_TEST_TMPDIR" ] && rm -rf "$XDG_TEST_TMPDIR"
	fi
}