3 # Common code used run regression tests for usr.bin/make.
5 # $DragonFly: src/usr.bin/make/tests/common.sh,v 1.8 2005/03/02 10:55:37 okumoto Exp $
10 # Output usage messsage.
14 echo "Usage: $0 command"
15 echo " clean - remove temp files"
16 echo " compare - compare result of test to expected"
17 echo " desc - print description of test"
18 echo " diff - print diffs between results and expected"
19 echo " run - run the {test, compare, clean}"
20 echo " test - run test case"
21 echo " update - update the expected with current results"
25 # Check if the test result is the same as the expected result.
26 # First remove the RCS Id tag, check for differences in the files.
27 # We need this function because the CVS repository will not allow
28 # us to check in a file without a DragonFly RCS Id tag.
35 EXPECTED="expected.$1"
38 if [ -f $EXPECTED ]; then
42 1> /dev/null 2> /dev/null
50 # Check if the test result is the same as the expected result.
51 # First remove the RCS Id tag, print the differences in the files.
52 # We need this function because the CVS repository will not allow
53 # us to check in a file without a DragonFly RCS Id tag.
60 EXPECTED="expected.$1"
63 echo diff $EXPECTED $RESULT
64 if [ -f $EXPECTED ]; then
75 # Default run_test() function. It should be replace by the
76 # user specified regression test.
78 # Both the variables SRC_BASE WORK_BASE are available.
82 echo "Missing setup_test() function in $SRC_BASE/test.sh"
86 # Default run_test() function. It can be replace by the
87 # user specified regression test.
89 # Both the variables SRC_BASE WORK_BASE are available.
91 # Note: this function executes from a subshell.
96 $MAKE_PROG 1> stdout 2> stderr
101 # Execute cmd in subdirectory.
105 local SRC_BASE WORK_BASE
108 echo "Test directory '$1' missing in directory '$SRC_BASE'"
112 if [ ! -f $1/test.sh ]; then
113 echo "Test script missing in directory '$SRC_BASE/$1'"
117 SRC_BASE=${SRC_BASE}/$1
118 WORK_BASE=${WORK_BASE}/$1
119 (cd $1; sh ./test.sh $2)
123 # Note: Uses global variable $DIR which might be assigned by
124 # the script which sourced this file.
128 if [ "${DIR}" ]; then
130 # When there are subdirectories defined, recurse
131 # down into them if the cmd is valid.
134 clean|compare|desc|diff|run|test|update|run_output)
136 eval_subdir_cmd $d $1
155 hack_cmp stdout || FAIL="stdout $FAIL"
156 hack_cmp stderr || FAIL="stderr $FAIL"
157 hack_cmp status || FAIL="status $FAIL"
159 if [ ! -z "$FAIL" ]; then
161 echo "$SRC_BASE: Test failed {$FAIL}"
165 echo -n "$SRC_BASE: "
170 echo "------------------------"
172 echo "------------------------"
185 echo "------------------------"
187 echo "------------------------"
188 cat $WORK_BASE/stdout
189 echo "------------------------"
191 echo "------------------------"
192 cat $WORK_BASE/stderr
193 echo "------------------------"
195 echo "------------------------"
197 cat $WORK_BASE/status
201 [ -d $WORK_BASE ] || mkdir -p $WORK_BASE
208 # Preserve the RCS id tag at top of file.
209 # Create initial tag if the file didn't
212 if [ -f "."$SRC_BASE/expected.stdout ]; then
213 head -n 1 "."$SRC_BASE/expected.stdout
216 fi > $WORK_BASE/expected.stdout
218 if [ -f "."$SRC_BASE/expected.stderr ]; then
219 head -n 1 "."$SRC_BASE/expected.stderr
222 fi > $WORK_BASE/expected.stderr
224 if [ -f "."$SRC_BASE/expected.status ]; then
225 head -n 1 "."$SRC_BASE/expected.status
228 fi > $WORK_BASE/expected.status
230 cat $WORK_BASE/stdout >> $WORK_BASE/expected.stdout
231 cat $WORK_BASE/stderr >> $WORK_BASE/expected.stderr
232 cat $WORK_BASE/status >> $WORK_BASE/expected.status
233 mv $WORK_BASE/expected.stdout "."$SRC_BASE/expected.stdout
234 mv $WORK_BASE/expected.stderr "."$SRC_BASE/expected.stderr
235 mv $WORK_BASE/expected.status "."$SRC_BASE/expected.status
245 # Parse command line arguments.
247 args=`getopt m:w:v $*`
276 SRC_BASE=${SRC_BASE:-""}
277 WORK_BASE=${WORK_BASE:-"/tmp/$USER.make.test"}
278 MAKE_PROG=${MAKE_PROG:-/usr/bin/make}