Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev: improve and clean fix_test #2457

Merged
merged 1 commit into from
Jan 4, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion test/fix_test.go
Original file line number Diff line number Diff line change
@@ -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"
)

@@ -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)

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 (
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 (
8 changes: 0 additions & 8 deletions test/testdata/fix/out/unused.go

This file was deleted.