]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/fix: mark tests as parallel
authorJosh Bleecher Snyder <josharian@gmail.com>
Mon, 13 May 2019 18:56:15 +0000 (11:56 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Mon, 13 May 2019 20:03:20 +0000 (20:03 +0000)
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>
src/cmd/fix/main_test.go

index c2ace28caae365bbc79998f9789a5d44604d5390..8868140adefaf568cb558eb98679114777214bb0 100644 (file)
@@ -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)
+                       }
+               })
        }
 }