@@ -17,12 +17,13 @@ import (
17
17
"github.com/golangci/golangci-lint/pkg/logutils"
18
18
)
19
19
20
- const binName = "../golangci-lint"
20
+ const defaultBinPath = "../golangci-lint"
21
21
22
22
type RunnerBuilder struct {
23
23
tb testing.TB
24
24
log logutils.Log
25
25
26
+ binPath string
26
27
command string
27
28
env []string
28
29
@@ -42,11 +43,18 @@ func NewRunnerBuilder(tb testing.TB) *RunnerBuilder {
42
43
return & RunnerBuilder {
43
44
tb : tb ,
44
45
log : log ,
46
+ binPath : defaultBinPath ,
45
47
command : "run" ,
46
48
allowParallelRunners : true ,
47
49
}
48
50
}
49
51
52
+ func (b * RunnerBuilder ) WithBinPath (binPath string ) * RunnerBuilder {
53
+ b .binPath = binPath
54
+
55
+ return b
56
+ }
57
+
50
58
func (b * RunnerBuilder ) WithCommand (command string ) * RunnerBuilder {
51
59
b .command = command
52
60
@@ -162,6 +170,7 @@ func (b *RunnerBuilder) Runner() *Runner {
162
170
}
163
171
164
172
return & Runner {
173
+ binPath : b .binPath ,
165
174
log : b .log ,
166
175
tb : b .tb ,
167
176
env : b .env ,
@@ -174,6 +183,7 @@ type Runner struct {
174
183
log logutils.Log
175
184
tb testing.TB
176
185
186
+ binPath string
177
187
env []string
178
188
command string
179
189
args []string
@@ -197,11 +207,10 @@ func (r *Runner) Run() *RunnerResult {
197
207
runArgs := append ([]string {r .command }, r .args ... )
198
208
199
209
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 ))
201
211
}(time .Now ())
202
212
203
- cmd := exec .Command (binName , runArgs ... )
204
- cmd .Env = append (os .Environ (), r .env ... )
213
+ cmd := r .Command ()
205
214
206
215
out , err := cmd .CombinedOutput ()
207
216
if err != nil {
@@ -239,11 +248,8 @@ func (r *Runner) Command() *exec.Cmd {
239
248
240
249
runArgs := append ([]string {r .command }, r .args ... )
241
250
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 ... )
247
253
cmd .Env = append (os .Environ (), r .env ... )
248
254
249
255
return cmd
@@ -311,19 +317,22 @@ func (r *RunnerResult) ExpectHasIssue(issueText string) *RunnerResult {
311
317
return r .ExpectExitCode (exitcodes .IssuesFound ).ExpectOutputContains (issueText )
312
318
}
313
319
314
- func InstallGolangciLint (tb testing.TB ) {
320
+ func InstallGolangciLint (tb testing.TB ) string {
315
321
tb .Helper ()
316
322
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" )
320
325
321
- cmd := exec .Command ("make" , "-C" , ".." , "build" )
326
+ output , err := cmd .CombinedOutput ()
327
+ if err != nil {
328
+ tb .Log (string (output ))
329
+ }
322
330
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" )
326
332
}
327
333
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
329
338
}
0 commit comments