mirror of
https://github.com/golang/go
synced 2024-11-18 09:04:49 -07:00
cmd/guru: fix tests
A consequence of CL 19747 was that ad hoc packages of a single filename are no longer valid -scope arguments, which broke most of the tests. This CL fixes the tests by extracting the import path from the filename. The test output now includes the import path, not the package name, of each of these packages, so the output was updated too. Also, the -scope argument caused the main package to be imported twice, once as main.go and once under its import path, causing duplicate 'implements' results. I'm not sure how I failed to notice this. Change-Id: I6fb3ae3e1497f0eb8cf88f453660b9e2fd9718d8 Reviewed-on: https://go-review.googlesource.com/19886 Reviewed-by: Michael Matloob <matloob@golang.org>
This commit is contained in:
parent
108746816d
commit
2327a65811
@ -38,6 +38,7 @@ import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"strconv"
|
||||
@ -169,11 +170,12 @@ func doQuery(out io.Writer, q *query, useJson bool) {
|
||||
|
||||
var buildContext = build.Default
|
||||
buildContext.GOPATH = "testdata"
|
||||
pkg := filepath.Dir(strings.TrimPrefix(q.filename, "testdata/src/"))
|
||||
query := guru.Query{
|
||||
Mode: q.verb,
|
||||
Pos: q.queryPos,
|
||||
Build: &buildContext,
|
||||
Scope: []string{q.filename},
|
||||
Scope: []string{pkg},
|
||||
Reflection: true,
|
||||
}
|
||||
if err := guru.Run(&query); err != nil {
|
||||
|
8
cmd/guru/testdata/src/calls-json/main.golden
vendored
8
cmd/guru/testdata/src/calls-json/main.golden
vendored
@ -6,7 +6,7 @@
|
||||
"desc": "dynamic function call",
|
||||
"callees": [
|
||||
{
|
||||
"name": "main.main$1",
|
||||
"name": "calls-json.main$1",
|
||||
"pos": "testdata/src/calls-json/main.go:12:7"
|
||||
}
|
||||
]
|
||||
@ -17,17 +17,17 @@
|
||||
"mode": "callstack",
|
||||
"callstack": {
|
||||
"pos": "testdata/src/calls-json/main.go:12:7",
|
||||
"target": "main.main$1",
|
||||
"target": "calls-json.main$1",
|
||||
"callers": [
|
||||
{
|
||||
"pos": "testdata/src/calls-json/main.go:8:3",
|
||||
"desc": "dynamic function call",
|
||||
"caller": "main.call"
|
||||
"caller": "calls-json.call"
|
||||
},
|
||||
{
|
||||
"pos": "testdata/src/calls-json/main.go:12:6",
|
||||
"desc": "static function call",
|
||||
"caller": "main.main"
|
||||
"caller": "calls-json.main"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
66
cmd/guru/testdata/src/calls/main.golden
vendored
66
cmd/guru/testdata/src/calls/main.golden
vendored
@ -4,10 +4,10 @@ this *int may point to these objects:
|
||||
b
|
||||
|
||||
-------- @callstack callstack-A --------
|
||||
Found a call path from root to main.A
|
||||
main.A
|
||||
dynamic function call from main.apply
|
||||
concurrent static function call from main.main
|
||||
Found a call path from root to calls.A
|
||||
calls.A
|
||||
dynamic function call from calls.apply
|
||||
concurrent static function call from calls.main
|
||||
|
||||
-------- @pointsto pointsto-B-x --------
|
||||
this *int may point to these objects:
|
||||
@ -15,40 +15,40 @@ this *int may point to these objects:
|
||||
b
|
||||
|
||||
-------- @callers callers-B --------
|
||||
main.B is called from these 1 sites:
|
||||
dynamic function call from main.apply
|
||||
calls.B is called from these 1 sites:
|
||||
dynamic function call from calls.apply
|
||||
|
||||
-------- @callees callees-apply --------
|
||||
this dynamic function call dispatches to:
|
||||
main.A
|
||||
main.B
|
||||
calls.A
|
||||
calls.B
|
||||
|
||||
-------- @callers callers-apply --------
|
||||
main.apply is called from these 2 sites:
|
||||
concurrent static function call from main.main
|
||||
deferred static function call from main.main
|
||||
calls.apply is called from these 2 sites:
|
||||
concurrent static function call from calls.main
|
||||
deferred static function call from calls.main
|
||||
|
||||
-------- @callers callers-store --------
|
||||
main.store is called from these 2 sites:
|
||||
static function call from main.main
|
||||
static function call from main.main
|
||||
calls.store is called from these 2 sites:
|
||||
static function call from calls.main
|
||||
static function call from calls.main
|
||||
|
||||
-------- @pointsto pointsto-result-f --------
|
||||
this func() *int may point to these objects:
|
||||
main.main$1
|
||||
calls.main$1
|
||||
|
||||
-------- @callees callees-main.call-f --------
|
||||
this dynamic function call dispatches to:
|
||||
main.main$1
|
||||
calls.main$1
|
||||
|
||||
-------- @callers callers-main.call --------
|
||||
main.call is called from these 2 sites:
|
||||
static function call from main.main
|
||||
static function call from main.main
|
||||
calls.call is called from these 2 sites:
|
||||
static function call from calls.main
|
||||
static function call from calls.main
|
||||
|
||||
-------- @callees callees-main-apply1 --------
|
||||
this static function call dispatches to:
|
||||
main.apply
|
||||
calls.apply
|
||||
|
||||
-------- @pointsto pointsto-pc --------
|
||||
this *int may point to these objects:
|
||||
@ -72,7 +72,7 @@ Error: this is a type conversion, not a function call
|
||||
Error: ambiguous selection within function call (or conversion)
|
||||
-------- @callees callees-err-deadcode1 --------
|
||||
this static function call dispatches to:
|
||||
main.main
|
||||
calls.main
|
||||
|
||||
-------- @callees callees-err-nil-func --------
|
||||
dynamic function call on nil value
|
||||
@ -82,11 +82,11 @@ dynamic method call on nil value
|
||||
|
||||
-------- @callees callees-not-a-wrapper --------
|
||||
this dynamic method call dispatches to:
|
||||
(main.myint).f
|
||||
(calls.myint).f
|
||||
|
||||
-------- @callees callees-static-call --------
|
||||
this static function call dispatches to:
|
||||
main.foo
|
||||
calls.foo
|
||||
|
||||
-------- @callees callees-qualified-call --------
|
||||
this static function call dispatches to:
|
||||
@ -94,32 +94,32 @@ this static function call dispatches to:
|
||||
|
||||
-------- @callees callees-static-method-call --------
|
||||
this static function call dispatches to:
|
||||
(main.method).f
|
||||
(calls.method).f
|
||||
|
||||
-------- @callees callees-implicit-selection-method-call --------
|
||||
this dynamic method call dispatches to:
|
||||
(main.method).f
|
||||
(calls.method).f
|
||||
|
||||
-------- @callers callers-not-a-wrapper --------
|
||||
(main.myint).f is called from these 1 sites:
|
||||
dynamic method call from main.main
|
||||
(calls.myint).f is called from these 1 sites:
|
||||
dynamic method call from calls.main
|
||||
|
||||
-------- @callees callees-err-deadcode2 --------
|
||||
this static function call dispatches to:
|
||||
main.main
|
||||
calls.main
|
||||
|
||||
-------- @callstack callstack-err-deadcode --------
|
||||
main.deadcode is unreachable in this analysis scope
|
||||
calls.deadcode is unreachable in this analysis scope
|
||||
|
||||
-------- @callees callees-err-deadcode3 --------
|
||||
|
||||
Error: this call site is unreachable in this analysis
|
||||
-------- @callers callers-global --------
|
||||
main.init is called from these 1 sites:
|
||||
calls.init is called from these 1 sites:
|
||||
the root of the call graph
|
||||
|
||||
-------- @callstack callstack-init --------
|
||||
Found a call path from root to main.init#1
|
||||
main.init#1
|
||||
static function call from main.init
|
||||
Found a call path from root to calls.init#1
|
||||
calls.init#1
|
||||
static function call from calls.init
|
||||
|
||||
|
@ -274,18 +274,6 @@
|
||||
"name": "lib.Type",
|
||||
"pos": "testdata/src/lib/lib.go:3:6",
|
||||
"kind": "basic"
|
||||
},
|
||||
{
|
||||
"name": "main.I",
|
||||
"pos": "testdata/src/implements-methods-json/main.go:35:6",
|
||||
"kind": "interface"
|
||||
}
|
||||
],
|
||||
"from": [
|
||||
{
|
||||
"name": "main.I",
|
||||
"pos": "testdata/src/implements-methods-json/main.go:35:6",
|
||||
"kind": "interface"
|
||||
}
|
||||
],
|
||||
"method": {
|
||||
@ -296,16 +284,6 @@
|
||||
{
|
||||
"name": "method (lib.Type) Method(x *int) *int",
|
||||
"pos": "testdata/src/lib/lib.go:5:13"
|
||||
},
|
||||
{
|
||||
"name": "method (main.I) Method(*int) *int",
|
||||
"pos": "testdata/src/implements-methods-json/main.go:36:2"
|
||||
}
|
||||
],
|
||||
"from_method": [
|
||||
{
|
||||
"name": "method (main.I) Method(*int) *int",
|
||||
"pos": "testdata/src/implements-methods-json/main.go:36:2"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -34,6 +34,4 @@ concrete method func (sorter).Len() int
|
||||
-------- @implements I.Method --------
|
||||
abstract method func (I).Method(*int) *int
|
||||
is implemented by method (lib.Type).Method
|
||||
is implemented by method (main.I).Method
|
||||
implements method (main.I).Method
|
||||
|
||||
|
2
cmd/guru/testdata/src/implements/main.golden
vendored
2
cmd/guru/testdata/src/implements/main.golden
vendored
@ -41,6 +41,4 @@ slice type sorter
|
||||
-------- @implements I --------
|
||||
interface type I
|
||||
is implemented by basic type lib.Type
|
||||
is implemented by interface type main.I
|
||||
implements main.I
|
||||
|
||||
|
2
cmd/guru/testdata/src/imports/main.golden
vendored
2
cmd/guru/testdata/src/imports/main.golden
vendored
@ -42,7 +42,7 @@ defined here
|
||||
|
||||
-------- @pointsto p --------
|
||||
this *int may point to these objects:
|
||||
main.a
|
||||
imports.a
|
||||
|
||||
-------- @describe ref-pkg --------
|
||||
reference to package "lib"
|
||||
|
2
cmd/guru/testdata/src/peers/main.golden
vendored
2
cmd/guru/testdata/src/peers/main.golden
vendored
@ -26,7 +26,7 @@ This channel of type chan *int may be:
|
||||
|
||||
-------- @pointsto pointsto-rA --------
|
||||
this *int may point to these objects:
|
||||
main.a2
|
||||
peers.a2
|
||||
a1
|
||||
|
||||
-------- @peers peer-recv-chB --------
|
||||
|
16
cmd/guru/testdata/src/pointsto/main.golden
vendored
16
cmd/guru/testdata/src/pointsto/main.golden
vendored
@ -3,33 +3,33 @@
|
||||
Error: pointer analysis wants an expression of reference type; got untyped float
|
||||
-------- @pointsto func-ref-main --------
|
||||
this func() may point to these objects:
|
||||
main.main
|
||||
pointsto.main
|
||||
|
||||
-------- @pointsto func-ref-*C.f --------
|
||||
this func() may point to these objects:
|
||||
(*main.C).f
|
||||
(*pointsto.C).f
|
||||
|
||||
-------- @pointsto func-ref-D.f --------
|
||||
this func() may point to these objects:
|
||||
(main.D).f
|
||||
(pointsto.D).f
|
||||
|
||||
-------- @pointsto func-ref-I.f --------
|
||||
|
||||
Error: func (main.I).f() is an interface method
|
||||
Error: func (pointsto.I).f() is an interface method
|
||||
-------- @pointsto func-ref-d.f --------
|
||||
this func() may point to these objects:
|
||||
(main.D).f
|
||||
(pointsto.D).f
|
||||
|
||||
-------- @pointsto func-ref-i.f --------
|
||||
|
||||
Error: func (main.I).f() is an interface method
|
||||
Error: func (pointsto.I).f() is an interface method
|
||||
-------- @pointsto ref-lexical-d.f --------
|
||||
this func() may point to these objects:
|
||||
(main.D).f
|
||||
(pointsto.D).f
|
||||
|
||||
-------- @pointsto ref-anon --------
|
||||
this func() may point to these objects:
|
||||
main.main$1
|
||||
pointsto.main$1
|
||||
|
||||
-------- @pointsto ref-global --------
|
||||
this *string may point to these objects:
|
||||
|
10
cmd/guru/testdata/src/reflection/main.golden
vendored
10
cmd/guru/testdata/src/reflection/main.golden
vendored
@ -1,18 +1,18 @@
|
||||
-------- @pointsto mrv --------
|
||||
this reflect.Value may contain these dynamic types:
|
||||
*bool, may point to:
|
||||
main.b
|
||||
reflection.b
|
||||
*int, may point to:
|
||||
main.a
|
||||
reflection.a
|
||||
map[*int]*bool, may point to:
|
||||
makemap
|
||||
|
||||
-------- @pointsto p1 --------
|
||||
this interface{} may contain these dynamic types:
|
||||
*bool, may point to:
|
||||
main.b
|
||||
reflection.b
|
||||
*int, may point to:
|
||||
main.a
|
||||
reflection.a
|
||||
map[*int]*bool, may point to:
|
||||
makemap
|
||||
|
||||
@ -23,7 +23,7 @@ this []reflect.Value may point to these objects:
|
||||
-------- @pointsto p3 --------
|
||||
this reflect.Value may contain these dynamic types:
|
||||
*int, may point to:
|
||||
main.a
|
||||
reflection.a
|
||||
|
||||
-------- @pointsto p4 --------
|
||||
this reflect.Type may contain these dynamic types:
|
||||
|
Loading…
Reference in New Issue
Block a user