MCPcopy
hub / github.com/uber-go/goleak / TestVerifyTestMain

Function TestVerifyTestMain

testmain_test.go:61–87  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

59}
60
61func 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}

Callers

nothing calls this directly

Calls 7

clearOSStubsFunction · 0.85
osStubsFunction · 0.85
startBlockedGFunction · 0.85
VerifyTestMainFunction · 0.85
dummyTestMainTypeAlias · 0.85
CleanupFunction · 0.85
unblockMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…