|
4 | 4 | "os"
|
5 | 5 | "os/exec"
|
6 | 6 | "path/filepath"
|
| 7 | + "sort" |
7 | 8 | "testing"
|
8 | 9 |
|
9 | 10 | "github.com/stretchr/testify/require"
|
@@ -35,25 +36,42 @@ func TestFix(t *testing.T) {
|
35 | 36 |
|
36 | 37 | sources := findSources(t, tmpDir, "in", "*.go")
|
37 | 38 |
|
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 |
39 | 47 | input := input
|
40 | 48 | t.Run(filepath.Base(input), func(t *testing.T) {
|
41 | 49 | t.Parallel()
|
42 | 50 |
|
43 | 51 | rc := testshared.ParseTestDirectives(t, input)
|
44 | 52 | 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 | + } |
45 | 57 | t.Logf("Skipped: %s", input)
|
46 | 58 | return
|
47 | 59 | }
|
48 | 60 |
|
| 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 | + } |
49 | 73 | 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...). |
57 | 75 | WithRunContext(rc).
|
58 | 76 | WithTargetPath(input).
|
59 | 77 | Runner().
|
|
0 commit comments