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 $
8 # Output usage messsage.
12 echo "Usage: $0 command"
13 echo " clean - remove temp files"
14 echo " compare - compare result of test to expected"
15 echo " desc - print description of test"
16 echo " diff - print diffs between results and expected"
17 echo " run - run the {test, compare, clean}"
18 echo " test - run test case"
19 echo " update - update the expected with current results"
23 # Check if the test result is the same as the expected result.
30 EXPECTED="expected.$1"
33 if [ -f $EXPECTED ]; then
34 diff -q $EXPECTED $RESULT 1> /dev/null 2> /dev/null
42 # Check if the test result is the same as the expected result.
49 EXPECTED="expected.$1"
52 echo diff $EXPECTED $RESULT
53 if [ -f $EXPECTED ]; then
54 diff $EXPECTED $RESULT
62 # Default run_test() function. It should be replace by the
63 # user specified regression test.
65 # Both the variables SRC_BASE WORK_BASE are available.
69 echo "Missing setup_test() function in $SRC_BASE/test.sh"
73 # Default run_test() function. It can be replace by the
74 # user specified regression test.
76 # Both the variables SRC_BASE WORK_BASE are available.
78 # Note: this function executes from a subshell.
83 $MAKE_PROG 1> stdout 2> stderr
88 # Execute cmd in subdirectory.
92 local SRC_BASE WORK_BASE
95 echo "Test directory '$1' missing in directory '$SRC_BASE'"
99 if [ ! -f $1/test.sh ]; then
100 echo "Test script missing in directory '$SRC_BASE/$1'"
104 SRC_BASE=${SRC_BASE}/$1
105 WORK_BASE=${WORK_BASE}/$1
106 (cd $1; sh ./test.sh $2)
110 # Note: Uses global variable $DIR which might be assigned by
111 # the script which sourced this file.
115 if [ "${DIR}" ]; then
117 # When there are subdirectories defined, recurse
118 # down into them if the cmd is valid.
121 clean|compare|desc|diff|run|test|update|run_output)
123 eval_subdir_cmd $d $1
142 hack_cmp stdout || FAIL="stdout $FAIL"
143 hack_cmp stderr || FAIL="stderr $FAIL"
144 hack_cmp status || FAIL="status $FAIL"
146 if [ ! -z "$FAIL" ]; then
148 echo "$SRC_BASE: Test failed {$FAIL}"
152 echo -n "$SRC_BASE: "
157 echo "------------------------"
159 echo "------------------------"
172 echo "------------------------"
174 echo "------------------------"
175 cat $WORK_BASE/stdout
176 echo "------------------------"
178 echo "------------------------"
179 cat $WORK_BASE/stderr
180 echo "------------------------"
182 echo "------------------------"
184 cat $WORK_BASE/status
188 [ -d $WORK_BASE ] || mkdir -p $WORK_BASE
194 cp $WORK_BASE/stdout "."$SRC_BASE/expected.stdout
195 cp $WORK_BASE/stderr "."$SRC_BASE/expected.stderr
196 cp $WORK_BASE/status "."$SRC_BASE/expected.status
206 # Parse command line arguments.
208 args=`getopt m:w:v $*`
237 SRC_BASE=${SRC_BASE:-""}
238 WORK_BASE=${WORK_BASE:-"/tmp/$USER.make.test"}
239 MAKE_PROG=${MAKE_PROG:-/usr/bin/make}