Skip to content

Commit

Permalink
dev: improve and clean fix_test (golangci#2457)
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez authored and SeigeC committed Apr 4, 2023
1 parent 5d4c9c6 commit c73de9c
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 23 deletions.
15 changes: 14 additions & 1 deletion test/fix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/stretchr/testify/require"
"gopkg.in/yaml.v3"

"github.com/golangci/golangci-lint/pkg/exitcodes"
"github.com/golangci/golangci-lint/test/testshared"
)

Expand Down Expand Up @@ -52,7 +53,19 @@ func TestFix(t *testing.T) {
cfg, err := yaml.Marshal(rc.config)
require.NoError(t, err)

testshared.NewLintRunner(t).RunWithYamlConfig(string(cfg), args...)
var runResult *testshared.RunResult
if rc.configPath != "" {
args = append(args, "-c", rc.configPath)
runResult = testshared.NewLintRunner(t).RunCommand("run", args...)
} else {
runResult = testshared.NewLintRunner(t).RunWithYamlConfig(string(cfg), args...)
}

// nolintlint test uses non existing linters (bob, alice)
if rc.expectedLinter != "nolintlint" {
runResult.ExpectExitCode(exitcodes.Success)
}

output, err := os.ReadFile(input)
require.NoError(t, err)

Expand Down
8 changes: 8 additions & 0 deletions test/testdata/configs/gocritic-fix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
linters-settings:
gocritic:
enabled-checks:
- ruleguard
settings:
ruleguard:
rules: 'ruleguard/rangeExprCopy.go,ruleguard/strings_simplify.go'

5 changes: 2 additions & 3 deletions test/testdata/fix/in/gocritic.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//args: -Egocritic
//config: linters-settings.gocritic.enabled-checks=ruleguard
//config: linters-settings.gocritic.settings.ruleguard.rules=ruleguard/rangeExprCopy.go,ruleguard/strings_simplify.go
// args: -Egocritic
// config_path: testdata/configs/gocritic-fix.yml
package p

import (
Expand Down
8 changes: 0 additions & 8 deletions test/testdata/fix/in/unused.go

This file was deleted.

5 changes: 2 additions & 3 deletions test/testdata/fix/out/gocritic.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//args: -Egocritic
//config: linters-settings.gocritic.enabled-checks=ruleguard
//config: linters-settings.gocritic.settings.ruleguard.rules=ruleguard/rangeExprCopy.go,ruleguard/strings_simplify.go
// args: -Egocritic
// config_path: testdata/configs/gocritic-fix.yml
package p

import (
Expand Down
8 changes: 0 additions & 8 deletions test/testdata/fix/out/unused.go

This file was deleted.

0 comments on commit c73de9c

Please sign in to comment.