diff --git a/cmd/guru/guru_test.go b/cmd/guru/guru_test.go index 53134daddc..ef24c7f329 100644 --- a/cmd/guru/guru_test.go +++ b/cmd/guru/guru_test.go @@ -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 { diff --git a/cmd/guru/testdata/src/calls-json/main.golden b/cmd/guru/testdata/src/calls-json/main.golden index f5eced6be2..80de6695f0 100644 --- a/cmd/guru/testdata/src/calls-json/main.golden +++ b/cmd/guru/testdata/src/calls-json/main.golden @@ -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" } ] } diff --git a/cmd/guru/testdata/src/calls/main.golden b/cmd/guru/testdata/src/calls/main.golden index 9159cd60ec..ab68e95a63 100644 --- a/cmd/guru/testdata/src/calls/main.golden +++ b/cmd/guru/testdata/src/calls/main.golden @@ -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 diff --git a/cmd/guru/testdata/src/implements-methods-json/main.golden b/cmd/guru/testdata/src/implements-methods-json/main.golden index 831900a588..fa117df41f 100644 --- a/cmd/guru/testdata/src/implements-methods-json/main.golden +++ b/cmd/guru/testdata/src/implements-methods-json/main.golden @@ -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" } ] } diff --git a/cmd/guru/testdata/src/implements-methods/main.golden b/cmd/guru/testdata/src/implements-methods/main.golden index 227d305cbd..bd591e8476 100644 --- a/cmd/guru/testdata/src/implements-methods/main.golden +++ b/cmd/guru/testdata/src/implements-methods/main.golden @@ -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 diff --git a/cmd/guru/testdata/src/implements/main.golden b/cmd/guru/testdata/src/implements/main.golden index cb2f2ac57f..ee00f3d9fe 100644 --- a/cmd/guru/testdata/src/implements/main.golden +++ b/cmd/guru/testdata/src/implements/main.golden @@ -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 diff --git a/cmd/guru/testdata/src/imports/main.golden b/cmd/guru/testdata/src/imports/main.golden index 2e9d607ce0..66fe902b21 100644 --- a/cmd/guru/testdata/src/imports/main.golden +++ b/cmd/guru/testdata/src/imports/main.golden @@ -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" diff --git a/cmd/guru/testdata/src/peers/main.golden b/cmd/guru/testdata/src/peers/main.golden index 597a3c6c86..f97e672953 100644 --- a/cmd/guru/testdata/src/peers/main.golden +++ b/cmd/guru/testdata/src/peers/main.golden @@ -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 -------- diff --git a/cmd/guru/testdata/src/pointsto/main.golden b/cmd/guru/testdata/src/pointsto/main.golden index fd68bda6dd..7b12b2aff7 100644 --- a/cmd/guru/testdata/src/pointsto/main.golden +++ b/cmd/guru/testdata/src/pointsto/main.golden @@ -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: diff --git a/cmd/guru/testdata/src/reflection/main.golden b/cmd/guru/testdata/src/reflection/main.golden index 6190c0655a..4782132bd7 100644 --- a/cmd/guru/testdata/src/reflection/main.golden +++ b/cmd/guru/testdata/src/reflection/main.golden @@ -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: