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-03 10:54:05 +00:00
|
|
|
HandleExitCoder(NewExitError("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-03 10:54:05 +00:00
|
|
|
exitErr := NewExitError("galactic perimeter breach", 9)
|
2016-05-02 15:25:37 +00:00
|
|
|
err := NewMultiError(errors.New("wowsa"), errors.New("egad"), exitErr)
|
|
|
|
HandleExitCoder(err)
|
|
|
|
|
|
|
|
expect(t, exitCode, 9)
|
|
|
|
expect(t, called, true)
|
|
|
|
}
|