Commit 33786830 authored by Josh Bleecher Snyder's avatar Josh Bleecher Snyder

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 #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: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 9c86eae3
...@@ -37,18 +37,18 @@ func fnop(*ast.File) bool { return false } ...@@ -37,18 +37,18 @@ func fnop(*ast.File) bool { return false }
func parseFixPrint(t *testing.T, fn func(*ast.File) bool, desc, in string, mustBeGofmt bool) (out string, fixed, ok bool) { func parseFixPrint(t *testing.T, fn func(*ast.File) bool, desc, in string, mustBeGofmt bool) (out string, fixed, ok bool) {
file, err := parser.ParseFile(fset, desc, in, parserMode) file, err := parser.ParseFile(fset, desc, in, parserMode)
if err != nil { if err != nil {
t.Errorf("%s: parsing: %v", desc, err) t.Errorf("parsing: %v", err)
return return
} }
outb, err := gofmtFile(file) outb, err := gofmtFile(file)
if err != nil { if err != nil {
t.Errorf("%s: printing: %v", desc, err) t.Errorf("printing: %v", err)
return return
} }
if s := string(outb); in != s && mustBeGofmt { if s := string(outb); in != s && mustBeGofmt {
t.Errorf("%s: not gofmt-formatted.\n--- %s\n%s\n--- %s | gofmt\n%s", t.Errorf("not gofmt-formatted.\n--- %s\n%s\n--- %s | gofmt\n%s",
desc, desc, in, desc, s) desc, in, desc, s)
tdiff(t, in, s) tdiff(t, in, s)
return return
} }
...@@ -65,7 +65,7 @@ func parseFixPrint(t *testing.T, fn func(*ast.File) bool, desc, in string, mustB ...@@ -65,7 +65,7 @@ func parseFixPrint(t *testing.T, fn func(*ast.File) bool, desc, in string, mustB
outb, err = gofmtFile(file) outb, err = gofmtFile(file)
if err != nil { if err != nil {
t.Errorf("%s: printing: %v", desc, err) t.Errorf("printing: %v", err)
return return
} }
...@@ -74,48 +74,51 @@ func parseFixPrint(t *testing.T, fn func(*ast.File) bool, desc, in string, mustB ...@@ -74,48 +74,51 @@ func parseFixPrint(t *testing.T, fn func(*ast.File) bool, desc, in string, mustB
func TestRewrite(t *testing.T) { func TestRewrite(t *testing.T) {
for _, tt := range testCases { for _, tt := range testCases {
t.Run(tt.Name, func(t *testing.T) {
t.Parallel()
// Apply fix: should get tt.Out. // Apply fix: should get tt.Out.
out, fixed, ok := parseFixPrint(t, tt.Fn, tt.Name, tt.In, true) out, fixed, ok := parseFixPrint(t, tt.Fn, tt.Name, tt.In, true)
if !ok { if !ok {
continue return
} }
// reformat to get printing right // reformat to get printing right
out, _, ok = parseFixPrint(t, fnop, tt.Name, out, false) out, _, ok = parseFixPrint(t, fnop, tt.Name, out, false)
if !ok { if !ok {
continue return
} }
if out != tt.Out { if out != tt.Out {
t.Errorf("%s: incorrect output.\n", tt.Name) t.Errorf("incorrect output.\n")
if !strings.HasPrefix(tt.Name, "testdata/") { if !strings.HasPrefix(tt.Name, "testdata/") {
t.Errorf("--- have\n%s\n--- want\n%s", out, tt.Out) t.Errorf("--- have\n%s\n--- want\n%s", out, tt.Out)
} }
tdiff(t, out, tt.Out) tdiff(t, out, tt.Out)
continue return
} }
if changed := out != tt.In; changed != fixed { if changed := out != tt.In; changed != fixed {
t.Errorf("%s: changed=%v != fixed=%v", tt.Name, changed, fixed) t.Errorf("changed=%v != fixed=%v", changed, fixed)
continue return
} }
// Should not change if run again. // Should not change if run again.
out2, fixed2, ok := parseFixPrint(t, tt.Fn, tt.Name+" output", out, true) out2, fixed2, ok := parseFixPrint(t, tt.Fn, tt.Name+" output", out, true)
if !ok { if !ok {
continue return
} }
if fixed2 { if fixed2 {
t.Errorf("%s: applied fixes during second round", tt.Name) t.Errorf("applied fixes during second round")
continue return
} }
if out2 != out { if out2 != out {
t.Errorf("%s: changed output after second round of fixes.\n--- output after first round\n%s\n--- output after second round\n%s", t.Errorf("changed output after second round of fixes.\n--- output after first round\n%s\n--- output after second round\n%s",
tt.Name, out, out2) out, out2)
tdiff(t, out, out2) tdiff(t, out, out2)
} }
})
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment