cp _gotest_.o `dirname $package`/lib`basename $package`.a
# Force the test version of the package to be imported first,
- # so that it's type definitions will be used, in case any new
+ # so that its type definitions will be used, in case any new
# methods appear in export_test.go files.
echo "package $xpackage" > _first_test.go
echo 'import _ "'$package'"' >> _first_test.go
done
}
+# Takes an example name and puts any output into the file example.txt.
+# It strips comment markers but does not otherwise change the output.
+exampleoutput() {
+ local n=$(testname $1)
+ local f
+ for f in $gofiles $xgofiles; do
+ if ! grep "^func $n(" $f >/dev/null 2>&1; then
+ continue
+ fi
+ # Copy the output comment, if any, into example.txt.
+ # Remove the comment markers.
+ sed -n "/^func $n(/,/^}$/ p" $f |
+ sed -n '\|// \([Uu]nordered \)\?[Oo]utput:|,$ p' |
+ sed -n '\|//| s|[ ]*// \?||p' > example.txt
+ # Check whether we found an output comment.
+ if ! sed -n '1p' < example.txt | grep '[Oo]utput:' >/dev/null 2>&1; then
+ rm -f example.txt
+ fi
+ return
+ done
+}
+
{
# On systems using PPC64 ELF ABI v1 function symbols show up
# as descriptors in the data section.
pattern='Test([^a-z].*)?'
# The -p option tells GNU nm not to sort.
# The -v option tells Solaris nm to sort by value.
- testsyms=$($NM -p -v _gotest_.o $xofile | egrep " $text .*\."$pattern'$' | fgrep -v ' __go_' | egrep -v '\.\.\w+$' | sed 's/.* //')
+ testsyms=$($NM -p -v _gotest_.o | egrep " $text .*\."$pattern'$' | fgrep -v ' __go_' | egrep -v '\.\.\w+$' | sed 's/.* //')
+ testxsyms=
+ if $havex; then
+ testxsyms=$($NM -p -v $xofile | egrep " $text .*\."$pattern'$' | fgrep -v ' __go_' | egrep -v '\.\.\w+$' | sed 's/.* //')
+ testsyms="$testsyms $testxsyms"
+ fi
tests=$(symtogo "$testsyms")
if [ "x$tests" = x ]; then
echo 'gotest: warning: no tests matching '$pattern in _gotest_.o $xofile 1>&2
fi
# benchmarks are named BenchmarkFoo.
pattern='Benchmark([^a-z].*)?'
- benchmarksyms=$($NM -p -v _gotest_.o $xofile | egrep " $text .*\."$pattern'$' | fgrep -v ' __go_' | egrep -v '\.\.\w+$' | sed 's/.* //')
+ benchmarksyms=$($NM -p -v _gotest_.o | egrep " $text .*\."$pattern'$' | fgrep -v ' __go_' | egrep -v '\.\.\w+$' | sed 's/.* //')
+ if $havex; then
+ benchmarkxsyms=$($NM -p -v $xofile | egrep " $text .*\."$pattern'$' | fgrep -v ' __go_' | egrep -v '\.\.\w+$' | sed 's/.* //')
+ benchmarksyms="$benchmarksyms $benchmarkxsyms"
+ fi
benchmarks=$(symtogo "$benchmarksyms")
# examples are named ExampleFoo
pattern='Example([^a-z].*)?'
- examplesyms=$($NM -p -v _gotest_.o $xofile | egrep " $text .*\."$pattern'$' | fgrep -v ' __go_' | egrep -v '\.\.\w+$' | sed 's/.* //')
+ examplesyms=$($NM -p -v _gotest_.o | egrep " $text .*\."$pattern'$' | fgrep -v ' __go_' | egrep -v '\.\.\w+$' | sed 's/.* //')
+ if $havex; then
+ examplexsyms=$($NM -p -v $xofile | egrep " $text .*\."$pattern'$' | fgrep -v ' __go_' | egrep -v '\.\.\w+$' | sed 's/.* //')
+ examplesyms="$examplesyms $examplexsyms"
+ fi
examples=$(symtogo "$examplesyms")
# package spec
echo 'import "./_gotest_"'
fi
if $havex; then
+ needxtest=false
+ if test -n "$testxsyms" -o -n "$benchmarkxsyms"; then
+ needxtest=true
+ else
+ # Check whether any example has output.
+ for i in $(symtogo "$examplexsyms"); do
+ exampleoutput $i
+ if test -f example.txt; then
+ rm -f example.txt
+ needxtest=true
+ break
+ fi
+ done
+ fi
+ if test x$needxtest = xtrue; then
echo 'import "./_xtest_"'
+ else
+ echo 'import _ "./_xtest_"'
+ fi
fi
echo 'import "testing"'
echo 'import "testing/internal/testdeps"'
# benchmark array
# The comment makes the multiline declaration
# gofmt-safe even when there are no benchmarks.
- echo 'var benchmarks = []testing.InternalBenchmark{ //'
+ echo 'var benchmarks = []testing.InternalBenchmark{'
for i in $benchmarks; do
n=$(testname $i)
j=$(localname $i)
echo '}'
# examples array
- echo 'var examples = []testing.InternalExample{ //'
+ echo 'var examples = []testing.InternalExample{'
for i in $examples; do
n=$(testname $i)
j=$(localname $i)
hasoutput=false
unordered=false
output=
- for f in $gofiles $xgofiles; do
- if ! grep "^func $n(" $f >/dev/null 2>&1; then
- continue
- fi
- # Copy the output comment, if any, into example.txt.
- # Remove the comment markers.
- sed -n "/^func $n(/,/^}$/ p" $f |
- sed -n '\|// \([Uu]nordered \)\?[Oo]utput:|,$ p' |
- sed -n '\|//| s|[ ]*// \?||p' > example.txt
- # Check whether we found an output comment.
- if ! sed -n '1p' < example.txt | grep '[Oo]utput:' >/dev/null 2>&1; then
- # An example with no output is only compiled, not run,
- # so don't add it to the examples slice.
- rm -f example.txt
- break
- fi
- # Check whether the output can be unordered.
- unordered=false
- if sed -n '1p' < example.txt | grep -i unordered; then
- unordered=true
- fi
- # Remove the output header.
- # Quote backslashes.
- # Quote quotation characters.
- # Turn tab into \t.
- # Turn pairs of spaces into " \x20", because $() will
- # drop duplicate spaces.
- # Drop trailing spaces, and turn newlines into \n.
- # Remove leading and trailing \n.
- sed '1 s/\([Uu]nordered \)\?[Oo]utput:[ ]*//' < example.txt |
- sed -e 's/\\/\\\\/g' \
- -e 's/"/\\"/g' \
- -e 's/ /\\t/g' \
- -e 's/ / \\x20/g' \
- -e 's/[ ]*$/\\n/g' |
- tr -d '\n' |
- sed -e 's/^\(\\n\)*//' \
- -e 's/\(\\n\)*$//' > example2.txt
- hasoutput=true
- rm -f example.txt
- break
- done
- if test x$hasoutput = xtrue; then
- echo ' {"'$n'", '$j','
- sed -e 's/^/ "/' -e 's/$/", /' < example2.txt
- echo $unordered'},'
- rm -f example2.txt
+ exampleoutput $i
+ if ! test -f example.txt; then
+ continue
+ fi
+ # Check whether the output can be unordered.
+ unordered=false
+ if sed -n '1p' < example.txt | grep -i unordered >/dev/null 2>&1; then
+ unordered=true
fi
+ # Remove the output header.
+ # Quote backslashes.
+ # Quote quotation characters.
+ # Turn tab into \t.
+ # Turn pairs of spaces into " \x20", because $() will
+ # drop duplicate spaces.
+ # Drop trailing spaces, and turn newlines into \n.
+ # Remove leading and trailing \n.
+ sed '1 s/\([Uu]nordered \)\?[Oo]utput:[ ]*//' < example.txt |
+ sed -e 's/\\/\\\\/g' \
+ -e 's/"/\\"/g' \
+ -e 's/ /\\t/g' \
+ -e 's/ / \\x20/g' \
+ -e 's/[ ]*$/\\n/g' |
+ tr -d '\n' |
+ sed -e 's/^\(\\n\)*//' \
+ -e 's/\(\\n\)*$//' > example2.txt
+ hasoutput=true
+ echo ' {"'$n'", '$j','
+ sed -e 's/^/ "/' -e 's/$/", /' < example2.txt
+ echo $unordered'},'
+ rm -f example.txt example2.txt
done
echo '}'