OSDN Git Service

gotest: Don't get confused by data tables named Test on PPC.
[pf3gnuchains/gcc-fork.git] / libgo / testsuite / gotest
index 938f475..c6966fa 100755 (executable)
@@ -16,7 +16,7 @@ export LC_CTYPE=C
 
 GC=${GC:-gccgo}
 GL=${GL:-${GC-gccgo}}
-GOLIBS=
+GOLIBS=${GOLIBS:-}
 export GC GL GOLIBS
 
 NM=${NM:-nm}
@@ -32,8 +32,10 @@ loop=true
 keep=false
 prefix=
 dejagnu=no
-timeout=60
+GOARCH=""
+timeout=240
 testname=""
+trace=false
 while $loop; do
        case "x$1" in
         x--srcdir)
@@ -85,6 +87,15 @@ while $loop; do
                dejagnu=`echo $1 | sed -e 's/^--dejagnu=//'`
                shift
                ;;
+       x--goarch)
+               GOARCH=$2
+               shift
+               shift
+               ;;
+       x--goarch=*)
+               GOARCH=`echo $1 | sed -e 's/^--goarch=//'`
+               shift
+               ;;
        x--timeout)
                timeout=$2
                shift
@@ -103,6 +114,10 @@ while $loop; do
                testname=`echo $1 | sed -e 's/^--testname=//'`
                shift
                ;;
+       x--trace)
+               trace=true
+               shift
+               ;;
        x-*)
                loop=false
                ;;
@@ -268,8 +283,18 @@ 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/:.*//'))
+for f in $gofiles; do
+    package=`grep '^package[   ]' $f | sed 1q`
+    case "$package" in
+    *_test)
+       xgofiles="$xgofiles $f"
+       ;;
+    *)
+       ngofiles="$ngofiles $f"
+       ;;
+    esac
+done
+gofiles=$ngofiles
 
 # External $O file
 xofile=""
@@ -288,10 +313,17 @@ if test -n "$prefix"; then
        prefixarg="-fgo-prefix=$prefix"
 fi
 
+if test "$trace" = "true"; then
+  echo $GC -g $prefixarg -c -I . -fno-toplevel-reorder -o _gotest_.o $gofiles $pkgbasefiles
+fi
 $GC -g $prefixarg -c -I . -fno-toplevel-reorder -o _gotest_.o $gofiles $pkgbasefiles
+
 if $havex; then
        mkdir -p `dirname $package`
        cp _gotest_.o `dirname $package`/lib`basename $package`.a
+       if test "$trace" = "true"; then
+           echo $GC -g -c -I . -fno-toplevel-reorder -o $xofile $xgofiles
+       fi
        $GC -g -c -I . -fno-toplevel-reorder -o $xofile $xgofiles
 fi
 
@@ -304,20 +336,29 @@ localname() {
 }
 
 {
+       text="T"
+       case "$GOARCH" in
+       ppc*) text="D" ;;
+       esac
+
        # test functions are named TestFoo
        # the grep -v eliminates methods and other special names
        # that have multiple dots.
        pattern='Test([^a-z].*)?'
        # The -p option tells GNU nm not to sort.
        # The -v option tells Solaris nm to sort by value.
-       tests=$($NM -p -v _gotest_.o $xofile | egrep ' T .*\.'$pattern'$' | grep -v '\..*\..*\.' | sed 's/.* //' | sed 's/.*\.\(.*\.\)/\1/')
+       tests=$($NM -p -v _gotest_.o $xofile | egrep " $text .*\."$pattern'$' | grep -v '\..*\..*\.' | fgrep -v '$' | fgrep -v ' __go_' | sed 's/.* //' | sed 's/.*\.\(.*\.\)/\1/')
        if [ "x$tests" = x ]; then
                echo 'gotest: warning: no tests matching '$pattern in _gotest_.o $xofile 1>&2
                exit 2
        fi
        # benchmarks are named BenchmarkFoo.
        pattern='Benchmark([^a-z].*)?'
-       benchmarks=$($NM -p -v _gotest_.o $xofile | egrep ' T .*\.'$pattern'$' | grep -v '\..*\..*\.' | sed 's/.* //' | sed 's/.*\.\(.*\.\)/\1/')
+       benchmarks=$($NM -p -v _gotest_.o $xofile | egrep " $test .*\."$pattern'$' | grep -v '\..*\..*\.' | fgrep -v '$' | fgrep -v ' __go_' | sed 's/.* //' | sed 's/.*\.\(.*\.\)/\1/')
+
+       # examples are named ExampleFoo
+       pattern='Example([^a-z].*)?'
+       examples=$($NM -p -v _gotest_.o $xofile | egrep " $text .*\."$pattern'$' | grep -v '\..*\..*\.' | fgrep -v '$' | fgrep -v ' __go_' | sed 's/.* //' | sed 's/.*\.\(.*\.\)/\1/')
 
        # package spec
        echo 'package main'
@@ -330,7 +371,6 @@ localname() {
                echo 'import "./_xtest_"'
        fi
        echo 'import "testing"'
-       echo 'import __os__     "os"' # rename in case tested package is called os
        echo 'import __regexp__ "regexp"' # rename in case tested package is called regexp
        # test array
        echo
@@ -341,6 +381,7 @@ localname() {
                echo '  {"'$i'", '$j'},'
        done
        echo '}'
+
        # benchmark array
        # The comment makes the multiline declaration
        # gofmt-safe even when there are no benchmarks.
@@ -351,13 +392,24 @@ localname() {
                echo '  {"'$i'", '$j'},'
        done
        echo '}'
+
+       # 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 '}'
+
        # body
        echo \
 '
 var matchPat string
 var matchRe *__regexp__.Regexp
 
-func matchString(pat, str string) (result bool, err __os__.Error) {
+func matchString(pat, str string) (result bool, err error) {
        if matchRe == nil || matchPat != pat {
                matchPat = pat
                matchRe, err = __regexp__.Compile(matchPat)
@@ -369,16 +421,26 @@ func matchString(pat, str string) (result bool, err __os__.Error) {
 }
 
 func main() {
-       testing.Main(matchString, tests, benchmarks)
+       testing.Main(matchString, tests, benchmarks, examples)
 }'
 }>_testmain.go
 
 case "x$dejagnu" in
 xno)
+       if test "$trace" = "true"; then
+           echo ${GC} -g -c _testmain.go
+       fi
        ${GC} -g -c _testmain.go
+
+       if test "$trace" = "true"; then
+           echo ${GL} *.o ${GOLIBS}
+       fi
        ${GL} *.o ${GOLIBS}
 
-       ./a.out -test.short -test.timeout=$timeout "$@" &
+       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