keep=false
prefix=
dejagnu=no
+GOARCH=""
timeout=240
testname=""
trace=false
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
# 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=""
}
{
+ 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'
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
echo ' {"'$i'", '$j'},'
done
echo '}'
+
# benchmark array
# The comment makes the multiline declaration
# gofmt-safe even when there are no benchmarks.
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)
}
func main() {
- testing.Main(matchString, tests, benchmarks)
+ testing.Main(matchString, tests, benchmarks, examples)
}'
}>_testmain.go
${GL} *.o ${GOLIBS}
if test "$trace" = "true"; then
- echo ./a.out -test.short -test.timeout=$timeout "$@"
+ echo ./a.out -test.short -test.timeout=${timeout}s "$@"
fi
- ./a.out -test.short -test.timeout=$timeout "$@" &
+ ./a.out -test.short -test.timeout=${timeout}s "$@" &
pid=$!
(sleep `expr $timeout + 10`
echo > gotest-timeout