@@ -17,12 +17,13 @@ import (
1717 "github.com/golangci/golangci-lint/pkg/logutils"
1818)
1919
20- const binName = "../golangci-lint"
20+ const defaultBinPath = "../golangci-lint"
2121
2222type RunnerBuilder struct {
2323 tb testing.TB
2424 log logutils.Log
2525
26+ binPath string
2627 command string
2728 env []string
2829
@@ -42,11 +43,18 @@ func NewRunnerBuilder(tb testing.TB) *RunnerBuilder {
4243 return & RunnerBuilder {
4344 tb : tb ,
4445 log : log ,
46+ binPath : defaultBinPath ,
4547 command : "run" ,
4648 allowParallelRunners : true ,
4749 }
4850}
4951
52+ func (b * RunnerBuilder ) WithBinPath (binPath string ) * RunnerBuilder {
53+ b .binPath = binPath
54+
55+ return b
56+ }
57+
5058func (b * RunnerBuilder ) WithCommand (command string ) * RunnerBuilder {
5159 b .command = command
5260
@@ -162,6 +170,7 @@ func (b *RunnerBuilder) Runner() *Runner {
162170 }
163171
164172 return & Runner {
173+ binPath : b .binPath ,
165174 log : b .log ,
166175 tb : b .tb ,
167176 env : b .env ,
@@ -174,6 +183,7 @@ type Runner struct {
174183 log logutils.Log
175184 tb testing.TB
176185
186+ binPath string
177187 env []string
178188 command string
179189 args []string
@@ -197,11 +207,10 @@ func (r *Runner) Run() *RunnerResult {
197207 runArgs := append ([]string {r .command }, r .args ... )
198208
199209 defer func (startedAt time.Time ) {
200- r .log .Infof ("ran [%s %s] in %s" , binName , strings .Join (runArgs , " " ), time .Since (startedAt ))
210+ r .log .Infof ("ran [%s %s] in %s" , r . binPath , strings .Join (runArgs , " " ), time .Since (startedAt ))
201211 }(time .Now ())
202212
203- cmd := exec .Command (binName , runArgs ... )
204- cmd .Env = append (os .Environ (), r .env ... )
213+ cmd := r .Command ()
205214
206215 out , err := cmd .CombinedOutput ()
207216 if err != nil {
@@ -239,11 +248,8 @@ func (r *Runner) Command() *exec.Cmd {
239248
240249 runArgs := append ([]string {r .command }, r .args ... )
241250
242- defer func (startedAt time.Time ) {
243- r .log .Infof ("ran [../golangci-lint %s] in %s" , strings .Join (runArgs , " " ), time .Since (startedAt ))
244- }(time .Now ())
245-
246- cmd := exec .Command ("../golangci-lint" , runArgs ... )
251+ //nolint:gosec
252+ cmd := exec .Command (r .binPath , runArgs ... )
247253 cmd .Env = append (os .Environ (), r .env ... )
248254
249255 return cmd
@@ -311,19 +317,22 @@ func (r *RunnerResult) ExpectHasIssue(issueText string) *RunnerResult {
311317 return r .ExpectExitCode (exitcodes .IssuesFound ).ExpectOutputContains (issueText )
312318}
313319
314- func InstallGolangciLint (tb testing.TB ) {
320+ func InstallGolangciLint (tb testing.TB ) string {
315321 tb .Helper ()
316322
317- if os .Getenv ("GOLANGCI_LINT_INSTALLED" ) == "true" {
318- return
319- }
323+ if os .Getenv ("GOLANGCI_LINT_INSTALLED" ) != "true" {
324+ cmd := exec .Command ("make" , "-C" , ".." , "build" )
320325
321- cmd := exec .Command ("make" , "-C" , ".." , "build" )
326+ output , err := cmd .CombinedOutput ()
327+ if err != nil {
328+ tb .Log (string (output ))
329+ }
322330
323- output , err := cmd .CombinedOutput ()
324- if err != nil {
325- tb .Log (string (output ))
331+ require .NoError (tb , err , "Can't go install golangci-lint" )
326332 }
327333
328- require .NoError (tb , err , "Can't go install golangci-lint" )
334+ abs , err := filepath .Abs (defaultBinPath )
335+ require .NoError (tb , err )
336+
337+ return abs
329338}
0 commit comments