Skip to content

Commit

Permalink
fix: improve some tests for Go 1.21
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez committed Feb 17, 2024
1 parent da8c4ef commit c6a3ee4
Showing 1 changed file with 42 additions and 7 deletions.
49 changes: 42 additions & 7 deletions test/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ package test

import (
"path/filepath"
"runtime"
"strings"
"testing"

hcversion "github.com/hashicorp/go-version"
"github.com/stretchr/testify/require"
_ "github.com/valyala/quicktemplate"

Expand Down Expand Up @@ -131,14 +134,20 @@ func TestTestsAreLintedByDefault(t *testing.T) {
}

func TestCgoOk(t *testing.T) {
args := []string{"--timeout=3m",
"--enable-all",
"-D",
"nosnakecase", // try to analyze the generated Go.
}

// TODO(ldez) remove when we will run go1.23 on the CI.
if isGoVersion("1.21") {
args = append(args, "-D", "intrange,copyloopvar")
}

testshared.NewRunnerBuilder(t).
WithNoConfig().
WithArgs(
"--timeout=3m",
"--enable-all",
"-D",
"nosnakecase,gci",
).
WithArgs(args...).
WithTargetPath(testdataDir, "cgo").
Runner().
Install().
Expand Down Expand Up @@ -353,9 +362,16 @@ func TestLineDirectiveProcessedFiles(t *testing.T) {
}

func TestUnsafeOk(t *testing.T) {
args := []string{"--enable-all"}

// TODO(ldez) remove when we will run go1.23 on the CI.
if isGoVersion("1.21") {
args = append(args, "-D", "intrange,copyloopvar")
}

testshared.NewRunnerBuilder(t).
WithNoConfig().
WithArgs("--enable-all").
WithArgs(args...).
WithTargetPath(testdataDir, "unsafe").
Runner().
Install().
Expand Down Expand Up @@ -511,6 +527,11 @@ func TestEnableAllFastAndEnableCanCoexist(t *testing.T) {
t.Run(test.desc, func(t *testing.T) {
t.Parallel()

// TODO(ldez) remove when we will run go1.23 on the CI.
if isGoVersion("1.21") {
test.args = append(test.args, "-D", "intrange,copyloopvar")
}

testshared.NewRunnerBuilder(t).
WithNoConfig().
WithArgs(test.args...).
Expand Down Expand Up @@ -681,3 +702,17 @@ func TestPathPrefix(t *testing.T) {
})
}
}

func isGoVersion(tag string) bool {
vRuntime, err := hcversion.NewVersion(strings.TrimPrefix(runtime.Version(), "go"))
if err != nil {
return false
}

vTag, err := hcversion.NewVersion(strings.TrimPrefix(tag, "go"))
if err != nil {
return false
}

return vRuntime.GreaterThanOrEqual(vTag)
}

0 comments on commit c6a3ee4

Please sign in to comment.