Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b8ea93c

Browse files
committedMar 18, 2023
test: check that fixer works with --path-prefix
The combination with --path gets tested for the first test case. This is arbitrary. It could also be tested for all of them, but then each test would have to run twice (with and without).
1 parent 62c61eb commit b8ea93c

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed
 

‎test/fix_test.go

+26-8
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"os"
55
"os/exec"
66
"path/filepath"
7+
"sort"
78
"testing"
89

910
"github.com/stretchr/testify/require"
@@ -35,25 +36,42 @@ func TestFix(t *testing.T) {
3536

3637
sources := findSources(t, tmpDir, "in", "*.go")
3738

38-
for _, input := range sources {
39+
// The combination with --path gets tested for the first test case.
40+
// This is arbitrary. It could also be tested for all of them,
41+
// but then each test would have to run twice (with and without).
42+
// To make this determinstic, the sources get sorted by name.
43+
sort.Strings(sources)
44+
45+
for i, input := range sources {
46+
withPathPrefix := i == 0
3947
input := input
4048
t.Run(filepath.Base(input), func(t *testing.T) {
4149
t.Parallel()
4250

4351
rc := testshared.ParseTestDirectives(t, input)
4452
if rc == nil {
53+
if withPathPrefix {
54+
t.Errorf("The testcase %s should not get skipped, it's used for testing --path.", input)
55+
return
56+
}
4557
t.Logf("Skipped: %s", input)
4658
return
4759
}
4860

61+
args := []string{
62+
"--disable-all",
63+
"--print-issued-lines=false",
64+
"--print-linter-name=false",
65+
"--out-format=line-number",
66+
"--fix",
67+
}
68+
if withPathPrefix {
69+
t.Log("Testing with --path-prefix.")
70+
// This must not break fixing...
71+
args = append(args, "--path-prefix=foobar/")
72+
}
4973
testshared.NewRunnerBuilder(t).
50-
WithArgs(
51-
"--disable-all",
52-
"--print-issued-lines=false",
53-
"--print-linter-name=false",
54-
"--out-format=line-number",
55-
"--fix",
56-
).
74+
WithArgs(args...).
5775
WithRunContext(rc).
5876
WithTargetPath(input).
5977
Runner().

0 commit comments

Comments
 (0)
Please sign in to comment.