@@ -2,8 +2,11 @@ package test
2
2
3
3
import (
4
4
"path/filepath"
5
+ "runtime"
6
+ "strings"
5
7
"testing"
6
8
9
+ hcversion "github.com/hashicorp/go-version"
7
10
"github.com/stretchr/testify/require"
8
11
_ "github.com/valyala/quicktemplate"
9
12
@@ -131,14 +134,20 @@ func TestTestsAreLintedByDefault(t *testing.T) {
131
134
}
132
135
133
136
func TestCgoOk (t * testing.T ) {
137
+ args := []string {"--timeout=3m" ,
138
+ "--enable-all" ,
139
+ "-D" ,
140
+ "nosnakecase" , // try to analyze the generated Go.
141
+ }
142
+
143
+ // TODO(ldez) remove when we will run go1.23 on the CI.
144
+ if isGoVersion ("1.21" ) {
145
+ args = append (args , "-D" , "intrange,copyloopvar" )
146
+ }
147
+
134
148
testshared .NewRunnerBuilder (t ).
135
149
WithNoConfig ().
136
- WithArgs (
137
- "--timeout=3m" ,
138
- "--enable-all" ,
139
- "-D" ,
140
- "nosnakecase,gci" ,
141
- ).
150
+ WithArgs (args ... ).
142
151
WithTargetPath (testdataDir , "cgo" ).
143
152
Runner ().
144
153
Install ().
@@ -353,9 +362,16 @@ func TestLineDirectiveProcessedFiles(t *testing.T) {
353
362
}
354
363
355
364
func TestUnsafeOk (t * testing.T ) {
365
+ args := []string {"--enable-all" }
366
+
367
+ // TODO(ldez) remove when we will run go1.23 on the CI.
368
+ if isGoVersion ("1.21" ) {
369
+ args = append (args , "-D" , "intrange,copyloopvar" )
370
+ }
371
+
356
372
testshared .NewRunnerBuilder (t ).
357
373
WithNoConfig ().
358
- WithArgs ("--enable-all" ).
374
+ WithArgs (args ... ).
359
375
WithTargetPath (testdataDir , "unsafe" ).
360
376
Runner ().
361
377
Install ().
@@ -511,6 +527,11 @@ func TestEnableAllFastAndEnableCanCoexist(t *testing.T) {
511
527
t .Run (test .desc , func (t * testing.T ) {
512
528
t .Parallel ()
513
529
530
+ // TODO(ldez) remove when we will run go1.23 on the CI.
531
+ if isGoVersion ("1.21" ) {
532
+ test .args = append (test .args , "-D" , "intrange,copyloopvar" )
533
+ }
534
+
514
535
testshared .NewRunnerBuilder (t ).
515
536
WithNoConfig ().
516
537
WithArgs (test .args ... ).
@@ -681,3 +702,17 @@ func TestPathPrefix(t *testing.T) {
681
702
})
682
703
}
683
704
}
705
+
706
+ func isGoVersion (tag string ) bool {
707
+ vRuntime , err := hcversion .NewVersion (strings .TrimPrefix (runtime .Version (), "go" ))
708
+ if err != nil {
709
+ return false
710
+ }
711
+
712
+ vTag , err := hcversion .NewVersion (strings .TrimPrefix (tag , "go" ))
713
+ if err != nil {
714
+ return false
715
+ }
716
+
717
+ return vRuntime .GreaterThanOrEqual (vTag )
718
+ }
0 commit comments