(t *testing.T)
| 59 | } |
| 60 | |
| 61 | func TestVerifyTestMain(t *testing.T) { |
| 62 | defer clearOSStubs() |
| 63 | exitCode, stderr := osStubs() |
| 64 | |
| 65 | blocked := startBlockedG() |
| 66 | VerifyTestMain(dummyTestMain(7)) |
| 67 | assert.Equal(t, 7, <-exitCode, "Exit code should not be modified") |
| 68 | assert.NotContains(t, <-stderr, "goleak: Errors", "Ignore leaks on unsuccessful runs") |
| 69 | |
| 70 | VerifyTestMain(dummyTestMain(0)) |
| 71 | assert.Equal(t, 1, <-exitCode, "Expect error due to leaks on successful runs") |
| 72 | assert.Contains(t, <-stderr, "goleak: Errors", "Find leaks on successful runs") |
| 73 | |
| 74 | blocked.unblock() |
| 75 | VerifyTestMain(dummyTestMain(0)) |
| 76 | assert.Equal(t, 0, <-exitCode, "Expect no errors without leaks") |
| 77 | assert.NotContains(t, <-stderr, "goleak: Errors", "No errors on successful run without leaks") |
| 78 | |
| 79 | cleanupCalled := false |
| 80 | cleanupExitcode := 0 |
| 81 | VerifyTestMain(dummyTestMain(3), Cleanup(func(ec int) { |
| 82 | cleanupCalled = true |
| 83 | cleanupExitcode = ec |
| 84 | })) |
| 85 | assert.True(t, cleanupCalled) |
| 86 | assert.Equal(t, 3, cleanupExitcode) |
| 87 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…