Add an initial regression test suite for make(1).

Submitted by:	Max Okumoto <okumotu@ucsd.edu> (partly, initial version)
This commit is contained in:
Hartmut Brandt 2005-04-28 13:20:48 +00:00
parent bc2d4d6784
commit 1b26a92962
65 changed files with 958 additions and 0 deletions

View File

@ -0,0 +1,60 @@
$FreeBSD$
This directory contains regression tests for make(1).
The tests are invoked via the test.sh script or prove(1) from p5-Test-Harness
% test.sh [-v] [-m path_to_make_binary] command
clean - Remove the results and the other temp files that
are produced by running the test. This brings the
test into its initial state.
compare - Check if results of the test match the expected
output from stdout, stderr, and the status.
desc - print description of test
diff - Output the diffs from the tests and the expected
stdout, stderr, and the status files.
run - Invoke test, compare, and clean in sequence.
test - Invoke the test code
update - Copy the output of the last test run as the expected
output from stdout, stderr, and the status.
% [MAKE_PROG=path_to_make_binary] prove [options] [files/directories]
Example:
% sh test.t -m `pwd`/../obj/make run
% MAKE_PROG=/usr/obj/usr/src/usr.bin/make/make prove -r
Variables
---------
WORK_BASE - base directory for working files
SRC_BASE - test source base directory
SUBDIR - subdirectory below WORK_BASE and SRC_BASE for current test
WORK_DIR - ${WORK_BASE}/${SUBDIR}
SRC_DIR - ${SRC_BASE}/${SUBDIR}
MAKE_PROG - path to the make program to test
WORK_BASE and MAKE_PROG are intented to be set by the user. All other
variables are set by the script and can be used in scripts.
Directory layout
----------------
common.sh - common code
all.sh - recursively call test scripts
basic/
t0/test.t - regression test
t1/test.t - regression test
t2/test.t - regression test
variables/
t0/test.t - regression test
t1/test.t - regression test
Each test directory should contain at least a test.t script
and the expected output files.

View File

@ -0,0 +1,16 @@
#!/bin/sh
# $FreeBSD$
# find all test scripts below our current directory
SCRIPTS=`find . -name test.t`
if [ -z "${SCRIPTS}" ] ; then
exit 0
fi
for i in ${SCRIPTS} ; do
(
cd `dirname $i`
sh ./test.t $1
)
done

View File

