aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/fix
diff options
context:
space:
mode:
authorJosh Bleecher Snyder <josharian@gmail.com>2019-05-13 11:56:15 -0700
committerJosh Bleecher Snyder <josharian@gmail.com>2019-05-13 20:03:20 +0000
commit337868305401dbe82a6a7235bb613392e86d8b40 (patch)
tree6f699c71d20c336e782526cfc0888e1b60a88031 /src/cmd/fix
parent9c86eae3844105c2e66ca6064ca70fd287894819 (diff)
downloadgo-337868305401dbe82a6a7235bb613392e86d8b40.tar.gz
go-337868305401dbe82a6a7235bb613392e86d8b40.zip
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: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'src/cmd/fix')
-rw-r--r--src/cmd/fix/main_test.go83
1 files changed, 43 insertions, 40 deletions
diff --git a/src/cmd/fix/main_test.go b/src/cmd/fix/main_test.go
index c2ace28caa..8868140ade 100644
--- a/src/cmd/fix/main_test.go
+++ b/src/cmd/fix/main_test.go
@@ -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) {
file, err := parser.ParseFile(fset, desc, in, parserMode)
if err != nil {
- t.Errorf("%s: parsing: %v", desc, err)
+ t.Errorf("parsing: %v", err)
return
}
outb, err := gofmtFile(file)
if err != nil {
- t.Errorf("%s: printing: %v", desc, err)
+ t.Errorf("printing: %v", err)
return
}
if s := string(outb); in != s && mustBeGofmt {
- t.Errorf("%s: not gofmt-formatted.\n--- %s\n%s\n--- %s | gofmt\n%s",
- desc, desc, in, desc, s)
+ t.Errorf("not gofmt-formatted.\n--- %s\n%s\n--- %s | gofmt\n%s",
+ desc, in, desc, s)
tdiff(t, in, s)
return
}
@@ -65,7 +65,7 @@ func parseFixPrint(t *testing.T, fn func(*ast.File) bool, desc, in string, mustB
outb, err = gofmtFile(file)
if err != nil {
- t.Errorf("%s: printing: %v", desc, err)
+ t.Errorf("printing: %v", err)
return
}
@@ -74,48 +74,51 @@ func parseFixPrint(t *testing.T, fn func(*ast.File) bool, desc, in string, mustB
func TestRewrite(t *testing.T) {
for _, tt := range testCases {
- // Apply fix: should get tt.Out.
- out, fixed, ok := parseFixPrint(t, tt.Fn, tt.Name, tt.In, true)
- if !ok {
- continue
- }
+ t.Run(tt.Name, func(t *testing.T) {
+ t.Parallel()
+ // Apply fix: should get tt.Out.
+ out, fixed, ok := parseFixPrint(t, tt.Fn, tt.Name, tt.In, true)
+ if !ok {
+ return
+ }
- // reformat to get printing right
- out, _, ok = parseFixPrint(t, fnop, tt.Name, out, false)
- if !ok {
- continue
- }
+ // reformat to get printing right
+ out, _, ok = parseFixPrint(t, fnop, tt.Name, out, false)
+ if !ok {
+ return
+ }
- if out != tt.Out {
- t.Errorf("%s: incorrect output.\n", tt.Name)
- if !strings.HasPrefix(tt.Name, "testdata/") {
- t.Errorf("--- have\n%s\n--- want\n%s", out, tt.Out)
+ if out != tt.Out {
+ t.Errorf("incorrect output.\n")
+ if !strings.HasPrefix(tt.Name, "testdata/") {
+ t.Errorf("--- have\n%s\n--- want\n%s", out, tt.Out)
+ }
+ tdiff(t, out, tt.Out)
+ return
}
- tdiff(t, out, tt.Out)
- continue
- }
- if changed := out != tt.In; changed != fixed {
- t.Errorf("%s: changed=%v != fixed=%v", tt.Name, changed, fixed)
- continue
- }
+ if changed := out != tt.In; changed != fixed {
+ t.Errorf("changed=%v != fixed=%v", changed, fixed)
+ return
+ }
- // Should not change if run again.
- out2, fixed2, ok := parseFixPrint(t, tt.Fn, tt.Name+" output", out, true)
- if !ok {
- continue
- }
+ // Should not change if run again.
+ out2, fixed2, ok := parseFixPrint(t, tt.Fn, tt.Name+" output", out, true)
+ if !ok {
+ return
+ }
- if fixed2 {
- t.Errorf("%s: applied fixes during second round", tt.Name)
- continue
- }
+ if fixed2 {
+ t.Errorf("applied fixes during second round")
+ return
+ }
- 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",
- tt.Name, out, out2)
- tdiff(t, out, out2)
- }
+ if out2 != out {
+ t.Errorf("changed output after second round of fixes.\n--- output after first round\n%s\n--- output after second round\n%s",
+ out, out2)
+ tdiff(t, out, out2)
+ }
+ })
}
}