@@ -10,6 +10,8 @@ import (
1010 "runtime"
1111 "strconv"
1212 "strings"
13+ "sync"
14+ "syscall"
1315 "testing"
1416 "time"
1517
@@ -20,6 +22,15 @@ import (
2022 "github.com/stretchr/testify/assert"
2123)
2224
25+ var installOnce sync.Once
26+
27+ func installBinary (t assert.TestingT ) {
28+ installOnce .Do (func () {
29+ cmd := exec .Command ("go" , "install" , filepath .Join (".." , "cmd" , binName ))
30+ assert .NoError (t , cmd .Run (), "Can't go install %s" , binName )
31+ })
32+ }
33+
2334func runGoErrchk (c * exec.Cmd , t * testing.T ) {
2435 output , err := c .CombinedOutput ()
2536 assert .NoError (t , err , "Output:\n %s" , output )
@@ -51,9 +62,30 @@ func TestSourcesFromTestdataWithIssuesDir(t *testing.T) {
5162 }
5263}
5364
54- func installBinary (t assert.TestingT ) {
55- cmd := exec .Command ("go" , "install" , filepath .Join (".." , "cmd" , binName ))
56- assert .NoError (t , cmd .Run (), "Can't go install %s" , binName )
65+ func TestDeadlineExitCode (t * testing.T ) {
66+ installBinary (t )
67+
68+ exitCode := runGolangciLintGetExitCode (t , "--no-config" , "--deadline=1ms" )
69+ assert .Equal (t , 4 , exitCode )
70+ }
71+
72+ func runGolangciLintGetExitCode (t * testing.T , args ... string ) int {
73+ runArgs := append ([]string {"run" }, args ... )
74+ cmd := exec .Command ("golangci-lint" , runArgs ... )
75+ err := cmd .Run ()
76+ if err != nil {
77+ if exitError , ok := err .(* exec.ExitError ); ok {
78+ ws := exitError .Sys ().(syscall.WaitStatus )
79+ return ws .ExitStatus ()
80+ }
81+
82+ t .Fatalf ("can't get error code from %s" , err )
83+ return - 1
84+ }
85+
86+ // success, exitCode should be 0 if go is ok
87+ ws := cmd .ProcessState .Sys ().(syscall.WaitStatus )
88+ return ws .ExitStatus ()
5789}
5890
5991func testOneSource (t * testing.T , sourcePath string ) {
0 commit comments