@ -0,0 +1,63 @@
# $FreeBSD$
# This test checks the code reading archive files. The archive file
# is a BSD4.4 file with __.SYMTAB and #1/N long file names.
all:
-@make test_ok1 && echo "1 ok"
-@make test_ok2 && echo "2 ok"
-@make test_ok3 && echo "3 ok"
-@make test_ok4 && echo "4 ok"
-@make test_fail5 || echo "5 ok"
-@make test_fail6 || echo "6 ok"
-@make test_fail7 || echo "7 ok"
#############################################################################
test_ok1: libtest.a(short.o)
@:
libtest.a(short.o): ood
@:
#############################################################################
test_ok2: libtest.a(exactly15char.o)
@:
libtest.a(exactly15char.o): ood
@:
#############################################################################
test_ok3: libtest.a(exactly16chars.o)
@:
libtest.a(exactly16chars.o): ood
@:
#############################################################################
test_ok4: libtest.a(verylongobjectname.o)
@:
libtest.a(verylongobjectname.o): ood
@:
#############################################################################
# Truncated to 16 characters
test_fail5: libtest.a(verylongobjectna)
@:
#############################################################################
# Truncated to 15 characters
test_fail6: libtest.a(verylongobjectn)
@:
#############################################################################
test_fail7: libtest.a(\#1/20)
@:
ood:

View File

@ -0,0 +1 @@
0

View File

@ -0,0 +1,3 @@
make: don't know how to make verylongobjectna. Stop
make: don't know how to make verylongobjectn. Stop
make: don't know how to make #1/20. Stop

View File

@ -0,0 +1,7 @@
1 ok
2 ok
3 ok
4 ok
5 ok
6 ok
7 ok

Binary file not shown.

View File

@ -0,0 +1,18 @@
#!/bin/sh
# $FreeBSD$
cd `dirname $0`
. ../../common.sh
setup_test()
{
cp libtest.a ${WORK_DIR}
}
desc_test()
{
echo "Archive parsing (BSD4.4 format)."
}
eval_cmd $1

View File

@ -0,0 +1,66 @@
# $FreeBSD$
# This test checks the code reading archive files. The archive file
# is a BSD4.4 file with __.SYMTAB and #1/N long file names.
#
# The modification of the archive consists in slashes appended to short names.
#
all:
-@make test_ok1 && echo "1 ok"
-@make test_ok2 && echo "2 ok"
-@make test_ok3 && echo "3 ok"
-@make test_ok4 && echo "4 ok"
-@make test_fail5 || echo "5 ok"
-@make test_fail6 || echo "6 ok"
-@make test_fail7 || echo "7 ok"
#############################################################################
test_ok1: libtest.a(short.o)
@:
libtest.a(short.o): ood
@:
#############################################################################
test_ok2: libtest.a(exactly15char.o)
@:
libtest.a(exactly15char.o): ood
@:
#############################################################################
test_ok3: libtest.a(exactly16chars.o)
@:
libtest.a(exactly16chars.o): ood
@:
#############################################################################
test_ok4: libtest.a(verylongobjectname.o)
@:
libtest.a(verylongobjectname.o): ood
@:
#############################################################################
# Truncated to 16 characters
test_fail5: libtest.a(verylongobjectna)
@:
#############################################################################
# Truncated to 15 characters
test_fail6: libtest.a(verylongobjectn)
@:
#############################################################################
test_fail7: libtest.a(\#1/20)
@:
ood:

View File

@ -0,0 +1 @@
0

View File

@ -0,0 +1,3 @@
make: don't know how to make verylongobjectna. Stop
make: don't know how to make verylongobjectn. Stop
make: don't know how to make #1/20. Stop

View File

@ -0,0 +1,7 @@
1 ok
2 ok
3 ok
4 ok
5 ok
6 ok
7 ok

Binary file not shown.

View File

@ -0,0 +1,18 @@
#!/bin/sh
# $FreeBSD$
cd `dirname $0`
. ../../common.sh
setup_test()
{
cp libtest.a ${WORK_DIR}
}
desc_test()
{
echo "Archive parsing (modified BSD4.4 format)."
}
eval_cmd $1

View File

@ -0,0 +1,64 @@
# $FreeBSD$
# This test checks the code reading archive files. The archive file
# is an old BSD file with __.SYMTAB and no long file names. Filenames
# are truncated to 16 characters.
all:
-@make test_ok1 && echo "1 ok"
-@make test_ok2 && echo "2 ok"
-@make test_ok3 && echo "3 ok"
-@make test_ok4 && echo "4 ok"
-@make test_fail5 && echo "5 ok"
-@make test_fail6 || echo "6 ok"
-@make test_fail7 || echo "7 ok"
#############################################################################
test_ok1: libtest.a(short.o)
@:
libtest.a(short.o): ood
@:
#############################################################################
test_ok2: libtest.a(exactly15char.o)
@:
libtest.a(exactly15char.o): ood
@:
#############################################################################
test_ok3: libtest.a(exactly16chars.o)
@:
libtest.a(exactly16chars.o): ood
@:
#############################################################################
test_ok4: libtest.a(verylongobjectname.o)
@:
libtest.a(verylongobjectname.o): ood
@:
#############################################################################
# Truncated to 16 characters
test_fail5: libtest.a(verylongobjectna)
@:
#############################################################################
# Truncated to 15 characters
test_fail6: libtest.a(verylongobjectn)
@:
#############################################################################
test_fail7: libtest.a(\#1/20)
@:
ood:

View File

@ -0,0 +1 @@
0

View File

@ -0,0 +1,2 @@
make: don't know how to make verylongobjectn. Stop
make: don't know how to make #1/20. Stop

View File

@ -0,0 +1,7 @@
1 ok
2 ok
3 ok
4 ok
5 ok
6 ok
7 ok

Binary file not shown.

View File

@ -0,0 +1,18 @@
#!/bin/sh
# $FreeBSD$
cd `dirname $0`
. ../../common.sh
setup_test()
{
cp libtest.a ${WORK_DIR}
}
desc_test()
{
echo "Archive parsing (old BSD format)."
}
eval_cmd $1

View File

@ -0,0 +1 @@
2

View File

@ -0,0 +1 @@
make: no target to make.

View File

@ -0,0 +1,18 @@
#!/bin/sh
# $FreeBSD$
cd `dirname $0`
. ../../common.sh
setup_test()
{
cp /dev/null ${WORK_DIR}/Makefile
}
desc_test()
{
echo "An empty Makefile file."
}
eval_cmd $1

View File

@ -0,0 +1 @@
0

View File

@ -0,0 +1,20 @@
#!/bin/sh
# $FreeBSD$
cd `dirname $0`
. ../../common.sh
setup_test()
{
cat > ${WORK_DIR}/Makefile << _EOF_
all:
_EOF_
}
desc_test()
{
echo "A Makefile file with only a 'all:' file dependency specification."
}
eval_cmd $1

View File

@ -0,0 +1 @@
0

View File

@ -0,0 +1,2 @@
echo hello
hello

View File

@ -0,0 +1,21 @@
#!/bin/sh
# $FreeBSD$
cd `dirname $0`
. ../../common.sh
setup_test()
{
cat > ${WORK_DIR}/Makefile << _EOF_
all:
echo hello
_EOF_
}
desc_test()
{
echo "A Makefile file with only a 'all:' file dependency specification, and shell command."
}
eval_cmd $1

View File

@ -0,0 +1 @@
2

View File

@ -0,0 +1 @@
make: no target to make.

View File

@ -0,0 +1,18 @@
#!/bin/sh
# $FreeBSD$
cd `dirname $0`
. ../../common.sh
setup_test()
{
rm -f ${WORK_DIR}/Makefile
}
desc_test()
{
echo "No Makefile file."
}
eval_cmd $1

View File

@ -0,0 +1,276 @@
#!/bin/sh
#
# Common code used run regression tests for usr.bin/make.
#
# $FreeBSD$
#
# Output usage messsage.
#
print_usage()
{
echo "Usage: $0 command"
echo " clean - remove temp files (get initial state)"
echo " compare - compare result of test to expected"
echo " desc - print description of test"
echo " diff - print diffs between results and expected"
echo " harness - produce output suiteable for Test::Harness"
echo " run - run the {test, compare, clean}"
echo " test - run test case"
echo " update - update the expected with current results"
}
#
# Check if the test result is the same as the expected result.
#
# $1 Input file
#
hack_cmp()
{
local EXPECTED RESULT
EXPECTED="expected.$1"
RESULT=${WORK_DIR}/$1
if [ -f $EXPECTED ]; then
diff -q $EXPECTED $RESULT 1> /dev/null 2> /dev/null
return $?
else
return 1 # FAIL
fi
}
#
# Check if the test result is the same as the expected result.
#
# $1 Input file
#
hack_diff()
{
local EXPECTED RESULT
EXPECTED="expected.$1"
RESULT=${WORK_DIR}/$1
echo diff -u $EXPECTED $RESULT
if [ -f $EXPECTED ]; then
diff -u $EXPECTED $RESULT
return $?
else
return 1 # FAIL
fi
}
#
# Default setup_test() function.
#
# The default function just does nothing.
#
# Both the variables SRC_BASE WORK_BASE are available.
#
setup_test()
{
}
#
# Default run_test() function. It can be replace by the
# user specified regression test.
#
# Both the variables SRC_BASE WORK_BASE are available.
#
# Note: this function executes from a subshell.
#
run_test()
{
cd ${WORK_DIR}
$MAKE_PROG 1> stdout 2> stderr
echo $? > status
}
#
# Default clean routine
#
clean_test()
{
}
#
# Clean working directory
#
eval_clean()
{
rm -f ${WORK_DIR}/stdout
rm -f ${WORK_DIR}/stderr
rm -f ${WORK_DIR}/status
clean_test
}
#
# Compare results with expected results
#
eval_compare()
{
hack_cmp stdout || FAIL="stdout $FAIL"
hack_cmp stderr || FAIL="stderr $FAIL"
hack_cmp status || FAIL="status $FAIL"
if [ ! -z "$FAIL" ]; then
FAIL=`echo $FAIL`
echo "$SUBDIR: Test failed {$FAIL}"
fi
}
#
# Compare results with expected results for prove(1)
#
eval_hcompare()
{
FAIL=
hack_cmp stdout || FAIL="stdout $FAIL"
hack_cmp stderr || FAIL="stderr $FAIL"
hack_cmp status || FAIL="status $FAIL"
if [ ! -z "$FAIL" ]; then
FAIL=`echo $FAIL`
echo "not ok 1 $SUBDIR # reason: {$FAIL}"
else
echo "ok 1 $SUBDIR"
fi
}
#
# Print description
#
eval_desc()
{
echo -n "$SUBDIR: "
desc_test
}
#
# Prepare and run the test
#
eval_test()
{
[ -d ${WORK_DIR} ] || mkdir -p ${WORK_DIR}
if [ -f Makefile ] ; then
cp Makefile ${WORK_DIR}
fi
setup_test
( run_test )
}
#
# Diff current and expected results
#
eval_diff()
{
eval_test
echo "------------------------"
echo "- $SUBDIR"
echo "------------------------"
hack_diff stdout
hack_diff stderr
hack_diff status
}
#
# Run the test for prove(1)
#
eval_harness()
{
echo 1..1
eval_test
eval_hcompare
eval_clean
}
#
# Run the test
#
eval_run()
{
eval_test
eval_compare
eval_clean
}
#
# Update expected results
#
eval_update()
{
eval_test
cat ${WORK_DIR}/stdout > expected.stdout
cat ${WORK_DIR}/stderr > expected.stderr
cat ${WORK_DIR}/status > expected.status
}
#
# Note: Uses global variable $DIR which might be assigned by
# the script which sourced this file.
#
eval_cmd()
{
if [ $# -eq 0 ] ; then
set -- harness
fi
case $1 in
clean|compare|hcompare|desc|diff|harness|run|test|update)
eval eval_$1
;;
*)
print_usage
;;
esac
}
#
# Parse command line arguments.
#
args=`getopt m:w:v $*`
if [ $? != 0 ]; then
echo 'Usage: ...'
exit 2
fi
set -- $args
for i; do
case "$i" in
-m)
MAKE_PROG="$2"
shift
shift
;;
-w)
WORK_BASE="$2"
shift
shift
;;
-v)
VERBOSE=1
shift
;;
--)
shift
break
;;
esac
done
#
# Determine our sub-directory. Argh.
#
SRC_DIR=`pwd`
SRC_BASE=`while [ ! -f common.sh ] ; do cd .. ; done ; pwd`
SUBDIR=`echo ${SRC_DIR} | sed "s@${SRC_BASE}/@@"`
WORK_BASE=${WORK_BASE:-"/tmp/$USER.make.test"}
WORK_DIR=${WORK_BASE}/${SUBDIR}
MAKE_PROG=${MAKE_PROG:-/usr/bin/make}
export MAKE_PROG
export VERBOSE
export SRC_BASE
export WORK_BASE
export SUBDIR
export SRC_DIR
export WORK_DIR

View File

@ -0,0 +1,11 @@
# $FreeBSD$
all: TEST1.b
diff -u TEST1.a TEST1.b
.SUFFIXES:
.SUFFIXES: .a .b
.a.b:
cat ${.IMPSRC} >${.TARGET}

View File

@ -0,0 +1 @@
I'm test file 1.

View File

@ -0,0 +1 @@
0

View File

@ -0,0 +1,2 @@
cat TEST1.a >TEST1.b
diff -u TEST1.a TEST1.b

View File

@ -0,0 +1,30 @@
#!/bin/sh
# $FreeBSD$
cd `dirname $0`
. ../../common.sh
setup_test()
{
cp TEST1.a $WORK_DIR
}
run_test()
{
cd $WORK_DIR
$MAKE_PROG -r 1>stdout 2>stderr
echo $? >status
}
clean_test()
{
rm -f TEST1.b
}
desc_test()
{
echo "Basic suffix operation."
}
eval_cmd $1

View File

@ -0,0 +1,7 @@
# $FreeBSD$
all: TEST1.b
cat TEST1.a TEST2.a | diff -u - TEST1.b
TEST1.b: *.a
cat ${.ALLSRC} >${.TARGET}

View File

@ -0,0 +1 @@
I'm test file 1.

View File

@ -0,0 +1 @@
I'm test file 2.

