mirror of
https://github.com/golang/go
synced 2024-11-18 17:44:47 -07:00
cmd/guru: make tests granular and parallel
This make it possible to easily run individual guru tests. It also slightly speeds up the overall test run, from 23s to 18s on my machine; the TestGuru/calls is now the limiting factor, by a significant margin. This work supported by Sourcegraph. Change-Id: If61ebf1cc60441a65274f3fddd31f69c7ca23b48 Reviewed-on: https://go-review.googlesource.com/108876 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Alan Donovan <adonovan@google.com>
This commit is contained in:
parent
94b14834a2
commit
7e5e8df4df
@ -6,7 +6,7 @@ package main_test
|
|||||||
|
|
||||||
// This file defines a test framework for guru queries.
|
// This file defines a test framework for guru queries.
|
||||||
//
|
//
|
||||||
// The files beneath testdata/src/main contain Go programs containing
|
// The files beneath testdata/src contain Go programs containing
|
||||||
// query annotations of the form:
|
// query annotations of the form:
|
||||||
//
|
//
|
||||||
// @verb id "select"
|
// @verb id "select"
|
||||||
@ -246,65 +246,69 @@ func TestGuru(t *testing.T) {
|
|||||||
"testdata/src/referrers-json/main.go",
|
"testdata/src/referrers-json/main.go",
|
||||||
"testdata/src/what-json/main.go",
|
"testdata/src/what-json/main.go",
|
||||||
} {
|
} {
|
||||||
if filename == "testdata/src/referrers/main.go" && runtime.GOOS == "plan9" {
|
filename := filename
|
||||||
// Disable this test on plan9 since it expects a particular
|
name := strings.Split(filename, "/")[2]
|
||||||
// wording for a "no such file or directory" error.
|
t.Run(name, func(t *testing.T) {
|
||||||
continue
|
t.Parallel()
|
||||||
}
|
if filename == "testdata/src/referrers/main.go" && runtime.GOOS == "plan9" {
|
||||||
if filename == "testdata/src/alias/alias.go" && !guru.HasAlias {
|
// Disable this test on plan9 since it expects a particular
|
||||||
continue
|
// wording for a "no such file or directory" error.
|
||||||
}
|
t.Skip()
|
||||||
if strings.HasSuffix(filename, "19.go") && !contains(build.Default.ReleaseTags, "go1.9") {
|
}
|
||||||
// TODO(adonovan): recombine the 'describe' and 'definition'
|
if filename == "testdata/src/alias/alias.go" && !guru.HasAlias {
|
||||||
// tests once we drop support for go1.8.
|
t.Skip()
|
||||||
continue
|
}
|
||||||
}
|
if strings.HasSuffix(filename, "19.go") && !contains(build.Default.ReleaseTags, "go1.9") {
|
||||||
if filename == "testdata/src/referrers/main.go" && !contains(build.Default.ReleaseTags, "go1.11") {
|
// TODO(adonovan): recombine the 'describe' and 'definition'
|
||||||
// Disabling broken test on Go 1.9 and Go 1.10. https://golang.org/issue/24421
|
// tests once we drop support for go1.8.
|
||||||
// TODO(gri,adonovan): fix this test.
|
t.Skip()
|
||||||
continue
|
}
|
||||||
}
|
if filename == "testdata/src/referrers/main.go" && !contains(build.Default.ReleaseTags, "go1.11") {
|
||||||
|
// Disabling broken test on Go 1.9 and Go 1.10. https://golang.org/issue/24421
|
||||||
|
// TODO(gri,adonovan): fix this test.
|
||||||
|
t.Skip()
|
||||||
|
}
|
||||||
|
|
||||||
json := strings.Contains(filename, "-json/")
|
json := strings.Contains(filename, "-json/")
|
||||||
queries := parseQueries(t, filename)
|
queries := parseQueries(t, filename)
|
||||||
golden := filename + "lden"
|
golden := filename + "lden"
|
||||||
got := filename + "t"
|
got := filename + "t"
|
||||||
gotfh, err := os.Create(got)
|
gotfh, err := os.Create(got)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Create(%s) failed: %s", got, err)
|
t.Fatalf("Create(%s) failed: %s", got, err)
|
||||||
continue
|
}
|
||||||
}
|
defer os.Remove(got)
|
||||||
defer os.Remove(got)
|
defer gotfh.Close()
|
||||||
defer gotfh.Close()
|
|
||||||
|
|
||||||
// Run the guru on each query, redirecting its output
|
// Run the guru on each query, redirecting its output
|
||||||
// and error (if any) to the foo.got file.
|
// and error (if any) to the foo.got file.
|
||||||
for _, q := range queries {
|
for _, q := range queries {
|
||||||
doQuery(gotfh, q, json)
|
doQuery(gotfh, q, json)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compare foo.got with foo.golden.
|
// Compare foo.got with foo.golden.
|
||||||
var cmd *exec.Cmd
|
var cmd *exec.Cmd
|
||||||
switch runtime.GOOS {
|
switch runtime.GOOS {
|
||||||
case "plan9":
|
case "plan9":
|
||||||
cmd = exec.Command("/bin/diff", "-c", golden, got)
|
cmd = exec.Command("/bin/diff", "-c", golden, got)
|
||||||
default:
|
default:
|
||||||
cmd = exec.Command("/usr/bin/diff", "-u", golden, got)
|
cmd = exec.Command("/usr/bin/diff", "-u", golden, got)
|
||||||
}
|
}
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
cmd.Stdout = buf
|
cmd.Stdout = buf
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
if err := cmd.Run(); err != nil {
|
if err := cmd.Run(); err != nil {
|
||||||
t.Errorf("Guru tests for %s failed: %s.\n%s\n",
|
t.Errorf("Guru tests for %s failed: %s.\n%s\n",
|
||||||
filename, err, buf)
|
filename, err, buf)
|
||||||
|
|
||||||
if *updateFlag {
|
if *updateFlag {
|
||||||
t.Logf("Updating %s...", golden)
|
t.Logf("Updating %s...", golden)
|
||||||
if err := exec.Command("/bin/cp", got, golden).Run(); err != nil {
|
if err := exec.Command("/bin/cp", got, golden).Run(); err != nil {
|
||||||
t.Errorf("Update failed: %s", err)
|
t.Errorf("Update failed: %s", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user