2010-12-03 05:34:57 +01:00
|
|
|
#!/bin/sh
|
|
|
|
# Copyright 2009 The Go Authors. All rights reserved.
|
|
|
|
# Use of this source code is governed by a BSD-style
|
|
|
|
# license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
# Using all the *_test.go files in the current directory, write out a file
|
|
|
|
# _testmain.go that runs all its tests. Compile everything and run the
|
|
|
|
# tests.
|
|
|
|
# If files are named on the command line, use them instead of *_test.go.
|
|
|
|
|
|
|
|
# Makes egrep,grep work better in general if we put them
|
|
|
|
# in ordinary C mode instead of what the current language is.
|
|
|
|
unset LANG
|
|
|
|
export LC_ALL=C
|
|
|
|
export LC_CTYPE=C
|
|
|
|
|
|
|
|
GC=${GC:-gccgo}
|
|
|
|
GL=${GL:-${GC-gccgo}}
|
2011-09-27 00:33:31 +02:00
|
|
|
GOLIBS=${GOLIBS:-}
|
2010-12-03 05:34:57 +01:00
|
|
|
export GC GL GOLIBS
|
|
|
|
|
2011-01-13 00:06:13 +01:00
|
|
|
NM=${NM:-nm}
|
|
|
|
|
2010-12-03 05:34:57 +01:00
|
|
|
# srcdir is where the source files are found. basedir is where the
|
|
|
|
# source file paths are relative to.
|
|
|
|
# gofiles are the test files. pkgfiles are the source files.
|
|
|
|
srcdir=.
|
|
|
|
basedir=.
|
|
|
|
gofiles=""
|
|
|
|
pkgfiles=""
|
|
|
|
loop=true
|
|
|
|
keep=false
|
|
|
|
prefix=
|
|
|
|
dejagnu=no
|
2011-09-22 01:02:31 +02:00
|
|
|
timeout=240
|
2011-04-01 01:03:20 +02:00
|
|
|
testname=""
|
2011-09-16 17:47:21 +02:00
|
|
|
trace=false
|
2010-12-03 05:34:57 +01:00
|
|
|
while $loop; do
|
|
|
|
case "x$1" in
|
|
|
|
x--srcdir)
|
|
|
|
srcdir=$2
|
|
|
|
shift
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
x--srcdir=*)
|
|
|
|
srcdir=`echo $1 | sed -e 's/^--srcdir=//'`
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
x--basedir)
|
|
|
|
basedir=$2
|
|
|
|
shift
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
x--basedir=*)
|
|
|
|
basedir=`echo $1 | sed -e 's/^--basedir=//'`
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
x--prefix)
|
|
|
|
prefix=$2
|
|
|
|
shift
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
x--prefix=*)
|
|
|
|
prefix=`echo $1 | sed -e 's/^--prefix=//'`
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
x--keep)
|
|
|
|
keep=true
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
x--pkgfiles)
|
|
|
|
pkgfiles=$2
|
|
|
|
shift
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
x--pkgfiles=*)
|
|
|
|
pkgfiles=`echo $1 | sed -e 's/^--pkgfiles=//'`
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
x--dejagnu)
|
|
|
|
dejagnu=$2
|
|
|
|
shift
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
x--dejagnu=*)
|
|
|
|
dejagnu=`echo $1 | sed -e 's/^--dejagnu=//'`
|
|
|
|
shift
|
|
|
|
;;
|
2011-04-01 00:36:10 +02:00
|
|
|
x--timeout)
|
|
|
|
timeout=$2
|
|
|
|
shift
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
x--timeout=*)
|
|
|
|
timeout=`echo $1 | sed -e 's/^--timeout=//'`
|
|
|
|
shift
|
|
|
|
;;
|
2011-04-01 01:03:20 +02:00
|
|
|
x--testname)
|
|
|
|
testname=$2
|
|
|
|
shift
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
x--testname=*)
|
|
|
|
testname=`echo $1 | sed -e 's/^--testname=//'`
|
|
|
|
shift
|
|
|
|
;;
|
2011-09-16 17:47:21 +02:00
|
|
|
x--trace)
|
|
|
|
trace=true
|
|
|
|
shift
|
|
|
|
;;
|
2010-12-03 05:34:57 +01:00
|
|
|
x-*)
|
|
|
|
loop=false
|
|
|
|
;;
|
|
|
|
x)
|
|
|
|
loop=false
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
gofiles="$gofiles $1"
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
DIR=gotest$$
|
|
|
|
rm -rf $DIR
|
|
|
|
mkdir $DIR
|
|
|
|
|
|
|
|
cd $DIR
|
|
|
|
|
|
|
|
if test $keep = false; then
|
|
|
|
trap "cd ..; rm -rf $DIR" 0 1 2 3 14 15
|
|
|
|
else
|
|
|
|
trap "cd ..; echo Keeping $DIR" 0 1 2 3 14 15
|
|
|
|
fi
|
|
|
|
|
|
|
|
case "$srcdir" in
|
|
|
|
/*)
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
srcdir="../$srcdir"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
SRCDIR=$srcdir
|
|
|
|
export SRCDIR
|
|
|
|
|
|
|
|
case "$basedir" in
|
|
|
|
/*)
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
basedir="../$basedir"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
# Link all the files/directories in srcdir into our working directory,
|
|
|
|
# so that the tests do not have to refer to srcdir to find test data.
|
|
|
|
ln -s $srcdir/* .
|
|
|
|
|
2011-03-17 00:05:44 +01:00
|
|
|
# Some tests refer to a ../testdata directory.
|
|
|
|
if test -e $srcdir/../testdata; then
|
|
|
|
rm -f ../testdata
|
|
|
|
abssrcdir=`cd $srcdir && pwd`
|
|
|
|
ln -s $abssrcdir/../testdata ../testdata
|
|
|
|
fi
|
|
|
|
|
2010-12-03 05:34:57 +01:00
|
|
|
# Copy the .go files because io/utils_test.go expects a regular file.
|
|
|
|
case "x$gofiles" in
|
|
|
|
x)
|
|
|
|
case "x$pkgfiles" in
|
|
|
|
x)
|
|
|
|
for f in `cd $srcdir; ls *.go`; do
|
|
|
|
rm -f $f;
|
|
|
|
cp $srcdir/$f .
|
|
|
|
done
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
for f in $pkgfiles; do
|
|
|
|
if test -f $basedir/$f; then
|
|
|
|
b=`basename $f`
|
|
|
|
rm -f $b
|
|
|
|
cp $basedir/$f $b
|
|
|
|
elif test -f ../$f; then
|
|
|
|
b=`basename $f`
|
|
|
|
rm -f $b
|
|
|
|
cp ../$f $b
|
|
|
|
else
|
|
|
|
echo "file $f not found" 1>&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
for f in `cd $srcdir; ls *_test.go`; do
|
|
|
|
rm -f $f
|
|
|
|
cp $srcdir/$f .
|
|
|
|
done
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
for f in $gofiles; do
|
|
|
|
b=`basename $f`
|
|
|
|
rm -f $b
|
|
|
|
cp $basedir/$f $b
|
|
|
|
done
|
|
|
|
case "x$pkgfiles" in
|
|
|
|
x)
|
|
|
|
for f in `cd $srcdir; ls *.go | grep -v *_test.go`; do
|
|
|
|
rm -f $f
|
|
|
|
cp $srcdir/$f .
|
|
|
|
done
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
for f in $pkgfiles; do
|
|
|
|
if test -f $basedir/$f; then
|
|
|
|
b=`basename $f`
|
|
|
|
rm -f $b
|
|
|
|
cp $basedir/$f $b
|
|
|
|
elif test -f ../$f; then
|
|
|
|
b=`basename $f`
|
|
|
|
rm -f $b
|
|
|
|
cp ../$f $b
|
|
|
|
else
|
|
|
|
echo "file $f not found" 1>&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
# Some tests expect the _obj directory created by the gc Makefiles.
|
|
|
|
mkdir _obj
|
|
|
|
|
|
|
|
# Some tests expect the _test directory created by the gc Makefiles.
|
|
|
|
mkdir _test
|
|
|
|
|
|
|
|
case "x$gofiles" in
|
|
|
|
x)
|
2011-04-05 21:53:33 +02:00
|
|
|
gofiles=`ls *_test.go 2>/dev/null`
|
2010-12-03 05:34:57 +01:00
|
|
|
esac
|
|
|
|
|
|
|
|
case "x$gofiles" in
|
|
|
|
x)
|
|
|
|
echo 'no test files found' 1>&2
|
|
|
|
exit 1
|
|
|
|
esac
|
|
|
|
|
|
|
|
# Run any commands given in sources, like
|
|
|
|
# // gotest: $GC foo.go
|
|
|
|
# to build any test-only dependencies.
|
|
|
|
holdGC="$GC"
|
|
|
|
GC="$GC -g -c -I ."
|
|
|
|
sed -n 's/^\/\/ gotest: //p' $gofiles | sh
|
|
|
|
GC="$holdGC"
|
|
|
|
|
|
|
|
case "x$pkgfiles" in
|
|
|
|
x)
|
2011-04-05 21:53:33 +02:00
|
|
|
pkgbasefiles=`ls *.go | grep -v _test.go 2>/dev/null`
|
2010-12-03 05:34:57 +01:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
for f in $pkgfiles; do
|
|
|
|
pkgbasefiles="$pkgbasefiles `basename $f`"
|
|
|
|
done
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
case "x$pkgfiles" in
|
|
|
|
x)
|
|
|
|
echo 'no source files found' 1>&2
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
# Split $gofiles into external gofiles (those in *_test packages)
|
|
|
|
# and internal ones (those in the main package).
|
|
|
|
xgofiles=$(echo $(grep '^package[ ]' $gofiles /dev/null | grep ':.*_test' | sed 's/:.*//'))
|
|
|
|
gofiles=$(echo $(grep '^package[ ]' $gofiles /dev/null | grep -v ':.*_test' | sed 's/:.*//'))
|
|
|
|
|
|
|
|
# External $O file
|
|
|
|
xofile=""
|
|
|
|
havex=false
|
|
|
|
if [ "x$xgofiles" != "x" ]; then
|
|
|
|
xofile="_xtest_.o"
|
|
|
|
havex=true
|
|
|
|
fi
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
package=`echo ${srcdir} | sed -e 's|^.*libgo/go/||'`
|
|
|
|
|
|
|
|
prefixarg=
|
|
|
|
if test -n "$prefix"; then
|
|
|
|
prefixarg="-fgo-prefix=$prefix"
|
|
|
|
fi
|
|
|
|
|
2011-09-16 17:47:21 +02:00
|
|
|
if test "$trace" = "true"; then
|
|
|
|
echo $GC -g $prefixarg -c -I . -fno-toplevel-reorder -o _gotest_.o $gofiles $pkgbasefiles
|
|
|
|
fi
|
2011-07-13 03:04:50 +02:00
|
|
|
$GC -g $prefixarg -c -I . -fno-toplevel-reorder -o _gotest_.o $gofiles $pkgbasefiles
|
2011-09-16 17:47:21 +02:00
|
|
|
|
2010-12-03 05:34:57 +01:00
|
|
|
if $havex; then
|
|
|
|
mkdir -p `dirname $package`
|
|
|
|
cp _gotest_.o `dirname $package`/lib`basename $package`.a
|
2011-09-16 17:47:21 +02:00
|
|
|
if test "$trace" = "true"; then
|
|
|
|
echo $GC -g -c -I . -fno-toplevel-reorder -o $xofile $xgofiles
|
|
|
|
fi
|
2011-07-13 03:04:50 +02:00
|
|
|
$GC -g -c -I . -fno-toplevel-reorder -o $xofile $xgofiles
|
2010-12-03 05:34:57 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
# They all compile; now generate the code to call them.
|
2011-03-25 00:46:17 +01:00
|
|
|
|
|
|
|
localname() {
|
|
|
|
# The package main has been renamed to __main__ when imported.
|
|
|
|
# Adjust its uses.
|
|
|
|
echo $1 | sed 's/^main\./__main__./'
|
|
|
|
}
|
|
|
|
|
2010-12-03 05:34:57 +01:00
|
|
|
{
|
|
|
|
# test functions are named TestFoo
|
|
|
|
# the grep -v eliminates methods and other special names
|
|
|
|
# that have multiple dots.
|
|
|
|
pattern='Test([^a-z].*)?'
|
2011-03-10 01:51:14 +01:00
|
|
|
# The -p option tells GNU nm not to sort.
|
|
|
|
# The -v option tells Solaris nm to sort by value.
|
2012-01-06 22:47:49 +01:00
|
|
|
tests=$($NM -p -v _gotest_.o $xofile | egrep ' T .*\.'$pattern'$' | grep -v '\..*\..*\.' | fgrep -v '$' | sed 's/.* //' | sed 's/.*\.\(.*\.\)/\1/')
|
2010-12-03 05:34:57 +01:00
|
|
|
if [ "x$tests" = x ]; then
|
|
|
|
echo 'gotest: warning: no tests matching '$pattern in _gotest_.o $xofile 1>&2
|
|
|
|
exit 2
|
|
|
|
fi
|
2011-03-25 00:46:17 +01:00
|
|
|
# benchmarks are named BenchmarkFoo.
|
|
|
|
pattern='Benchmark([^a-z].*)?'
|
2012-01-06 22:47:49 +01:00
|
|
|
benchmarks=$($NM -p -v _gotest_.o $xofile | egrep ' T .*\.'$pattern'$' | grep -v '\..*\..*\.' | fgrep -v '$' | sed 's/.* //' | sed 's/.*\.\(.*\.\)/\1/')
|
2010-12-03 05:34:57 +01:00
|
|
|
|
2011-10-27 01:57:58 +02:00
|
|
|
# examples are named ExampleFoo
|
|
|
|
pattern='Example([^a-z].*)?'
|
2012-01-06 22:47:49 +01:00
|
|
|
examples=$($NM -p -v _gotest_.o $xofile | egrep ' T .*\.'$pattern'$' | grep -v '\..*\..*\.' | fgrep -v '$' | sed 's/.* //' | sed 's/.*\.\(.*\.\)/\1/')
|
2011-10-27 01:57:58 +02:00
|
|
|
|
2010-12-03 05:34:57 +01:00
|
|
|
# package spec
|
|
|
|
echo 'package main'
|
|
|
|
echo
|
|
|
|
# imports
|
|
|
|
if echo "$tests" | egrep -v '_test\.' >/dev/null; then
|
|
|
|
echo 'import "./_gotest_"'
|
|
|
|
fi
|
|
|
|
if $havex; then
|
|
|
|
echo 'import "./_xtest_"'
|
|
|
|
fi
|
2011-03-25 00:46:17 +01:00
|
|
|
echo 'import "testing"'
|
|
|
|
echo 'import __regexp__ "regexp"' # rename in case tested package is called regexp
|
2010-12-03 05:34:57 +01:00
|
|
|
# test array
|
|
|
|
echo
|
|
|
|
echo 'var tests = []testing.InternalTest {'
|
|
|
|
for i in $tests
|
|
|
|
do
|
2011-03-25 00:46:17 +01:00
|
|
|
j=$(localname $i)
|
|
|
|
echo ' {"'$i'", '$j'},'
|
2010-12-03 05:34:57 +01:00
|
|
|
done
|
|
|
|
echo '}'
|
2011-10-27 01:57:58 +02:00
|
|
|
|
2011-03-25 00:46:17 +01:00
|
|
|
# benchmark array
|
|
|
|
# The comment makes the multiline declaration
|
|
|
|
# gofmt-safe even when there are no benchmarks.
|
|
|
|
echo 'var benchmarks = []testing.InternalBenchmark{ //'
|
|
|
|
for i in $benchmarks
|
|
|
|
do
|
|
|
|
j=$(localname $i)
|
|
|
|
echo ' {"'$i'", '$j'},'
|
|
|
|
done
|
2010-12-03 05:34:57 +01:00
|
|
|
echo '}'
|
2011-10-27 01:57:58 +02:00
|
|
|
|
|
|
|
# examples array
|
|
|
|
echo 'var examples = []testing.InternalExample{ //'
|
|
|
|
# This doesn't work because we don't pick up the output.
|
|
|
|
#for i in $examples
|
|
|
|
#do
|
|
|
|
# j=$(localname $i)
|
|
|
|
# echo ' {"'$i'", '$j', ""},'
|
|
|
|
#done
|
|
|
|
echo '}'
|
|
|
|
|
2011-03-25 00:46:17 +01:00
|
|
|
# body
|
|
|
|
echo \
|
|
|
|
'
|
|
|
|
var matchPat string
|
|
|
|
var matchRe *__regexp__.Regexp
|
|
|
|
|
2011-12-03 03:17:34 +01:00
|
|
|
func matchString(pat, str string) (result bool, err error) {
|
2011-03-25 00:46:17 +01:00
|
|
|
if matchRe == nil || matchPat != pat {
|
|
|
|
matchPat = pat
|
|
|
|
matchRe, err = __regexp__.Compile(matchPat)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return matchRe.MatchString(str), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
2011-10-27 01:57:58 +02:00
|
|
|
testing.Main(matchString, tests, benchmarks, examples)
|
2011-03-25 00:46:17 +01:00
|
|
|
}'
|
2010-12-03 05:34:57 +01:00
|
|
|
}>_testmain.go
|
|
|
|
|
|
|
|
case "x$dejagnu" in
|
|
|
|
xno)
|
2011-09-16 17:47:21 +02:00
|
|
|
if test "$trace" = "true"; then
|
|
|
|
echo ${GC} -g -c _testmain.go
|
|
|
|
fi
|
2010-12-03 05:34:57 +01:00
|
|
|
${GC} -g -c _testmain.go
|
2011-09-16 17:47:21 +02:00
|
|
|
|
|
|
|
if test "$trace" = "true"; then
|
|
|
|
echo ${GL} *.o ${GOLIBS}
|
|
|
|
fi
|
2010-12-03 05:34:57 +01:00
|
|
|
${GL} *.o ${GOLIBS}
|
2011-04-05 23:11:35 +02:00
|
|
|
|
2011-09-16 17:47:21 +02:00
|
|
|
if test "$trace" = "true"; then
|
|
|
|
echo ./a.out -test.short -test.timeout=$timeout "$@"
|
|
|
|
fi
|
2011-04-05 23:11:35 +02:00
|
|
|
./a.out -test.short -test.timeout=$timeout "$@" &
|
|
|
|
pid=$!
|
|
|
|
(sleep `expr $timeout + 10`
|
|
|
|
echo > gotest-timeout
|
|
|
|
echo "timed out in gotest" 1>&2
|
|
|
|
kill -9 $pid) &
|
|
|
|
alarmpid=$!
|
|
|
|
wait $pid
|
|
|
|
status=$?
|
|
|
|
if ! test -f gotest-timeout; then
|
|
|
|
kill $alarmpid
|
|
|
|
fi
|
|
|
|
exit $status
|
2010-12-03 05:34:57 +01:00
|
|
|
;;
|
|
|
|
xyes)
|
2011-01-12 22:56:10 +01:00
|
|
|
rm -rf ../testsuite/*.o
|
|
|
|
files=`echo *`
|
|
|
|
for f in $files; do
|
|
|
|
if test "$f" = "_obj" || test "$f" = "_test"; then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
rm -rf ../testsuite/$f
|
|
|
|
if test -f $f; then
|
|
|
|
cp $f ../testsuite/
|
|
|
|
else
|
|
|
|
ln -s ../$DIR/$f ../testsuite/
|
|
|
|
fi
|
|
|
|
done
|
2010-12-03 05:34:57 +01:00
|
|
|
cd ../testsuite
|
2011-01-12 22:56:10 +01:00
|
|
|
rm -rf _obj _test
|
|
|
|
mkdir _obj _test
|
2011-04-01 01:03:20 +02:00
|
|
|
if test "$testname" != ""; then
|
|
|
|
GOTESTNAME="$testname"
|
|
|
|
export GOTESTNAME
|
|
|
|
fi
|
2010-12-03 05:34:57 +01:00
|
|
|
$MAKE check RUNTESTFLAGS="$RUNTESTFLAGS GOTEST_TMPDIR=$DIR"
|
|
|
|
# Useful when using make check-target-libgo
|
|
|
|
cat libgo.log >> libgo-all.log
|
|
|
|
cat libgo.sum >> libgo-all.sum
|
2011-01-12 22:56:10 +01:00
|
|
|
rm -rf $files
|
2010-12-03 05:34:57 +01:00
|
|
|
;;
|
|
|
|
esac
|