[gcc/devel/ranger] libgo: compile examples in _test packages

Aldy Hernandez aldyh@gcc.gnu.org
Wed Jun 17 17:47:25 GMT 2020


https://gcc.gnu.org/g:fcee603081c754044e682f9263f526fcefc9442c

commit fcee603081c754044e682f9263f526fcefc9442c
Author: Ian Lance Taylor <ian@gcc.gnu.org>
Date:   Thu Jan 9 23:14:57 2020 +0000

    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

Diff:
---
 gcc/go/gofrontend/MERGE                            |   2 +-
 libgo/go/compress/flate/example_test.go            |   2 -
 libgo/go/compress/gzip/example_test.go             |   2 -
 libgo/go/container/ring/example_test.go            |   2 -
 libgo/go/crypto/sha256/example_test.go             |   2 -
 libgo/go/database/sql/example_cli_test.go          |   2 -
 libgo/go/database/sql/example_service_test.go      |   2 -
 libgo/go/encoding/csv/example_test.go              |   2 -
 libgo/go/encoding/hex/example_test.go              |   2 -
 libgo/go/encoding/json/example_marshaling_test.go  |   2 -
 .../encoding/json/example_text_marshaling_test.go  |   2 -
 libgo/go/encoding/pem/example_test.go              |   2 -
 libgo/go/encoding/xml/example_marshaling_test.go   |   2 -
 .../encoding/xml/example_text_marshaling_test.go   |   2 -
 libgo/go/fmt/example_test.go                       |   2 -
 libgo/go/fmt/gostringer_example_test.go            |   2 -
 libgo/go/fmt/stringer_example_test.go              |   2 -
 libgo/go/go/types/example_test.go                  |   6 +-
 libgo/go/hash/crc32/example_test.go                |   2 -
 libgo/go/hash/example_test.go                      |   2 -
 libgo/go/html/example_test.go                      |   2 -
 libgo/go/html/template/example_test.go             |   2 -
 libgo/go/html/template/examplefiles_test.go        |   2 -
 libgo/go/image/draw/example_test.go                |   2 -
 libgo/go/image/png/example_test.go                 |   2 -
 libgo/go/index/suffixarray/example_test.go         |   2 -
 libgo/go/io/ioutil/example_test.go                 |   2 -
 libgo/go/io/ioutil/testdata/hello                  |   1 +
 libgo/go/log/syslog/example_test.go                |   1 -
 libgo/go/math/big/example_rat_test.go              |   2 -
 libgo/go/math/big/floatexample_test.go             |   2 -
 libgo/go/math/bits/example_test.go                 |   2 -
 libgo/go/math/cmplx/example_test.go                |   2 -
 libgo/go/mime/example_test.go                      |   2 -
 libgo/go/mime/quotedprintable/example_test.go      |   2 -
 .../net/http/cookiejar/dummy_publicsuffix_test.go  |   2 -
 libgo/go/net/http/cookiejar/example_test.go        |   2 -
 libgo/go/net/http/httptrace/example_test.go        |   2 -
 libgo/go/net/http/httputil/example_test.go         |   2 -
 libgo/go/net/mail/example_test.go                  |   2 -
 libgo/go/path/filepath/example_test.go             |   2 -
 libgo/go/runtime/trace/example_test.go             |   2 -
 libgo/go/text/scanner/example_test.go              |   2 -
 libgo/testsuite/gotest                             | 142 +++++++++++++--------
 44 files changed, 94 insertions(+), 136 deletions(-)

diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index e712bef1332..9189bed5e89 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-f9d1bfb3eec2d388c5f239779fd25a580064dd9d
+92ee4c2e295fc760105f187f6ea6dc65c81fa892
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
diff --git a/libgo/go/compress/flate/example_test.go b/libgo/go/compress/flate/example_test.go
index 3d44dde7ae1..578009248f5 100644
--- a/libgo/go/compress/flate/example_test.go
+++ b/libgo/go/compress/flate/example_test.go
@@ -2,8 +2,6 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build ignore
-
 package flate_test
 
 import (
diff --git a/libgo/go/compress/gzip/example_test.go b/libgo/go/compress/gzip/example_test.go
index 4764bcb090a..ce29e9ba365 100644
--- a/libgo/go/compress/gzip/example_test.go
+++ b/libgo/go/compress/gzip/example_test.go
@@ -2,8 +2,6 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build ignore
-
 package gzip_test
 
 import (
diff --git a/libgo/go/container/ring/example_test.go b/libgo/go/container/ring/example_test.go
index d8f16390eef..30bd0d74c9e 100644
--- a/libgo/go/container/ring/example_test.go
+++ b/libgo/go/container/ring/example_test.go
@@ -2,8 +2,6 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build ignore
-
 package ring_test
 
 import (
diff --git a/libgo/go/crypto/sha256/example_test.go b/libgo/go/crypto/sha256/example_test.go
index 89d5c977787..7d73120155c 100644
--- a/libgo/go/crypto/sha256/example_test.go
+++ b/libgo/go/crypto/sha256/example_test.go
@@ -2,8 +2,6 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build ignore
-
 package sha256_test
 
 import (
diff --git a/libgo/go/database/sql/example_cli_test.go b/libgo/go/database/sql/example_cli_test.go
index c87c508a141..8c61d755bb8 100644
--- a/libgo/go/database/sql/example_cli_test.go
+++ b/libgo/go/database/sql/example_cli_test.go
@@ -2,8 +2,6 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build ignore
-
 package sql_test
 
 import (
diff --git a/libgo/go/database/sql/example_service_test.go b/libgo/go/database/sql/example_service_test.go
index 7605e2f75d3..768307c1471 100644
--- a/libgo/go/database/sql/example_service_test.go
+++ b/libgo/go/database/sql/example_service_test.go
@@ -2,8 +2,6 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build ignore
-
 package sql_test
 
 import (
diff --git a/libgo/go/encoding/csv/example_test.go b/libgo/go/encoding/csv/example_test.go
index e3c3bd51228..dc227d4c8ba 100644
--- a/libgo/go/encoding/csv/example_test.go
+++ b/libgo/go/encoding/csv/example_test.go
@@ -2,8 +2,6 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build ignore
-
 package csv_test
 
 import (
diff --git a/libgo/go/encoding/hex/example_test.go b/libgo/go/encoding/hex/example_test.go
index fb1554eba7e..3580757a541 100644
--- a/libgo/go/encoding/hex/example_test.go
+++ b/libgo/go/encoding/hex/example_test.go
@@ -2,8 +2,6 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build ignore
-
 package hex_test
 
 import (
diff --git a/libgo/go/encoding/json/example_marshaling_test.go b/libgo/go/encoding/json/example_marshaling_test.go
index 1c4f783a693..7f15c742b8e 100644
--- a/libgo/go/encoding/json/example_marshaling_test.go
+++ b/libgo/go/encoding/json/example_marshaling_test.go
@@ -2,8 +2,6 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build ignore
-
 package json_test
 
 import (
diff --git a/libgo/go/encoding/json/example_text_marshaling_test.go b/libgo/go/encoding/json/example_text_marshaling_test.go
index a8a3f830f68..04c7813b267 100644
--- a/libgo/go/encoding/json/example_text_marshaling_test.go
+++ b/libgo/go/encoding/json/example_text_marshaling_test.go
@@ -2,8 +2,6 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build ignore
-
 package json_test
 
 import (
diff --git a/libgo/go/encoding/pem/example_test.go b/libgo/go/encoding/pem/example_test.go
index 22081b4d8ac..806e7bbbf72 100644
--- a/libgo/go/encoding/pem/example_test.go
+++ b/libgo/go/encoding/pem/example_test.go
@@ -2,8 +2,6 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build ignore
-
 package pem_test
 
 import (
diff --git a/libgo/go/encoding/xml/example_marshaling_test.go b/libgo/go/encoding/xml/example_marshaling_test.go
index 04d3470cac0..9f9e801e74e 100644
--- a/libgo/go/encoding/xml/example_marshaling_test.go
+++ b/libgo/go/encoding/xml/example_marshaling_test.go
@@ -2,8 +2,6 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build ignore
-
 package xml_test
 
 import (
diff --git a/libgo/go/encoding/xml/example_text_marshaling_test.go b/libgo/go/encoding/xml/example_text_marshaling_test.go
index 8d1f3325783..2549cb16ae5 100644
--- a/libgo/go/encoding/xml/example_text_marshaling_test.go
+++ b/libgo/go/encoding/xml/example_text_marshaling_test.go
@@ -2,8 +2,6 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build ignore
-
 package xml_test
 
 import (
diff --git a/libgo/go/fmt/example_test.go b/libgo/go/fmt/example_test.go
index ae60abef0b2..5962834226b 100644
--- a/libgo/go/fmt/example_test.go
+++ b/libgo/go/fmt/example_test.go
@@ -2,8 +2,6 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build ignore
-
 package fmt_test
 
 import (
diff --git a/libgo/go/fmt/gostringer_example_test.go b/libgo/go/fmt/gostringer_example_test.go
index 7c6b9f05453..ab19ee3b94d 100644
--- a/libgo/go/fmt/gostringer_example_test.go
+++ b/libgo/go/fmt/gostringer_example_test.go
@@ -2,8 +2,6 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build ignore
-
 package fmt_test
 
 import (
diff --git a/libgo/go/fmt/stringer_example_test.go b/libgo/go/fmt/stringer_example_test.go
index aa3cd05e3ef..c77e78809cc 100644
--- a/libgo/go/fmt/stringer_example_test.go
+++ b/libgo/go/fmt/stringer_example_test.go
@@ -2,8 +2,6 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build ignore
-
 package fmt_test
 
 import (
diff --git a/libgo/go/go/types/example_test.go b/libgo/go/go/types/example_test.go
index a2e481bd300..5619d20d494 100644
--- a/libgo/go/go/types/example_test.go
+++ b/libgo/go/go/types/example_test.go
@@ -5,7 +5,7 @@
 // Only run where builders (build.golang.org) have
 // access to compiled packages for import.
 //
-// +build ignore,!arm,!arm64,!nacl
+// +build !arm,!arm64,!nacl
 
 package types_test
 
@@ -77,7 +77,7 @@ func Unused() { {}; {{ var x int; _ = x }} } // make sure empty block scopes get
 	rx := regexp.MustCompile(` 0x[a-fA-F0-9]*`)
 	fmt.Println(rx.ReplaceAllString(buf.String(), ""))
 
-	// Output:
+	// no output for gccgo--can't import "fmt"
 	// package "temperature" scope {
 	// .  const temperature.Boiling temperature.Celsius
 	// .  type temperature.Celsius float64
@@ -147,7 +147,7 @@ func (c *Celsius) SetF(f float64) { *c = Celsius(f - 32 / 9 * 5) }
 		fmt.Println()
 	}
 
-	// Output:
+	// no output for gccgo--can't import "fmt"
 	// Method set of temperature.Celsius:
 	// method (temperature.Celsius) String() string
 	//
diff --git a/libgo/go/hash/crc32/example_test.go b/libgo/go/hash/crc32/example_test.go
index a1d9e165280..621bf838309 100644
--- a/libgo/go/hash/crc32/example_test.go
+++ b/libgo/go/hash/crc32/example_test.go
@@ -2,8 +2,6 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build ignore
-
 package crc32_test
 
 import (
diff --git a/libgo/go/hash/example_test.go b/libgo/go/hash/example_test.go
index 49dc8fc8abb..f07b9aaa2c4 100644
--- a/libgo/go/hash/example_test.go
+++ b/libgo/go/hash/example_test.go
@@ -2,8 +2,6 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build ignore
-
 package hash_test
 
 import (
diff --git a/libgo/go/html/example_test.go b/libgo/go/html/example_test.go
index d0f0a9bd850..0e28cac1be5 100644
--- a/libgo/go/html/example_test.go
+++ b/libgo/go/html/example_test.go
@@ -2,8 +2,6 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build ignore
-
 package html_test
 
 import (
diff --git a/libgo/go/html/template/example_test.go b/libgo/go/html/template/example_test.go
index 80107a63239..533c0dd9616 100644
--- a/libgo/go/html/template/example_test.go
+++ b/libgo/go/html/template/example_test.go
@@ -2,8 +2,6 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build ignore
-
 package template_test
 
 import (
diff --git a/libgo/go/html/template/examplefiles_test.go b/libgo/go/html/template/examplefiles_test.go
index ffca8d5a787..60518aee9ec 100644
--- a/libgo/go/html/template/examplefiles_test.go
+++ b/libgo/go/html/template/examplefiles_test.go
@@ -2,8 +2,6 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build ignore
-
 package template_test
 
 import (
diff --git a/libgo/go/image/draw/example_test.go b/libgo/go/image/draw/example_test.go
index d381c1c67fd..2ccc2f4acdb 100644
--- a/libgo/go/image/draw/example_test.go
+++ b/libgo/go/image/draw/example_test.go
@@ -2,8 +2,6 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build ignore
-
 package draw_test
 
 import (
diff --git a/libgo/go/image/png/example_test.go b/libgo/go/image/png/example_test.go
index 2a03be5a1a0..c4376320041 100644
--- a/libgo/go/image/png/example_test.go
+++ b/libgo/go/image/png/example_test.go
@@ -2,8 +2,6 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build ignore
-
 package png_test
 
 import (
diff --git a/libgo/go/index/suffixarray/example_test.go b/libgo/go/index/suffixarray/example_test.go
index a23a58026be..ea10bfd06a1 100644
--- a/libgo/go/index/suffixarray/example_test.go
+++ b/libgo/go/index/suffixarray/example_test.go
@@ -2,8 +2,6 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build ignore
-
 package suffixarray_test
 
 import (
diff --git a/libgo/go/io/ioutil/example_test.go b/libgo/go/io/ioutil/example_test.go
index 3066c94ee32..a7d340b77fa 100644
--- a/libgo/go/io/ioutil/example_test.go
+++ b/libgo/go/io/ioutil/example_test.go
@@ -2,8 +2,6 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build ignore
-
 package ioutil_test
 
 import (
diff --git a/libgo/go/io/ioutil/testdata/hello b/libgo/go/io/ioutil/testdata/hello
new file mode 100644
index 00000000000..e47c092a51a
--- /dev/null
+++ b/libgo/go/io/ioutil/testdata/hello
@@ -0,0 +1 @@
+Hello, Gophers!
diff --git a/libgo/go/log/syslog/example_test.go b/libgo/go/log/syslog/example_test.go
index 0513b26da17..3d5b76d219c 100644
--- a/libgo/go/log/syslog/example_test.go
+++ b/libgo/go/log/syslog/example_test.go
@@ -2,7 +2,6 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build ignore
 // +build !windows,!nacl,!plan9
 
 package syslog_test
diff --git a/libgo/go/math/big/example_rat_test.go b/libgo/go/math/big/example_rat_test.go
index f3127bb4717..a97117001c0 100644
--- a/libgo/go/math/big/example_rat_test.go
+++ b/libgo/go/math/big/example_rat_test.go
@@ -2,8 +2,6 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build ignore
-
 package big_test
 
 import (
diff --git a/libgo/go/math/big/floatexample_test.go b/libgo/go/math/big/floatexample_test.go
index 8645c44f103..0c6668c93bc 100644
--- a/libgo/go/math/big/floatexample_test.go
+++ b/libgo/go/math/big/floatexample_test.go
@@ -2,8 +2,6 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build ignore
-
 package big_test
 
 import (
diff --git a/libgo/go/math/bits/example_test.go b/libgo/go/math/bits/example_test.go
index 14cea6f700e..b2ed2cba4bf 100644
--- a/libgo/go/math/bits/example_test.go
+++ b/libgo/go/math/bits/example_test.go
@@ -4,8 +4,6 @@
 
 // Code generated by go run make_examples.go. DO NOT EDIT.
 
-// +build ignore
-
 package bits_test
 
 import (
diff --git a/libgo/go/math/cmplx/example_test.go b/libgo/go/math/cmplx/example_test.go
index be87cff5ef1..f0ed9631142 100644
--- a/libgo/go/math/cmplx/example_test.go
+++ b/libgo/go/math/cmplx/example_test.go
@@ -2,8 +2,6 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build ignore
-
 package cmplx_test
 
 import (
diff --git a/libgo/go/mime/example_test.go b/libgo/go/mime/example_test.go
index 12aafdc06d7..c7d13cdcdb5 100644
--- a/libgo/go/mime/example_test.go
+++ b/libgo/go/mime/example_test.go
@@ -2,8 +2,6 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build ignore
-
 package mime_test
 
 import (
diff --git a/libgo/go/mime/quotedprintable/example_test.go b/libgo/go/mime/quotedprintable/example_test.go
index 0593b049355..5a9ab450a3c 100644
--- a/libgo/go/mime/quotedprintable/example_test.go
+++ b/libgo/go/mime/quotedprintable/example_test.go
@@ -2,8 +2,6 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build ignore
-
 package quotedprintable_test
 
 import (
diff --git a/libgo/go/net/http/cookiejar/dummy_publicsuffix_test.go b/libgo/go/net/http/cookiejar/dummy_publicsuffix_test.go
index 748ec5cc431..9b3117358f8 100644
--- a/libgo/go/net/http/cookiejar/dummy_publicsuffix_test.go
+++ b/libgo/go/net/http/cookiejar/dummy_publicsuffix_test.go
@@ -2,8 +2,6 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build ignore
-
 package cookiejar_test
 
 import "net/http/cookiejar"
diff --git a/libgo/go/net/http/cookiejar/example_test.go b/libgo/go/net/http/cookiejar/example_test.go
index 19a57465ff6..91728ca9821 100644
--- a/libgo/go/net/http/cookiejar/example_test.go
+++ b/libgo/go/net/http/cookiejar/example_test.go
@@ -2,8 +2,6 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build ignore
-
 package cookiejar_test
 
 import (
diff --git a/libgo/go/net/http/httptrace/example_test.go b/libgo/go/net/http/httptrace/example_test.go
index 27cdcdec31b..07fdc0a4726 100644
--- a/libgo/go/net/http/httptrace/example_test.go
+++ b/libgo/go/net/http/httptrace/example_test.go
@@ -2,8 +2,6 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build ignore
-
 package httptrace_test
 
 import (
diff --git a/libgo/go/net/http/httputil/example_test.go b/libgo/go/net/http/httputil/example_test.go
index e8dc962d3e3..61916036745 100644
--- a/libgo/go/net/http/httputil/example_test.go
+++ b/libgo/go/net/http/httputil/example_test.go
@@ -2,8 +2,6 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build ignore
-
 package httputil_test
 
 import (
diff --git a/libgo/go/net/mail/example_test.go b/libgo/go/net/mail/example_test.go
index 972cfd6c424..c3365642aa4 100644
--- a/libgo/go/net/mail/example_test.go
+++ b/libgo/go/net/mail/example_test.go
@@ -2,8 +2,6 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build ignore
-
 package mail_test
 
 import (
diff --git a/libgo/go/path/filepath/example_test.go b/libgo/go/path/filepath/example_test.go
index d019c260c58..a1d680e4a05 100644
--- a/libgo/go/path/filepath/example_test.go
+++ b/libgo/go/path/filepath/example_test.go
@@ -2,8 +2,6 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build ignore
-
 package filepath_test
 
 import (
diff --git a/libgo/go/runtime/trace/example_test.go b/libgo/go/runtime/trace/example_test.go
index 8e0ee5a1a3f..ba96a829a3d 100644
--- a/libgo/go/runtime/trace/example_test.go
+++ b/libgo/go/runtime/trace/example_test.go
@@ -2,8 +2,6 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build ignore
-
 package trace_test
 
 import (
diff --git a/libgo/go/text/scanner/example_test.go b/libgo/go/text/scanner/example_test.go
index 88b992b136e..5e8c3fbda4f 100644
--- a/libgo/go/text/scanner/example_test.go
+++ b/libgo/go/text/scanner/example_test.go
@@ -2,8 +2,6 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build ignore
-
 package scanner_test
 
 import (
diff --git a/libgo/testsuite/gotest b/libgo/testsuite/gotest
index 4f1a2f822e4..4293db92664 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 '}'


More information about the Gcc-cvs mailing list