mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
testing: fix SkipNow and FailNow to avoid panic(nil) check
Sorry, too many windows in which to run all.bash. Fixes build. TBR=r CC=golang-codereviews https://golang.org/cl/55790043
This commit is contained in:
parent
52125738f3
commit
91fbf6f159
1 changed files with 10 additions and 8 deletions
|
|
@ -143,10 +143,11 @@ var (
|
||||||
// common holds the elements common between T and B and
|
// common holds the elements common between T and B and
|
||||||
// captures common methods such as Errorf.
|
// captures common methods such as Errorf.
|
||||||
type common struct {
|
type common struct {
|
||||||
mu sync.RWMutex // guards output and failed
|
mu sync.RWMutex // guards output and failed
|
||||||
output []byte // Output generated by test or benchmark.
|
output []byte // Output generated by test or benchmark.
|
||||||
failed bool // Test or benchmark has failed.
|
failed bool // Test or benchmark has failed.
|
||||||
skipped bool // Test of benchmark has been skipped.
|
skipped bool // Test of benchmark has been skipped.
|
||||||
|
finished bool
|
||||||
|
|
||||||
start time.Time // Time test or benchmark started
|
start time.Time // Time test or benchmark started
|
||||||
duration time.Duration
|
duration time.Duration
|
||||||
|
|
@ -275,6 +276,7 @@ func (c *common) FailNow() {
|
||||||
// it would run on a test failure. Because we send on c.signal during
|
// it would run on a test failure. Because we send on c.signal during
|
||||||
// a top-of-stack deferred function now, we know that the send
|
// a top-of-stack deferred function now, we know that the send
|
||||||
// only happens after any other stacked defers have completed.
|
// only happens after any other stacked defers have completed.
|
||||||
|
c.finished = true
|
||||||
runtime.Goexit()
|
runtime.Goexit()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -338,6 +340,7 @@ func (c *common) Skipf(format string, args ...interface{}) {
|
||||||
// those other goroutines.
|
// those other goroutines.
|
||||||
func (c *common) SkipNow() {
|
func (c *common) SkipNow() {
|
||||||
c.skip()
|
c.skip()
|
||||||
|
c.finished = true
|
||||||
runtime.Goexit()
|
runtime.Goexit()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -376,13 +379,12 @@ func tRunner(t *T, test *InternalTest) {
|
||||||
// returned normally or because a test failure triggered
|
// returned normally or because a test failure triggered
|
||||||
// a call to runtime.Goexit, record the duration and send
|
// a call to runtime.Goexit, record the duration and send
|
||||||
// a signal saying that the test is done.
|
// a signal saying that the test is done.
|
||||||
var finished bool
|
|
||||||
defer func() {
|
defer func() {
|
||||||
t.duration = time.Now().Sub(t.start)
|
t.duration = time.Now().Sub(t.start)
|
||||||
// If the test panicked, print any test output before dying.
|
// If the test panicked, print any test output before dying.
|
||||||
err := recover()
|
err := recover()
|
||||||
if !finished && err == nil {
|
if !t.finished && err == nil {
|
||||||
err = fmt.Errorf("test executed panic(nil)")
|
err = fmt.Errorf("test executed panic(nil) or runtime.Goexit")
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fail()
|
t.Fail()
|
||||||
|
|
@ -394,7 +396,7 @@ func tRunner(t *T, test *InternalTest) {
|
||||||
|
|
||||||
t.start = time.Now()
|
t.start = time.Now()
|
||||||
test.F(t)
|
test.F(t)
|
||||||
finished = true
|
t.finished = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// An internal function but exported because it is cross-package; part of the implementation
|
// An internal function but exported because it is cross-package; part of the implementation
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue