summaryrefslogtreecommitdiff
path: root/libgo/testsuite/gotest
diff options
context:
space:
mode:
Diffstat (limited to 'libgo/testsuite/gotest')
-rwxr-xr-xlibgo/testsuite/gotest77
1 files changed, 58 insertions, 19 deletions
diff --git a/libgo/testsuite/gotest b/libgo/testsuite/gotest
index 155c7a8619..3596d727ff 100755
--- a/libgo/testsuite/gotest
+++ b/libgo/testsuite/gotest
@@ -36,6 +36,7 @@ dejagnu=no
GOARCH=""
timeout=240
testname=""
+bench=""
trace=false
while $loop; do
case "x$1" in
@@ -124,6 +125,15 @@ while $loop; do
testname=`echo $1 | sed -e 's/^--testname=//'`
shift
;;
+ x--bench)
+ bench=$2
+ shift
+ shift
+ ;;
+ x--bench=*)
+ bench=`echo $1 | sed -e 's/^--bench=//'`
+ shift
+ ;;
x--trace)
trace=true
shift
@@ -325,6 +335,15 @@ if [ "x$xgofiles" != "x" ]; then
havex=true
fi
+testmain=
+if $havex && fgrep 'func TestMain(' $xgofiles >/dev/null 2>&1; then
+ package=`grep '^package[ ]' $xgofiles | sed 1q | sed -e 's/.* //'`
+ testmain="${package}.TestMain"
+elif test -n "$gofiles" && fgrep 'func TestMain(' $gofiles >/dev/null 2>&1; then
+ package=`grep '^package[ ]' $gofiles | sed 1q | sed -e 's/.* //'`
+ testmain="${package}.TestMain"
+fi
+
set -e
package=`echo ${srcdir} | sed -e 's|^.*libgo/go/||'`
@@ -369,7 +388,7 @@ localname() {
{
text="T"
case "$GOARCH" in
- ppc64) text="[TD]" ;;
+ ppc64*) text="[TD]" ;;
esac
symtogo='sed -e s/_test/XXXtest/ -e s/.*_\([^_]*\.\)/\1/ -e s/XXXtest/_test/'
@@ -405,14 +424,19 @@ localname() {
fi
echo 'import "testing"'
echo 'import __regexp__ "regexp"' # rename in case tested package is called regexp
+ if ! test -n "$testmain"; then
+ echo 'import __os__ "os"'
+ fi
# test array
echo
echo 'var tests = []testing.InternalTest {'
for i in $tests
do
n=$(testname $i)
- j=$(localname $i)
- echo ' {"'$n'", '$j'},'
+ if test "$n" != "TestMain"; then
+ j=$(localname $i)
+ echo ' {"'$n'", '$j'},'
+ fi
done
echo '}'
@@ -457,8 +481,15 @@ func matchString(pat, str string) (result bool, err error) {
}
func main() {
- testing.Main(matchString, tests, benchmarks, examples)
-}'
+ m := testing.MainStart(matchString, tests, benchmarks, examples)
+'
+ if test -n "$testmain"; then
+ echo " ${testmain}(m)"
+ else
+ echo ' __os__.Exit(m.Run())'
+ fi
+
+ echo '}'
}>_testmain.go
case "x$dejagnu" in
@@ -473,20 +504,28 @@ xno)
fi
${GL} *.o ${GOLIBS}
- if test "$trace" = "true"; then
- echo ./a.out -test.short -test.timeout=${timeout}s "$@"
- fi
- ./a.out -test.short -test.timeout=${timeout}s "$@" &
- 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
+ if test "$bench" = ""; then
+ if test "$trace" = "true"; then
+ echo ./a.out -test.short -test.timeout=${timeout}s "$@"
+ fi
+ ./a.out -test.short -test.timeout=${timeout}s "$@" &
+ 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
+ else
+ if test "$trace" = "true"; then
+ echo ./a.out -test.run=^\$ -test.bench="${bench}" "$@"
+ fi
+ ./a.out -test.run=^\$ -test.bench="${bench}" "$@"
+ status=$?
fi
exit $status
;;