Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(68)

Side by Side Diff: third_party/xdg-utils/tests/include/testcontrol.sh

Issue 151098: Patch from mdm@google.com... (Closed) Base URL: svn://chrome-svn/chrome/trunk/deps/
Patch Set: Created 11 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1
2 if [ -z "$IC_NUM" ] ; then
3 declare -i IC_NUM=1
4 fi
5
6 run_test() {
7 ## USAGE:
8 # run_test test_func
9
10 # if tests are being run with TET or the test runner
11 if [ ! -z "$USING_TET" -o ! -z "$USING_TEST_RUNNER" ]; then
12 ## The TET framework REQUIRES variables of the form $ic1 ... $icN
13 ## where each variable is a list of test functions. Here, there is only
14 ## one test function per $icN variable. Each $icN variable MUST be prese nt
15 ## in the $iclist
16 export ic$IC_NUM="$1"
17 export iclist="$iclist ic$IC_NUM"
18
19 ## The standalone test runner executes each function in $TEST_LIST
20 export TEST_LIST="$TEST_LIST $1"
21
22 else # test is being run directly.
23 test_setup
24
25 ## Subshell is necessary for containment
26 ( "$1" )
27 test_cleanup
28 fi
29 IC_NUM=$(($IC_NUM+1))
30
31 }
32
33 repeat_test() {
34 ## USAGE:
35 # repeat_test test_func N var1 ... varN var1_value1 ... var1_valueM ... varN_val ueM
36 # where N is the number of values to substiute and M is the number of
37 # values each varable takes
38 #
39 # EXAMPLE
40 # repeat_test copy_file 2 INPUT OUTPUT infile1 infile2 outfile1 outfile2
41 #
42 # NOTE - all variables MUST have the same number of arguments
43
44 if [ "$#" -lt 4 ] ; then
45 echo "TEST SYNTAX ERROR: repeat_test() requires at least 4 arguments!"
46 exit 255
47 fi
48
49 FUNC="$1"
50 VARS="$2"
51 shift 2
52
53 ## get list of variables
54 declare -i I=1
55 while [ "$I" -le "$VARS" ]; do
56 eval "v$I=$1"
57 shift 1
58
59 eval "out=\$v$I"
60 I=$(($I+1))
61 done
62
63 #echo "----"
64
65 ## $LENGTH is the number of values each variable takes
66 declare -i LENGTH=$(( $# / $VARS ))
67 #echo "list size: $LENGTH"
68
69 ## Main loop: create a test function for each set of values.
70 declare -i J=1
71 while [ "$J" -le "$LENGTH" ] ; do
72 declare -i I=1
73 ## Begin test function string
74
75 # it is only safe to use $IC_NUM since run_test is used later in this fu nction.
76 str="$FUNC-$J-$IC_NUM() {"
77
78 while [ "$I" -le "$VARS" ] ; do
79 ## Assign each value to appropriate variable
80 eval "var=\$v$I"
81 eval "value=\$$(( ($I-1)*$LENGTH+$J ))"
82 #echo "$var: $value"
83 str="$str
84 $var=\"$value\""
85
86 I=$(($I+1))
87 done
88 ## Close the test function and load it
89 str="$str
90 $FUNC
91 }"
92 #echo "$str"
93 eval "$str"
94 run_test "$FUNC-$J-$IC_NUM"
95
96 J=$(($J+1))
97 done
98
99 }
100
101 . "$XDG_TEST_DIR/include/tempfile.sh"
102
103 test_setup() {
104 get_guid "xdgt"
105 export XDG_TEST_ID="$GUID"
106 get_tmpsubdir "$XDG_TEST_DIR/tmp"
107 export XDG_TEST_TMPDIR="$TMPSUBDIR"
108 cd "$XDG_TEST_TMPDIR"
109
110 get_shortid "$XDG_TEST_DIR/tmp/shortid"
111 export XDG_TEST_SHORTID="$SHORTID"
112 }
113
114 test_cleanup() {
115 if [ -z "$XDG_TEST_DONT_CLEANUP" ] ; then
116 cd "$XDG_TEST_DIR"
117 # ALWAYS check what you pass to 'rm -rf'
118 [ -d "$XDG_TEST_TMPDIR" ] && rm -rf "$XDG_TEST_TMPDIR"
119 fi
120 }
121
OLDNEW
« no previous file with comments | « third_party/xdg-utils/tests/include/testassertions.sh ('k') | third_party/xdg-utils/tests/include/testfuncs.sh » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698