Skip to content

Commit 6fcbb73

Browse files
committed
fix: improve some tests for Go 1.21
1 parent da8c4ef commit 6fcbb73

File tree

1 file changed

+37
-7
lines changed

1 file changed

+37
-7
lines changed

test/run_test.go

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@ package test
22

33
import (
44
"path/filepath"
5+
"runtime"
6+
"strings"
57
"testing"
68

9+
hcversion "github.com/hashicorp/go-version"
710
"github.com/stretchr/testify/require"
811
_ "github.com/valyala/quicktemplate"
912

@@ -131,14 +134,20 @@ func TestTestsAreLintedByDefault(t *testing.T) {
131134
}
132135

133136
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+
134148
testshared.NewRunnerBuilder(t).
135149
WithNoConfig().
136-
WithArgs(
137-
"--timeout=3m",
138-
"--enable-all",
139-
"-D",
140-
"nosnakecase,gci",
141-
).
150+
WithArgs(args...).
142151
WithTargetPath(testdataDir, "cgo").
143152
Runner().
144153
Install().
@@ -353,9 +362,16 @@ func TestLineDirectiveProcessedFiles(t *testing.T) {
353362
}
354363

355364
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+
356372
testshared.NewRunnerBuilder(t).
357373
WithNoConfig().
358-
WithArgs("--enable-all").
374+
WithArgs(args...).
359375
WithTargetPath(testdataDir, "unsafe").
360376
Runner().
361377
Install().
@@ -681,3 +697,17 @@ func TestPathPrefix(t *testing.T) {
681697
})
682698
}
683699
}
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

Comments
 (0)