@@ -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 ().
@@ -681,3 +697,17 @@ func TestPathPrefix(t *testing.T) {
681
697
})
682
698
}
683
699
}
700
+
701
+ func isGoVersion (tag string ) bool {
702
+ vRuntime , err := hcversion .NewVersion (strings .TrimPrefix (runtime .Version (), "go" ))
703
+ if err != nil {
704
+ return false
705
+ }
706
+
707
+ vTag , err := hcversion .NewVersion (strings .TrimPrefix (tag , "go" ))
708
+ if err != nil {
709
+ return false
710
+ }
711
+
712
+ return vRuntime .GreaterThanOrEqual (vTag )
713
+ }
0 commit comments