Skip to content

Commit c605950

Browse files
committed
fix: ensure the appropriate error message is produced when the RunOnFailure() option is used.
adjust RunOnFailure() doc. follow up to uber-go#129
1 parent 79b1d32 commit c605950

File tree

4 files changed

+10
-8
lines changed

4 files changed

+10
-8
lines changed

leaks.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,6 @@ func Find(options ...Option) error {
5959
if opts.cleanup != nil {
6060
return errors.New("Cleanup can only be passed to VerifyNone or VerifyTestMain")
6161
}
62-
if opts.runOnFailure {
63-
return errors.New("RunOnFailure can only be passed to VerifyTestMain")
64-
}
6562
var stacks []stack.Stack
6663
retry := true
6764
for i := 0; retry; i++ {

options.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,9 @@ func IgnoreCurrent() Option {
109109
})
110110
}
111111

112-
// RunOnFailure makes goleak look for leaking goroutines upon test failures.
113-
// By default goleak only looks for leaking goroutines when tests succeed.
112+
// RunOnFailure makes [VerifyTestMain] look for leaking goroutines upon test failures as well.
113+
// By default [VerifyTestMain] only looks for leaking goroutines when tests succeed.
114+
// This has no effect on [VerifyNone], which always checks for leaking goroutines.
114115
func RunOnFailure() Option {
115116
return optionFunc(func(opts *opts) {
116117
opts.runOnFailure = true

testmain.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func VerifyTestMain(m TestingM, options ...Option) {
6565
errorMsg string
6666
)
6767

68-
if !opts.runOnFailure && exitCode == 0 {
68+
if exitCode == 0 {
6969
errorMsg = "goleak: Errors on successful test run:%v\n"
7070
run = true
7171
} else if opts.runOnFailure {

testmain_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,15 @@ func TestVerifyTestMain(t *testing.T) {
6969

7070
VerifyTestMain(dummyTestMain(7), RunOnFailure())
7171
assert.Equal(t, 7, <-exitCode, "Exit code should not be modified")
72-
assert.Contains(t, <-stderr, "goleak: Errors", "Find leaks on unsuccessful runs with RunOnFailure specified")
72+
assert.Contains(t, <-stderr, "goleak: Errors on unsuccessful test run", "Find leaks on unsuccessful runs with RunOnFailure specified")
7373

7474
VerifyTestMain(dummyTestMain(0))
7575
assert.Equal(t, 1, <-exitCode, "Expect error due to leaks on successful runs")
76-
assert.Contains(t, <-stderr, "goleak: Errors", "Find leaks on successful runs")
76+
assert.Contains(t, <-stderr, "goleak: Errors on successful test run", "Find leaks on successful runs")
77+
78+
VerifyTestMain(dummyTestMain(0), RunOnFailure())
79+
assert.Equal(t, 1, <-exitCode, "Expect error due to leaks on successful runs")
80+
assert.Contains(t, <-stderr, "goleak: Errors on successful test run", "Find leaks on successful runs")
7781

7882
blocked.unblock()
7983
VerifyTestMain(dummyTestMain(0))

0 commit comments

Comments
 (0)