Commit c8530c41 by Ian Lance Taylor

re PR go/89168 (FAIL: cmd/go/internal/load)

	PR go/89168
    libgo: change gotest to run examples with output
    
    Change the gotest script to act like "go test" and run examples that
    have "output" comments.  This is not done with full generality, but
    just enough to run the libgo tests.  Other packages should be tested
    with "go test" as usual.
    
    While we're here clean up some old bits of gotest, and only run
    TestXXX functions that are actually in *_test.go files.  The latter
    change should fix https://gcc.gnu.org/PR89168.
    
    Reviewed-on: https://go-review.googlesource.com/c/162139

From-SVN: r268922
parent b90fff0c
c2fc3b83d832725accd4fa5874a5b5ca02dd90dc 4a6f2bb2c8d3f00966f001a5b03c57cb4a278265
The first line of this file holds the git revision number of the last The first line of this file holds the git revision number of the last
merge done from the gofrontend repository. merge done from the gofrontend repository.
...@@ -31,7 +31,7 @@ func ExampleFrames() { ...@@ -31,7 +31,7 @@ func ExampleFrames() {
// To keep this example's output stable // To keep this example's output stable
// even if there are changes in the testing package, // even if there are changes in the testing package,
// stop unwinding when we leave package runtime. // stop unwinding when we leave package runtime.
if !strings.Contains(frame.File, "runtime/") { if !strings.Contains(frame.File, "runtime/") && !strings.Contains(frame.File, "/test/") {
break break
} }
fmt.Printf("- more:%v | %s\n", more, frame.Function) fmt.Printf("- more:%v | %s\n", more, frame.Function)
...@@ -47,8 +47,8 @@ func ExampleFrames() { ...@@ -47,8 +47,8 @@ func ExampleFrames() {
a() a()
// Output: // Output:
// - more:true | runtime.Callers // - more:true | runtime.Callers
// - more:true | runtime_test.ExampleFrames.func1 // - more:true | runtime_test.ExampleFrames..func1
// - more:true | runtime_test.ExampleFrames.func2 // - more:true | runtime_test.ExampleFrames..func2
// - more:true | runtime_test.ExampleFrames.func3 // - more:true | runtime_test.ExampleFrames..func3
// - more:true | runtime_test.ExampleFrames // - more:true | runtime_test.ExampleFrames
} }
...@@ -289,12 +289,6 @@ x) ...@@ -289,12 +289,6 @@ x)
;; ;;
esac esac
# Some tests expect the _obj directory created by the gc Makefiles.
mkdir _obj
# Some tests expect the _test directory created by the gc Makefiles.
mkdir _test
case "x$gofiles" in case "x$gofiles" in
x) x)
for f in `ls *_test.go`; do for f in `ls *_test.go`; do
...@@ -404,14 +398,6 @@ x) ...@@ -404,14 +398,6 @@ x)
;; ;;
esac esac
# Run any commands given in sources, like
# // gotest: $GC foo.go
# to build any test-only dependencies.
holdGC="$GC"
GC="$GC -g -c -I ."
sed -n 's/^\/\/ gotest: //p' $gofiles | sh
GC="$holdGC"
case "x$pkgfiles" in case "x$pkgfiles" in
x) x)
pkgbasefiles=`ls *.go | grep -v _test.go 2>/dev/null` pkgbasefiles=`ls *.go | grep -v _test.go 2>/dev/null`
...@@ -514,26 +500,29 @@ localname() { ...@@ -514,26 +500,29 @@ localname() {
# #
symtogo() { symtogo() {
result="" result=""
for tp in $* for tp in $*; do
do
s=$(echo "$tp" | sed -e 's/\.\.z2f/%/g' | sed -e 's/.*%//') s=$(echo "$tp" | sed -e 's/\.\.z2f/%/g' | sed -e 's/.*%//')
# screen out methods (X.Y.Z) # Screen out methods (X.Y.Z).
if ! expr "$s" : '^[^.]*\.[^.]*$' >/dev/null 2>&1; then if ! expr "$s" : '^[^.]*\.[^.]*$' >/dev/null 2>&1; then
continue continue
fi fi
tname=$(testname $s)
# Skip TestMain.
if test x$tname = xTestMain; then
continue
fi
# Check that the function is defined in a test file,
# not an ordinary non-test file.
if grep "^func $tname(" $gofiles $xgofiles >/dev/null 2>&1; then
echo "$s" echo "$s"
fi
done done
} }
{ {
text="T"
# On systems using PPC64 ELF ABI v1 function symbols show up # On systems using PPC64 ELF ABI v1 function symbols show up
# as descriptors in the data section. We assume that $goarch # as descriptors in the data section.
# distinguishes v1 (ppc64) from v2 (ppc64le).
if test "$goos" != "aix" && test "$goarch" = "ppc64"; then
text="[TD]" text="[TD]"
fi
# test functions are named TestFoo # test functions are named TestFoo
# the grep -v eliminates methods and other special names # the grep -v eliminates methods and other special names
...@@ -575,13 +564,10 @@ symtogo() { ...@@ -575,13 +564,10 @@ symtogo() {
# test array # test array
echo echo
echo 'var tests = []testing.InternalTest {' echo 'var tests = []testing.InternalTest {'
for i in $tests for i in $tests; do
do
n=$(testname $i) n=$(testname $i)
if test "$n" != "TestMain"; then
j=$(localname $i) j=$(localname $i)
echo ' {"'$n'", '$j'},' echo ' {"'$n'", '$j'},'
fi
done done
echo '}' echo '}'
...@@ -589,8 +575,7 @@ symtogo() { ...@@ -589,8 +575,7 @@ symtogo() {
# The comment makes the multiline declaration # The comment makes the multiline declaration
# gofmt-safe even when there are no benchmarks. # gofmt-safe even when there are no benchmarks.
echo 'var benchmarks = []testing.InternalBenchmark{ //' echo 'var benchmarks = []testing.InternalBenchmark{ //'
for i in $benchmarks for i in $benchmarks; do
do
n=$(testname $i) n=$(testname $i)
j=$(localname $i) j=$(localname $i)
echo ' {"'$n'", '$j'},' echo ' {"'$n'", '$j'},'
...@@ -599,13 +584,58 @@ symtogo() { ...@@ -599,13 +584,58 @@ symtogo() {
# examples array # examples array
echo 'var examples = []testing.InternalExample{ //' echo 'var examples = []testing.InternalExample{ //'
# This doesn't work because we don't pick up the output. for i in $examples; do
#for i in $examples n=$(testname $i)
#do j=$(localname $i)
# n=$(testname $i) # Look for a //output comment.
# j=$(localname $i) hasoutput=false
# echo ' {"'$n'", '$j', ""},' unordered=false
#done 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.
output="$(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')"
# Remove leading and trailing \n.
output="$(echo "$output" | sed -e 's/^\(\\n\)*//' -e 's/\(\\n\)*$//')"
hasoutput=true
rm -f example.txt
break
done
if test x$hasoutput = xtrue; then
echo ' {"'$n'", '$j', "'"$output"'", '$unordered'},'
fi
done
echo '}' echo '}'
# body # body
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment