mirror of
https://github.com/golang/go.git
synced 2025-05-16 21:04:38 +00:00
[release-branch.go1.16] testing: update helperNames just before checking it
parent's helperNames has not been set when frameSkip called, moving helperNames initilazing to frameSkip. For #44887 Fixes #44888 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> (cherry picked from commit 67048432026062a98a3937a865aeb05a398148c5) Reviewed-on: https://go-review.googlesource.com/c/go/+/303189 Trust: Ian Lance Taylor <iant@golang.org> Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
This commit is contained in:
parent
f39c4deee8
commit
902d16e97b
@ -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
|
type noopWriter int
|
||||||
|
|
||||||
func (nw *noopWriter) Write(b []byte) (int, error) { return len(b), nil }
|
func (nw *noopWriter) Write(b []byte) (int, error) { return len(b), nil }
|
||||||
|
@ -509,6 +509,13 @@ func (c *common) frameSkip(skip int) runtime.Frame {
|
|||||||
}
|
}
|
||||||
return prevFrame
|
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 {
|
if _, ok := c.helperNames[frame.Function]; !ok {
|
||||||
// Found a frame that wasn't inside a helper function.
|
// Found a frame that wasn't inside a helper function.
|
||||||
return frame
|
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.
|
// and inserts the final newline if needed and indentation spaces for formatting.
|
||||||
// This function must be called with c.mu held.
|
// This function must be called with c.mu held.
|
||||||
func (c *common) decorate(s string, skip int) string {
|
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)
|
frame := c.frameSkip(skip)
|
||||||
file := frame.File
|
file := frame.File
|
||||||
line := frame.Line
|
line := frame.Line
|
||||||
|
Loading…
x
Reference in New Issue
Block a user