3 # Common code used run regression tests for usr.bin/make.
5 # $DragonFly: src/usr.bin/make/tests/common.sh,v 1.3 2005/02/26 11:51:54 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 # We can't check a file into CVS without a DragonFly RCS Id tag, so
26 # we need to remove it before we compare.
34 1> /dev/null 2> /dev/null
42 # We can't check a file into CVS without a DragonFly RCS Id tag, so
43 # we need to remove it before we compare.
59 # Default run_test() function. It should be replace by the
60 # user specified regression test.
64 echo "Missing run_test() function in $START_BASE/test.sh"
68 # Execute cmd in subdirectory.
75 echo "Test directory '$1' missing in directory '$START_BASE'"
79 if [ ! -f $1/test.sh ]; then
80 echo "Test script missing in directory '$START_BASE/$1'"
84 START_BASE=${START_BASE}/$1
85 (cd $1; sh ./test.sh $2)
89 # Note: Uses global variable $DIR which might be assigned by
90 # the script which sourced this file.
96 # When there are subdirectories defined, recurse
97 # down into them if the cmd is valid.
100 clean|compare|desc|diff|run|test|update)
102 eval_subdir_cmd $d $1
121 hack_cmp expected.stdout stdout || FAIL="stdout, "$FAIL
122 hack_cmp expected.stderr stderr || FAIL="stderr, "$FAIL
123 hack_cmp expected.status status || FAIL="status, "$FAIL
125 if [ -z "$FAIL" ]; then
128 echo "$START_BASE: Test failed {$FAIL}" |\
133 echo -n "$START_BASE: "
138 echo "------------------------"
140 echo "------------------------"
141 hack_diff expected.stdout stdout
142 hack_diff expected.stderr stderr
143 hack_diff expected.status status
155 # Create expected files if they don't exist.
156 [ -f expected.stdout ] || echo $IDTAG > expected.stdout
157 [ -f expected.stderr ] || echo $IDTAG > expected.stderr
158 [ -f expected.status ] || echo $IDTAG > expected.status
160 # Remove previous contents of expected files, and
161 # replace them with the new contents.
162 sed -e '2,$d' < expected.stdout > new.expected.stdout
163 sed -e '2,$d' < expected.stderr > new.expected.stderr
164 sed -e '2,$d' < expected.status > new.expected.status
165 cat stdout >> new.expected.stdout
166 cat stderr >> new.expected.stderr
167 cat status >> new.expected.status
168 mv new.expected.stdout expected.stdout
169 mv new.expected.stderr expected.stderr
170 mv new.expected.status expected.status
180 # Parse command line arguments.
206 START_BASE=${START_BASE:-.}
207 MAKE=${MAKE:-/usr/bin/make}