Skip to content

Commit 2b4c9ab

Browse files
authored
dev: follow standards by using 'want' instead of 'ERROR' for tests (#3104)
1 parent 57a7e0d commit 2b4c9ab

File tree

181 files changed

+1273
-1244
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

181 files changed

+1273
-1244
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ test_race: build_race
4040
.PHONY: test_race
4141

4242
test_linters:
43-
GL_TEST_RUN=1 go test -v ./test -count 1 -run TestSourcesFromTestdataWithIssuesDir/$T
43+
GL_TEST_RUN=1 go test -v ./test -count 1 -run TestSourcesFromTestdata/$T
4444
.PHONY: test_linters
4545

4646
# Maintenance

test/data.go

-18
This file was deleted.

test/errchk.go

-240
This file was deleted.

test/fix_test.go

+15-26
Original file line numberDiff line numberDiff line change
@@ -8,37 +8,29 @@ import (
88

99
"github.com/stretchr/testify/require"
1010

11-
"github.com/golangci/golangci-lint/pkg/exitcodes"
1211
"github.com/golangci/golangci-lint/test/testshared"
1312
)
1413

1514
func TestFix(t *testing.T) {
16-
findSources := func(pathPatterns ...string) []string {
17-
sources, err := filepath.Glob(filepath.Join(pathPatterns...))
18-
require.NoError(t, err)
19-
require.NotEmpty(t, sources)
20-
return sources
21-
}
22-
2315
tmpDir := filepath.Join(testdataDir, "fix.tmp")
24-
os.RemoveAll(tmpDir) // cleanup after previous runs
16+
_ = os.RemoveAll(tmpDir) // cleanup previous runs
2517

2618
if os.Getenv("GL_KEEP_TEMP_FILES") == "1" {
2719
t.Logf("Temp dir for fix test: %s", tmpDir)
2820
} else {
29-
t.Cleanup(func() {
30-
os.RemoveAll(tmpDir)
31-
})
21+
t.Cleanup(func() { _ = os.RemoveAll(tmpDir) })
3222
}
3323

34-
fixDir := filepath.Join(testdataDir, "fix")
35-
err := exec.Command("cp", "-R", fixDir, tmpDir).Run()
24+
sourcesDir := filepath.Join(testdataDir, "fix")
25+
26+
err := exec.Command("cp", "-R", sourcesDir, tmpDir).Run()
3627
require.NoError(t, err)
3728

3829
testshared.InstallGolangciLint(t)
3930

40-
inputs := findSources(tmpDir, "in", "*.go")
41-
for _, input := range inputs {
31+
sources := findSources(t, tmpDir, "in", "*.go")
32+
33+
for _, input := range sources {
4234
input := input
4335
t.Run(filepath.Base(input), func(t *testing.T) {
4436
t.Parallel()
@@ -49,22 +41,19 @@ func TestFix(t *testing.T) {
4941
return
5042
}
5143

52-
runResult := testshared.NewRunnerBuilder(t).
53-
WithRunContext(rc).
54-
WithTargetPath(input).
44+
testshared.NewRunnerBuilder(t).
5545
WithArgs(
5646
"--disable-all",
5747
"--print-issued-lines=false",
5848
"--print-linter-name=false",
5949
"--out-format=line-number",
60-
"--fix").
50+
"--fix",
51+
).
52+
WithRunContext(rc).
53+
WithTargetPath(input).
6154
Runner().
62-
Run()
63-
64-
// nolintlint test uses non existing linters (bob, alice)
65-
if rc.ExpectedLinter != "nolintlint" {
66-
runResult.ExpectExitCode(exitcodes.Success)
67-
}
55+
Run().
56+
ExpectExitCode(rc.ExitCode)
6857

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

0 commit comments

Comments
 (0)