diff options
author | Tao Qingyun <qingyunha@gmail.com> | 2021-03-18 00:10:38 +0000 |
---|---|---|
committer | Ian Lance Taylor <iant@golang.org> | 2021-03-19 01:04:37 +0000 |
commit | 67048432026062a98a3937a865aeb05a398148c5 (patch) | |
tree | 9cc01e17553038545f4cf64ffc4036666b827fd3 /src/testing/helper_test.go | |
parent | dcc96e4b9403a3a1e135b81d5f556a72a04a2add (diff) | |
download | go-git-67048432026062a98a3937a865aeb05a398148c5.tar.gz |
testing: update helperNames just before checking it
parent's helperNames has not been set when frameSkip called, moving
helperNames initilazing to frameSkip.
Fixes #44887
Change-Id: I5107c5951033e5e47d1ac441eac3ba5344a7bdc0
GitHub-Last-Rev: 44b90b2e2eeca8e2bb4a2084ec6fdd279c88f76d
GitHub-Pull-Request: golang/go#45071
Reviewed-on: https://go-review.googlesource.com/c/go/+/302469
Trust: Cherry Zhang <cherryyz@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Diffstat (limited to 'src/testing/helper_test.go')
-rw-r--r-- | src/testing/helper_test.go | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/testing/helper_test.go b/src/testing/helper_test.go index 8858196cf0..b27fd62ee8 100644 --- a/src/testing/helper_test.go +++ b/src/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 } |