View File

@ -0,0 +1 @@
0

View File

@ -0,0 +1,2 @@
cat TEST1.a TEST2.a >TEST1.b
cat TEST1.a TEST2.a | diff -u - TEST1.b

View File

@ -0,0 +1,30 @@
#!/bin/sh
# $FreeBSD$
cd `dirname $0`
. ../../common.sh
setup_test()
{
cp TEST[12].a ${WORK_DIR}
}
run_test()
{
cd ${WORK_DIR}
${MAKE_PROG} -r 1>stdout 2>stderr
echo $? >status
}
clean_test()
{
rm -f TEST1.b
}
desc_test()
{
echo "Source wildcard expansion."
}
eval_cmd $1

View File

@ -0,0 +1,9 @@
# $FreeBSD$
SRC=*.a
all: TEST1.b
cat TEST1.a TEST2.a | diff -u - TEST1.b
TEST1.b: ${SRC}
cat ${.ALLSRC} >${.TARGET}

View File

@ -0,0 +1 @@
I'm test file 1.

View File

@ -0,0 +1 @@
I'm test file 2.

View File

@ -0,0 +1 @@
0

View File

@ -0,0 +1,2 @@
cat TEST1.a TEST2.a >TEST1.b
cat TEST1.a TEST2.a | diff -u - TEST1.b

