diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2020-01-09 23:14:57 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2020-01-09 23:14:57 +0000 |
commit | fcee603081c754044e682f9263f526fcefc9442c (patch) | |
tree | fd799d5e04409a5f50a3570151d4ef62c558bb09 /libgo/testsuite | |
parent | acd43917df56f8845b1497d939da97f4e22b5ebb (diff) | |
download | gcc-fcee603081c754044e682f9263f526fcefc9442c.zip gcc-fcee603081c754044e682f9263f526fcefc9442c.tar.gz gcc-fcee603081c754044e682f9263f526fcefc9442c.tar.bz2 |
libgo: compile examples in _test packages
Previously if the only names defined by _test packages were examples,
the gotest script would emit an incorrect _testmain.go file.
I worked around that by marking the example_test.go files +build ignored.
This CL changes the gotest script to handle this case correctly,
and removes the now-unnecessary build tags.
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/214039
From-SVN: r280085
Diffstat (limited to 'libgo/testsuite')
-rwxr-xr-x | libgo/testsuite/gotest | 142 |
1 files changed, 89 insertions, 53 deletions
diff --git a/libgo/testsuite/gotest b/libgo/testsuite/gotest index 4f1a2f8..4293db9 100755 --- a/libgo/testsuite/gotest +++ b/libgo/testsuite/gotest @@ -475,7 +475,7 @@ if $havex; then 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 @@ -535,6 +535,28 @@ symtogo() { 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. @@ -546,7 +568,12 @@ symtogo() { 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 @@ -554,12 +581,20 @@ symtogo() { 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 @@ -570,7 +605,25 @@ symtogo() { 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"' @@ -590,7 +643,7 @@ symtogo() { # 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) @@ -599,7 +652,7 @@ symtogo() { echo '}' # examples array - echo 'var examples = []testing.InternalExample{ //' + echo 'var examples = []testing.InternalExample{' for i in $examples; do n=$(testname $i) j=$(localname $i) @@ -607,54 +660,37 @@ symtogo() { 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 '}' |