Merge branch 'master' into toml-support

This commit is contained in:
kandayasu 2016-07-25 02:47:48 +09:00 committed by GitHub
commit dd7cc7a6d2
6 changed files with 77 additions and 13 deletions

View File

@ -7,23 +7,23 @@ cache:
- node_modules
go:
- 1.2.2
- 1.3.3
- 1.4
- 1.5.4
- 1.6.2
- 1.2.x
- 1.3.x
- 1.4.2
- 1.5.x
- 1.6.x
- master
matrix:
allow_failures:
- go: master
include:
- go: 1.6.2
- go: 1.6.x
os: osx
before_script:
- go get github.com/urfave/gfmrun/...
- go get golang.org/x/tools/cmd/goimports
- go get golang.org/x/tools/... || true
- if [ ! -f node_modules/.bin/markdown-toc ] ; then
npm install markdown-toc ;
fi

View File

@ -13,6 +13,19 @@ import (
"testing"
)
var (
lastExitCode = 0
fakeOsExiter = func(rc int) {
lastExitCode = rc
}
fakeErrWriter = &bytes.Buffer{}
)
func init() {
OsExiter = fakeOsExiter
ErrWriter = fakeErrWriter
}
type opCounts struct {
Total, BashComplete, OnUsageError, Before, CommandNotFound, Action, After, SubCommand int
}

View File

@ -10,7 +10,6 @@ environment:
PYTHON: C:\Python27-x64
PYTHON_VERSION: 2.7.x
PYTHON_ARCH: 64
GFMXR_DEBUG: 1
install:
- set PATH=%GOPATH%\bin;C:\go\bin;%PATH%

View File

@ -88,5 +88,11 @@ func HandleExitCoder(err error) {
for _, merr := range multiErr.Errors {
HandleExitCoder(merr)
}
return
}
if err.Error() != "" {
fmt.Fprintln(ErrWriter, err)
OsExiter(1)
}
}

View File

@ -1,8 +1,8 @@
package cli
import (
"bytes"
"errors"
"os"
"testing"
)
@ -15,7 +15,7 @@ func TestHandleExitCoder_nil(t *testing.T) {
called = true
}
defer func() { OsExiter = os.Exit }()
defer func() { OsExiter = fakeOsExiter }()
HandleExitCoder(nil)
@ -32,7 +32,7 @@ func TestHandleExitCoder_ExitCoder(t *testing.T) {
called = true
}
defer func() { OsExiter = os.Exit }()
defer func() { OsExiter = fakeOsExiter }()
HandleExitCoder(NewExitError("galactic perimeter breach", 9))
@ -49,7 +49,7 @@ func TestHandleExitCoder_MultiErrorWithExitCoder(t *testing.T) {
called = true
}
defer func() { OsExiter = os.Exit }()
defer func() { OsExiter = fakeOsExiter }()
exitErr := NewExitError("galactic perimeter breach", 9)
err := NewMultiError(errors.New("wowsa"), errors.New("egad"), exitErr)
@ -58,3 +58,49 @@ func TestHandleExitCoder_MultiErrorWithExitCoder(t *testing.T) {
expect(t, exitCode, 9)
expect(t, called, true)
}
func TestHandleExitCoder_ErrorWithMessage(t *testing.T) {
exitCode := 0
called := false
OsExiter = func(rc int) {
exitCode = rc
called = true
}
ErrWriter = &bytes.Buffer{}
defer func() {
OsExiter = fakeOsExiter
ErrWriter = fakeErrWriter
}()
err := errors.New("gourd havens")
HandleExitCoder(err)
expect(t, exitCode, 1)
expect(t, called, true)
expect(t, ErrWriter.(*bytes.Buffer).String(), "gourd havens\n")
}
func TestHandleExitCoder_ErrorWithoutMessage(t *testing.T) {
exitCode := 0
called := false
OsExiter = func(rc int) {
exitCode = rc
called = true
}
ErrWriter = &bytes.Buffer{}
defer func() {
OsExiter = fakeOsExiter
ErrWriter = fakeErrWriter
}()
err := errors.New("")
HandleExitCoder(err)
expect(t, exitCode, 0)
expect(t, called, false)
expect(t, ErrWriter.(*bytes.Buffer).String(), "")
}

View File

@ -71,7 +71,7 @@ def _toc():
def _gen():
go_version = check_output('go version'.split()).split()[2]
if go_version < 'go1.4':
if go_version < 'go1.5':
print('runtests: skip on {}'.format(go_version), file=sys.stderr)
return