Merge pull request #44 from golangci/support/exit-code-4-if-deadline
#41: exit with code 4 if timeouted
This commit is contained in:
commit
3b5ee0ce5b
@ -31,7 +31,10 @@ import (
|
|||||||
"golang.org/x/tools/go/loader"
|
"golang.org/x/tools/go/loader"
|
||||||
)
|
)
|
||||||
|
|
||||||
const exitCodeIfFailure = 3
|
const (
|
||||||
|
exitCodeIfFailure = 3
|
||||||
|
exitCodeIfTimeout = 4
|
||||||
|
)
|
||||||
|
|
||||||
func (e *Executor) initRun() {
|
func (e *Executor) initRun() {
|
||||||
var runCmd = &cobra.Command{
|
var runCmd = &cobra.Command{
|
||||||
@ -388,6 +391,10 @@ func (e *Executor) executeRun(cmd *cobra.Command, args []string) {
|
|||||||
e.exitCode = exitCodeIfFailure
|
e.exitCode = exitCodeIfFailure
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if e.exitCode == 0 && ctx.Err() != nil {
|
||||||
|
e.exitCode = exitCodeIfTimeout
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Executor) parseConfig(cmd *cobra.Command) {
|
func (e *Executor) parseConfig(cmd *cobra.Command) {
|
||||||
|
@ -10,6 +10,8 @@ import (
|
|||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
|
"syscall"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -20,6 +22,15 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var installOnce sync.Once
|
||||||
|
|
||||||
|
func installBinary(t assert.TestingT) {
|
||||||
|
installOnce.Do(func() {
|
||||||
|
cmd := exec.Command("go", "install", filepath.Join("..", "cmd", binName))
|
||||||
|
assert.NoError(t, cmd.Run(), "Can't go install %s", binName)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func runGoErrchk(c *exec.Cmd, t *testing.T) {
|
func runGoErrchk(c *exec.Cmd, t *testing.T) {
|
||||||
output, err := c.CombinedOutput()
|
output, err := c.CombinedOutput()
|
||||||
assert.NoError(t, err, "Output:\n%s", output)
|
assert.NoError(t, err, "Output:\n%s", output)
|
||||||
@ -51,9 +62,30 @@ func TestSourcesFromTestdataWithIssuesDir(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func installBinary(t assert.TestingT) {
|
func TestDeadlineExitCode(t *testing.T) {
|
||||||
cmd := exec.Command("go", "install", filepath.Join("..", "cmd", binName))
|
installBinary(t)
|
||||||
assert.NoError(t, cmd.Run(), "Can't go install %s", binName)
|
|
||||||
|
exitCode := runGolangciLintGetExitCode(t, "--no-config", "--deadline=1ms")
|
||||||
|
assert.Equal(t, 4, exitCode)
|
||||||
|
}
|
||||||
|
|
||||||
|
func runGolangciLintGetExitCode(t *testing.T, args ...string) int {
|
||||||
|
runArgs := append([]string{"run"}, args...)
|
||||||
|
cmd := exec.Command("golangci-lint", runArgs...)
|
||||||
|
err := cmd.Run()
|
||||||
|
if err != nil {
|
||||||
|
if exitError, ok := err.(*exec.ExitError); ok {
|
||||||
|
ws := exitError.Sys().(syscall.WaitStatus)
|
||||||
|
return ws.ExitStatus()
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Fatalf("can't get error code from %s", err)
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
|
||||||
|
// success, exitCode should be 0 if go is ok
|
||||||
|
ws := cmd.ProcessState.Sys().(syscall.WaitStatus)
|
||||||
|
return ws.ExitStatus()
|
||||||
}
|
}
|
||||||
|
|
||||||
func testOneSource(t *testing.T, sourcePath string) {
|
func testOneSource(t *testing.T, sourcePath string) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user