View File

@ -0,0 +1,30 @@
#!/bin/sh
# $FreeBSD$
cd `dirname $0`
. ../../common.sh
setup_test()
{
cp TEST[12].a ${WORK_DIR}
}
run_test()
{
cd ${WORK_DIR}
${MAKE_PROG} -r 1>stdout 2>stderr
echo $? >status
}
clean_test()
{
rm -f TEST1.b
}
desc_test()
{
echo "Source wildcard expansion."
}
eval_cmd $1

View File

@ -0,0 +1 @@
0

View File

@ -0,0 +1,31 @@
echo 0
0
echo 1
1
echo 0
0
# The following are soo broken why no syntax error?
echo
echo
echo
echo
echo
echo
echo
echo
echo
echo
echo
echo

View File

@ -0,0 +1,38 @@
#!/bin/sh
# $FreeBSD$
cd `dirname $0`
. ../../common.sh
setup_test()
{
cat > ${WORK_DIR}/Makefile << "_EOF_"
A = 0
AV = 1
all:
echo $A
echo ${AV}
echo ${A}
# The following are soo broken why no syntax error?
echo $(
echo $)
echo ${
echo ${A
echo ${A)
echo ${A){
echo ${AV
echo ${AV)
echo ${AV){
echo ${AV{
echo ${A{
echo $}
_EOF_
}
desc_test()
{
echo "Variable expansion."
}
eval_cmd $1

View File

@ -0,0 +1 @@
0

View File

@ -0,0 +1,7 @@
all files: main.c globals.h util.c util.h map.c map.h parser.y lexer.l cmdman.1 format.5
cfiles: main.c util.c map.c
hfiles: globals.h util.h map.h
grammer and lexer: parser.y lexer.l
man page: cmdman.1 format.5
utility files: util.c util.h
m files: main.c map.c map.h

View File

@ -0,0 +1,33 @@
#!/bin/sh
# $FreeBSD$
cd `dirname $0`
. ../../common.sh
setup_test()
{
cat > ${WORK_DIR}/Makefile << "_EOF_"
FILES = \
main.c globals.h \
util.c util.h \
map.c map.h \
parser.y lexer.l \
cmdman.1 format.5
all:
@echo "all files: ${FILES}"
@echo "cfiles: ${FILES:M*.c}"
@echo "hfiles: ${FILES:M*.h}"
@echo "grammer and lexer: ${FILES:M*.[ly]}"
@echo "man page: ${FILES:M*.[1-9]}"
@echo "utility files: ${FILES:Mutil.?}"
@echo "m files: ${FILES:Mm*}"
_EOF_
}
desc_test()
{
echo "Variable expansion with M modifier"
}
eval_cmd $1