aboutsummaryrefslogtreecommitdiff
path: root/libgo/go/testing
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2021-04-12 14:15:16 -0700
committerIan Lance Taylor <iant@golang.org>2021-04-12 15:23:16 -0700
commiteb49f7de9341cb464327234c3a673ce3ef642e01 (patch)
tree44682a0f81f3aeef685487c61e375abe6a0904d5 /libgo/go/testing
parent84081e2c6bd43a6790f751755865cf4227adac7c (diff)
downloadgcc-eb49f7de9341cb464327234c3a673ce3ef642e01.zip
gcc-eb49f7de9341cb464327234c3a673ce3ef642e01.tar.gz
gcc-eb49f7de9341cb464327234c3a673ce3ef642e01.tar.bz2
libgo: update to Go1.16.3 release
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/309490
Diffstat (limited to 'libgo/go/testing')
-rw-r--r--libgo/go/testing/helper_test.go32
-rw-r--r--libgo/go/testing/testing.go15
2 files changed, 39 insertions, 8 deletions
diff --git a/libgo/go/testing/helper_test.go b/libgo/go/testing/helper_test.go
index 8858196..b27fd62 100644
--- a/libgo/go/testing/helper_test.go
+++ b/libgo/go/testing/helper_test.go
@@ -71,6 +71,38 @@ func TestTBHelperParallel(t *T) {
}
}
+func TestTBHelperLineNumer(t *T) {
+ var buf bytes.Buffer
+ ctx := newTestContext(1, newMatcher(regexp.MatchString, "", ""))
+ t1 := &T{
+ common: common{
+ signal: make(chan bool),
+ w: &buf,
+ },
+ context: ctx,
+ }
+ t1.Run("Test", func(t *T) {
+ helperA := func(t *T) {
+ t.Helper()
+ t.Run("subtest", func(t *T) {
+ t.Helper()
+ t.Fatal("fatal error message")
+ })
+ }
+ helperA(t)
+ })
+
+ want := "helper_test.go:92: fatal error message"
+ got := ""
+ lines := strings.Split(strings.TrimSpace(buf.String()), "\n")
+ if len(lines) > 0 {
+ got = strings.TrimSpace(lines[len(lines)-1])
+ }
+ if got != want {
+ t.Errorf("got output:\n\n%v\nwant:\n\n%v", got, want)
+ }
+}
+
type noopWriter int
func (nw *noopWriter) Write(b []byte) (int, error) { return len(b), nil }
diff --git a/libgo/go/testing/testing.go b/libgo/go/testing/testing.go
index 795ee32..143d81c 100644
--- a/libgo/go/testing/testing.go
+++ b/libgo/go/testing/testing.go
@@ -509,6 +509,13 @@ func (c *common) frameSkip(skip int) runtime.Frame {
}
return prevFrame
}
+ // If more helper PCs have been added since we last did the conversion
+ if c.helperNames == nil {
+ c.helperNames = make(map[string]struct{})
+ for pc := range c.helperPCs {
+ c.helperNames[pcToName(pc)] = struct{}{}
+ }
+ }
if _, ok := c.helperNames[frame.Function]; !ok {
// Found a frame that wasn't inside a helper function.
return frame
@@ -521,14 +528,6 @@ func (c *common) frameSkip(skip int) runtime.Frame {
// and inserts the final newline if needed and indentation spaces for formatting.
// This function must be called with c.mu held.
func (c *common) decorate(s string, skip int) string {
- // If more helper PCs have been added since we last did the conversion
- if c.helperNames == nil {
- c.helperNames = make(map[string]struct{})
- for pc := range c.helperPCs {
- c.helperNames[pcToName(pc)] = struct{}{}
- }
- }
-
frame := c.frameSkip(skip)
file := frame.File
line := frame.Line