2016-05-02 15:25:37 +00:00
|
|
|
package cli
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestHandleExitCoder_nil(t *testing.T) {
|
|
|
|
exitCode := 0
|
|
|
|
called := false
|
|
|
|
|
|
|
|
OsExiter = func(rc int) {
|
|
|
|
exitCode = rc
|
|
|
|
called = true
|
|
|
|
}
|
|
|
|
|
|
|
|
defer func() { OsExiter = os.Exit }()
|
|
|
|
|
|
|
|
HandleExitCoder(nil)
|
|
|
|
|
|
|
|
expect(t, exitCode, 0)
|
|
|
|
expect(t, called, false)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestHandleExitCoder_ExitCoder(t *testing.T) {
|
|
|
|
exitCode := 0
|
|
|
|
called := false
|
|
|
|
|
|
|
|
OsExiter = func(rc int) {
|
|
|
|
exitCode = rc
|
|
|
|
called = true
|
|
|
|
}
|
|
|
|
|
|
|
|
defer func() { OsExiter = os.Exit }()
|
|
|
|
|
2016-05-25 16:05:14 +00:00
|
|
|
HandleExitCoder(Exit("galactic perimeter breach", 9))
|
2016-05-02 15:25:37 +00:00
|
|
|
|
|
|
|
expect(t, exitCode, 9)
|
|
|
|
expect(t, called, true)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestHandleExitCoder_MultiErrorWithExitCoder(t *testing.T) {
|
|
|
|
exitCode := 0
|
|
|
|
called := false
|
|
|
|
|
|
|
|
OsExiter = func(rc int) {
|
|
|
|
exitCode = rc
|
|
|
|
called = true
|
|
|
|
}
|
|
|
|
|
|
|
|
defer func() { OsExiter = os.Exit }()
|
|
|
|
|
2016-05-25 16:05:14 +00:00
|
|
|
exitErr := Exit("galactic perimeter breach", 9)
|
|
|
|
err := newMultiError(errors.New("wowsa"), errors.New("egad"), exitErr)
|
2016-05-02 15:25:37 +00:00
|
|
|
HandleExitCoder(err)
|
|
|
|
|
|
|
|
expect(t, exitCode, 9)
|
|
|
|
expect(t, called, true)
|
|
|
|
}
|