MCPcopy
hub / github.com/urfave/cli / TestHandleExitCoder_ErrorFormatter

Function TestHandleExitCoder_ErrorFormatter

errors_test.go:108–138  ·  errors_test.go::TestHandleExitCoder_ErrorFormatter
(t *testing.T)

Source from the content-addressed store, hash-verified

106}
107
108func TestHandleExitCoder_ErrorFormatter(t *testing.T) {
109 exitCode := 0
110 called := false
111
112 OsExiter = func(rc int) {
113 if !called {
114 exitCode = rc
115 called = true
116 }
117 }
118
119 oldWriter := ErrWriter
120 var buf bytes.Buffer
121 ErrWriter = &buf
122 defer func() {
123 OsExiter = fakeOsExiter
124 ErrWriter = oldWriter
125 }()
126
127 exitErr := Exit("galactic perimeter breach", 9)
128 exitErr2 := Exit("last ExitCoder", 11)
129 exitErr3 := &exitFormatter{code: 12}
130
131 // add some recursion for multi error to fix test coverage
132 err := newMultiError(errors.New("wowsa"), errors.New("egad"), exitErr3, newMultiError(exitErr, exitErr2))
133 HandleExitCoder(err)
134
135 assert.Equal(t, 11, exitCode)
136 assert.True(t, called)
137 assert.Contains(t, buf.String(), "some other special")
138}
139
140func TestHandleExitCoder_MultiErrorWithoutExitCoder(t *testing.T) {
141 exitCode := 0

Callers

nothing calls this directly

Calls 4

ExitFunction · 0.85
newMultiErrorFunction · 0.85
HandleExitCoderFunction · 0.85
StringMethod · 0.45

Tested by

no test coverage detected