go.tools/oracle: fix minor but confusing bug in test driver.
Since rev 4c5f46cc7b9d, error messages no longer contain "file:line:col: " prefixes, so applying stripLocation to them is incorrect. Also: add rationale comment to callgraph2.go test. R=crawshaw CC=golang-dev https://golang.org/cl/13888044
This commit is contained in:
parent
ae060fe849
commit
2bd0ec31c0
|
@ -147,12 +147,17 @@ func parseQueries(t *testing.T, filename string) []*query {
|
||||||
return queries
|
return queries
|
||||||
}
|
}
|
||||||
|
|
||||||
// stripLocation removes a "file:line: " prefix.
|
// WriteResult writes res (-format=plain) to w, stripping file locations.
|
||||||
func stripLocation(line string) string {
|
func WriteResult(w io.Writer, res *oracle.Result) {
|
||||||
if i := strings.Index(line, ": "); i >= 0 {
|
capture := new(bytes.Buffer) // capture standard output
|
||||||
line = line[i+2:]
|
res.WriteTo(capture)
|
||||||
|
for _, line := range strings.Split(capture.String(), "\n") {
|
||||||
|
// Remove a "file:line: " prefix.
|
||||||
|
if i := strings.Index(line, ": "); i >= 0 {
|
||||||
|
line = line[i+2:]
|
||||||
|
}
|
||||||
|
fmt.Fprintf(w, "%s\n", line)
|
||||||
}
|
}
|
||||||
return line
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// doQuery poses query q to the oracle and writes its response and
|
// doQuery poses query q to the oracle and writes its response and
|
||||||
|
@ -169,7 +174,7 @@ func doQuery(out io.Writer, q *query, useJson bool) {
|
||||||
&buildContext,
|
&buildContext,
|
||||||
true) // reflection
|
true) // reflection
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(out, "\nError: %s\n", stripLocation(err.Error()))
|
fmt.Fprintf(out, "\nError: %s\n", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -183,11 +188,7 @@ func doQuery(out io.Writer, q *query, useJson bool) {
|
||||||
out.Write(b)
|
out.Write(b)
|
||||||
} else {
|
} else {
|
||||||
// "plain" (compiler diagnostic format) output
|
// "plain" (compiler diagnostic format) output
|
||||||
capture := new(bytes.Buffer) // capture standard output
|
WriteResult(out, res)
|
||||||
res.WriteTo(capture)
|
|
||||||
for _, line := range strings.Split(capture.String(), "\n") {
|
|
||||||
fmt.Fprintf(out, "%s\n", stripLocation(line))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -272,18 +273,14 @@ func TestMultipleQueries(t *testing.T) {
|
||||||
// Release the other ASTs and type info to the GC.
|
// Release the other ASTs and type info to the GC.
|
||||||
imp = nil
|
imp = nil
|
||||||
|
|
||||||
// Run different query moes on same scope and selection.
|
// Run different query modes on same scope and selection.
|
||||||
out := new(bytes.Buffer)
|
out := new(bytes.Buffer)
|
||||||
for _, mode := range [...]string{"callers", "describe", "freevars"} {
|
for _, mode := range [...]string{"callers", "describe", "freevars"} {
|
||||||
res, err := o.Query(mode, qpos)
|
res, err := o.Query(mode, qpos)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("(*oracle.Oracle).Query(%q) failed: %s", pos, err)
|
t.Errorf("(*oracle.Oracle).Query(%q) failed: %s", pos, err)
|
||||||
}
|
}
|
||||||
capture := new(bytes.Buffer) // capture standard output
|
WriteResult(out, res)
|
||||||
res.WriteTo(capture)
|
|
||||||
for _, line := range strings.Split(capture.String(), "\n") {
|
|
||||||
fmt.Fprintf(out, "%s\n", stripLocation(line))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
want := `multi.f is called from these 1 sites:
|
want := `multi.f is called from these 1 sites:
|
||||||
static function call from multi.main
|
static function call from multi.main
|
||||||
|
|
|
@ -4,6 +4,8 @@ package main
|
||||||
// See go.tools/oracle/oracle_test.go for explanation.
|
// See go.tools/oracle/oracle_test.go for explanation.
|
||||||
// See callgraph2.golden for expected query results.
|
// See callgraph2.golden for expected query results.
|
||||||
|
|
||||||
|
// (Regression test for pointer analysis: programs that use reflection
|
||||||
|
// create some cgnodes before the root of the callgraph.)
|
||||||
import _ "reflect"
|
import _ "reflect"
|
||||||
|
|
||||||
func f() {}
|
func f() {}
|
||||||
|
|
Loading…
Reference in New Issue