mirror of https://github.com/golang/go.git
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>
This commit is contained in:
parent
9c86eae384
commit
3378683054
|
|
@ -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
|
||||
}
|
||||
|
||||
// reformat to get printing right
|
||||
out, _, ok = parseFixPrint(t, fnop, tt.Name, out, false)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
|
||||
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)
|
||||
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
|
||||
}
|
||||
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
|
||||
}
|
||||
// reformat to get printing right
|
||||
out, _, ok = parseFixPrint(t, fnop, tt.Name, out, false)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
// Should not change if run again.
|
||||
out2, fixed2, ok := parseFixPrint(t, tt.Fn, tt.Name+" output", out, true)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
if fixed2 {
|
||||
t.Errorf("%s: applied fixes during second round", tt.Name)
|
||||
continue
|
||||
}
|
||||
if changed := out != tt.In; changed != fixed {
|
||||
t.Errorf("changed=%v != fixed=%v", changed, fixed)
|
||||
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)
|
||||
}
|
||||
// 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("applied fixes during second round")
|
||||
return
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue