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.
24 # First remove the RCS Id tag, check for differences in the files.
25 # We need this function because the CVS repository will not allow
26 # us to check in a file without a DragonFly RCS Id tag.
33 EXPECTED="expected.$1"
36 if [ -f $EXPECTED ]; then
40 1> /dev/null 2> /dev/null
48 # Check if the test result is the same as the expected result.
49 # First remove the RCS Id tag, print the differences in the files.
50 # We need this function because the CVS repository will not allow
51 # us to check in a file without a DragonFly RCS Id tag.
58 EXPECTED="expected.$1"
61 echo diff $EXPECTED $RESULT
62 if [ -f $EXPECTED ]; then
73 # Default run_test() function. It should be replace by the
74 # user specified regression test.
76 # Both the variables SRC_BASE WORK_BASE are available.
80 echo "Missing setup_test() function in $SRC_BASE/test.sh"
84 # Default run_test() function. It can be replace by the
85 # user specified regression test.
87 # Both the variables SRC_BASE WORK_BASE are available.
89 # Note: this function executes from a subshell.
94 $MAKE_PROG 1> stdout 2> stderr
99 # Execute cmd in subdirectory.
103 local SRC_BASE WORK_BASE
106 echo "Test directory '$1' missing in directory '$SRC_BASE'"
110 if [ ! -f $1/test.sh ]; then
111 echo "Test script missing in directory '$SRC_BASE/$1'"
115 SRC_BASE=${SRC_BASE}/$1
116 WORK_BASE=${WORK_BASE}/$1
117 (cd $1; sh ./test.sh $2)
121 # Note: Uses global variable $DIR which might be assigned by
122 # the script which sourced this file.
126 if [ "${DIR}" ]; then
128 # When there are subdirectories defined, recurse
129 # down into them if the cmd is valid.
132 clean|compare|desc|diff|run|test|update|run_output)
134 eval_subdir_cmd $d $1
153 hack_cmp stdout || FAIL="stdout $FAIL"
154 hack_cmp stderr || FAIL="stderr $FAIL"
155 hack_cmp status || FAIL="status $FAIL"
157 if [ ! -z "$FAIL" ]; then
159 echo "$SRC_BASE: Test failed {$FAIL}"
163 echo -n "$SRC_BASE: "
168 echo "------------------------"
170 echo "------------------------"
183 echo "------------------------"
185 echo "------------------------"
186 cat $WORK_BASE/stdout
187 echo "------------------------"
189 echo "------------------------"
190 cat $WORK_BASE/stderr
191 echo "------------------------"
193 echo "------------------------"
195 cat $WORK_BASE/status
199 [ -d $WORK_BASE ] || mkdir -p $WORK_BASE
205 cp $WORK_BASE/stdout "."$SRC_BASE/expected.stdout
206 cp $WORK_BASE/stderr "."$SRC_BASE/expected.stderr
207 cp $WORK_BASE/status "."$SRC_BASE/expected.status
217 # Parse command line arguments.
219 args=`getopt m:w:v $*`
248 SRC_BASE=${SRC_BASE:-""}
249 WORK_BASE=${WORK_BASE:-"/tmp/$USER.make.test"}
250 MAKE_PROG=${MAKE_PROG:-/usr/bin/make}