Skip to content

Commit 3378683

Browse files
committed
cmd/fix: mark tests as parallel
This speeds up go test -short -count=1 cmd/fix on my machine from about 8s to about 0.05s. Updates golang#26473 Change-Id: I698ee20704ae0aee874ba642e7b0e070ddc99194 Reviewed-on: https://go-review.googlesource.com/c/go/+/176900 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
1 parent 9c86eae commit 3378683

File tree

1 file changed

+43
-40
lines changed

1 file changed

+43
-40
lines changed

src/cmd/fix/main_test.go

Lines changed: 43 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,18 @@ func fnop(*ast.File) bool { return false }
3737
func parseFixPrint(t *testing.T, fn func(*ast.File) bool, desc, in string, mustBeGofmt bool) (out string, fixed, ok bool) {
3838
file, err := parser.ParseFile(fset, desc, in, parserMode)
3939
if err != nil {
40-
t.Errorf("%s: parsing: %v", desc, err)
40+
t.Errorf("parsing: %v", err)
4141
return
4242
}
4343

4444
outb, err := gofmtFile(file)
4545
if err != nil {
46-
t.Errorf("%s: printing: %v", desc, err)
46+
t.Errorf("printing: %v", err)
4747
return
4848
}
4949
if s := string(outb); in != s && mustBeGofmt {
50-
t.Errorf("%s: not gofmt-formatted.\n--- %s\n%s\n--- %s | gofmt\n%s",
51-
desc, desc, in, desc, s)
50+
t.Errorf("not gofmt-formatted.\n--- %s\n%s\n--- %s | gofmt\n%s",
51+
desc, in, desc, s)
5252
tdiff(t, in, s)
5353
return
5454
}
@@ -65,7 +65,7 @@ func parseFixPrint(t *testing.T, fn func(*ast.File) bool, desc, in string, mustB
6565

6666
outb, err = gofmtFile(file)
6767
if err != nil {
68-
t.Errorf("%s: printing: %v", desc, err)
68+
t.Errorf("printing: %v", err)
6969
return
7070
}
7171

@@ -74,48 +74,51 @@ func parseFixPrint(t *testing.T, fn func(*ast.File) bool, desc, in string, mustB
7474

7575
func TestRewrite(t *testing.T) {
7676
for _, tt := range testCases {
77-
// Apply fix: should get tt.Out.
78-
out, fixed, ok := parseFixPrint(t, tt.Fn, tt.Name, tt.In, true)
79-
if !ok {
80-
continue
81-
}
77+
t.Run(tt.Name, func(t *testing.T) {
78+
t.Parallel()
79+
// Apply fix: should get tt.Out.
80+
out, fixed, ok := parseFixPrint(t, tt.Fn, tt.Name, tt.In, true)
81+
if !ok {
82+
return
83+
}
8284

83-
// reformat to get printing right
84-
out, _, ok = parseFixPrint(t, fnop, tt.Name, out, false)
85-
if !ok {
86-
continue
87-
}
85+
// reformat to get printing right
86+
out, _, ok = parseFixPrint(t, fnop, tt.Name, out, false)
87+
if !ok {
88+
return
89+
}
8890

89-
if out != tt.Out {
90-
t.Errorf("%s: incorrect output.\n", tt.Name)
91-
if !strings.HasPrefix(tt.Name, "testdata/") {
92-
t.Errorf("--- have\n%s\n--- want\n%s", out, tt.Out)
91+
if out != tt.Out {
92+
t.Errorf("incorrect output.\n")
93+
if !strings.HasPrefix(tt.Name, "testdata/") {
94+
t.Errorf("--- have\n%s\n--- want\n%s", out, tt.Out)
95+
}
96+
tdiff(t, out, tt.Out)
97+
return
9398
}
94-
tdiff(t, out, tt.Out)
95-
continue
96-
}
9799

98-
if changed := out != tt.In; changed != fixed {
99-
t.Errorf("%s: changed=%v != fixed=%v", tt.Name, changed, fixed)
100-
continue
101-
}
100+
if changed := out != tt.In; changed != fixed {
101+
t.Errorf("changed=%v != fixed=%v", changed, fixed)
102+
return
103+
}
102104

103-
// Should not change if run again.
104-
out2, fixed2, ok := parseFixPrint(t, tt.Fn, tt.Name+" output", out, true)
105-
if !ok {
106-
continue
107-
}
105+
// Should not change if run again.
106+
out2, fixed2, ok := parseFixPrint(t, tt.Fn, tt.Name+" output", out, true)
107+
if !ok {
108+
return
109+
}
108110

109-
if fixed2 {
110-
t.Errorf("%s: applied fixes during second round", tt.Name)
111-
continue
112-
}
111+
if fixed2 {
112+
t.Errorf("applied fixes during second round")
113+
return
114+
}
113115

114-
if out2 != out {
115-
t.Errorf("%s: changed output after second round of fixes.\n--- output after first round\n%s\n--- output after second round\n%s",
116-
tt.Name, out, out2)
117-
tdiff(t, out, out2)
118-
}
116+
if out2 != out {
117+
t.Errorf("changed output after second round of fixes.\n--- output after first round\n%s\n--- output after second round\n%s",
118+
out, out2)
119+
tdiff(t, out, out2)
120+
}
121+
})
119122
}
120123
}
121124

0 commit comments

Comments
 (0)