1
0
mirror of https://github.com/golang/go synced 2024-11-18 11:34:45 -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:
Alan Donovan 2016-02-25 17:06:15 -05:00
parent 108746816d
commit 2327a65811
10 changed files with 55 additions and 79 deletions

View File

@ -38,6 +38,7 @@ import (
"io/ioutil" "io/ioutil"
"os" "os"
"os/exec" "os/exec"
"path/filepath"
"regexp" "regexp"
"runtime" "runtime"
"strconv" "strconv"
@ -169,11 +170,12 @@ func doQuery(out io.Writer, q *query, useJson bool) {
var buildContext = build.Default var buildContext = build.Default
buildContext.GOPATH = "testdata" buildContext.GOPATH = "testdata"
pkg := filepath.Dir(strings.TrimPrefix(q.filename, "testdata/src/"))
query := guru.Query{ query := guru.Query{
Mode: q.verb, Mode: q.verb,
Pos: q.queryPos, Pos: q.queryPos,
Build: &buildContext, Build: &buildContext,
Scope: []string{q.filename}, Scope: []string{pkg},
Reflection: true, Reflection: true,
} }
if err := guru.Run(&query); err != nil { if err := guru.Run(&query); err != nil {

View File

@ -6,7 +6,7 @@
"desc": "dynamic function call", "desc": "dynamic function call",
"callees": [ "callees": [
{ {
"name": "main.main$1", "name": "calls-json.main$1",
"pos": "testdata/src/calls-json/main.go:12:7" "pos": "testdata/src/calls-json/main.go:12:7"
} }
] ]
@ -17,17 +17,17 @@
"mode": "callstack", "mode": "callstack",
"callstack": { "callstack": {
"pos": "testdata/src/calls-json/main.go:12:7", "pos": "testdata/src/calls-json/main.go:12:7",
"target": "main.main$1", "target": "calls-json.main$1",
"callers": [ "callers": [
{ {
"pos": "testdata/src/calls-json/main.go:8:3", "pos": "testdata/src/calls-json/main.go:8:3",
"desc": "dynamic function call", "desc": "dynamic function call",
"caller": "main.call" "caller": "calls-json.call"
}, },
{ {
"pos": "testdata/src/calls-json/main.go:12:6", "pos": "testdata/src/calls-json/main.go:12:6",
"desc": "static function call", "desc": "static function call",
"caller": "main.main" "caller": "calls-json.main"
} }
] ]
} }

View File

@ -4,10 +4,10 @@ this *int may point to these objects:
b b
-------- @callstack callstack-A -------- -------- @callstack callstack-A --------
Found a call path from root to main.A Found a call path from root to calls.A
main.A calls.A
dynamic function call from main.apply dynamic function call from calls.apply
concurrent static function call from main.main concurrent static function call from calls.main
-------- @pointsto pointsto-B-x -------- -------- @pointsto pointsto-B-x --------
this *int may point to these objects: this *int may point to these objects:
@ -15,40 +15,40 @@ this *int may point to these objects:
b b
-------- @callers callers-B -------- -------- @callers callers-B --------
main.B is called from these 1 sites: calls.B is called from these 1 sites:
dynamic function call from main.apply dynamic function call from calls.apply
-------- @callees callees-apply -------- -------- @callees callees-apply --------
this dynamic function call dispatches to: this dynamic function call dispatches to:
main.A calls.A
main.B calls.B
-------- @callers callers-apply -------- -------- @callers callers-apply --------
main.apply is called from these 2 sites: calls.apply is called from these 2 sites:
concurrent static function call from main.main concurrent static function call from calls.main
deferred static function call from main.main deferred static function call from calls.main
-------- @callers callers-store -------- -------- @callers callers-store --------
main.store is called from these 2 sites: calls.store is called from these 2 sites:
static function call from main.main static function call from calls.main
static function call from main.main static function call from calls.main
-------- @pointsto pointsto-result-f -------- -------- @pointsto pointsto-result-f --------
this func() *int may point to these objects: this func() *int may point to these objects:
main.main$1 calls.main$1
-------- @callees callees-main.call-f -------- -------- @callees callees-main.call-f --------
this dynamic function call dispatches to: this dynamic function call dispatches to:
main.main$1 calls.main$1
-------- @callers callers-main.call -------- -------- @callers callers-main.call --------
main.call is called from these 2 sites: calls.call is called from these 2 sites:
static function call from main.main static function call from calls.main
static function call from main.main static function call from calls.main
-------- @callees callees-main-apply1 -------- -------- @callees callees-main-apply1 --------
this static function call dispatches to: this static function call dispatches to:
main.apply calls.apply
-------- @pointsto pointsto-pc -------- -------- @pointsto pointsto-pc --------
this *int may point to these objects: 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) Error: ambiguous selection within function call (or conversion)
-------- @callees callees-err-deadcode1 -------- -------- @callees callees-err-deadcode1 --------
this static function call dispatches to: this static function call dispatches to:
main.main calls.main
-------- @callees callees-err-nil-func -------- -------- @callees callees-err-nil-func --------
dynamic function call on nil value dynamic function call on nil value
@ -82,11 +82,11 @@ dynamic method call on nil value
-------- @callees callees-not-a-wrapper -------- -------- @callees callees-not-a-wrapper --------
this dynamic method call dispatches to: this dynamic method call dispatches to:
(main.myint).f (calls.myint).f
-------- @callees callees-static-call -------- -------- @callees callees-static-call --------
this static function call dispatches to: this static function call dispatches to:
main.foo calls.foo
-------- @callees callees-qualified-call -------- -------- @callees callees-qualified-call --------
this static function call dispatches to: this static function call dispatches to:
@ -94,32 +94,32 @@ this static function call dispatches to:
-------- @callees callees-static-method-call -------- -------- @callees callees-static-method-call --------
this static function call dispatches to: this static function call dispatches to:
(main.method).f (calls.method).f
-------- @callees callees-implicit-selection-method-call -------- -------- @callees callees-implicit-selection-method-call --------
this dynamic method call dispatches to: this dynamic method call dispatches to:
(main.method).f (calls.method).f
-------- @callers callers-not-a-wrapper -------- -------- @callers callers-not-a-wrapper --------
(main.myint).f is called from these 1 sites: (calls.myint).f is called from these 1 sites:
dynamic method call from main.main dynamic method call from calls.main
-------- @callees callees-err-deadcode2 -------- -------- @callees callees-err-deadcode2 --------
this static function call dispatches to: this static function call dispatches to:
main.main calls.main
-------- @callstack callstack-err-deadcode -------- -------- @callstack callstack-err-deadcode --------
main.deadcode is unreachable in this analysis scope calls.deadcode is unreachable in this analysis scope
-------- @callees callees-err-deadcode3 -------- -------- @callees callees-err-deadcode3 --------
Error: this call site is unreachable in this analysis Error: this call site is unreachable in this analysis
-------- @callers callers-global -------- -------- @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 the root of the call graph
-------- @callstack callstack-init -------- -------- @callstack callstack-init --------
Found a call path from root to main.init#1 Found a call path from root to calls.init#1
main.init#1 calls.init#1
static function call from main.init static function call from calls.init

View File

@ -274,18 +274,6 @@
"name": "lib.Type", "name": "lib.Type",
"pos": "testdata/src/lib/lib.go:3:6", "pos": "testdata/src/lib/lib.go:3:6",
"kind": "basic" "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": { "method": {
@ -296,16 +284,6 @@
{ {
"name": "method (lib.Type) Method(x *int) *int", "name": "method (lib.Type) Method(x *int) *int",
"pos": "testdata/src/lib/lib.go:5:13" "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"
} }
] ]
} }

View File

@ -34,6 +34,4 @@ concrete method func (sorter).Len() int
-------- @implements I.Method -------- -------- @implements I.Method --------
abstract method func (I).Method(*int) *int abstract method func (I).Method(*int) *int
is implemented by method (lib.Type).Method is implemented by method (lib.Type).Method
is implemented by method (main.I).Method
implements method (main.I).Method

View File

@ -41,6 +41,4 @@ slice type sorter
-------- @implements I -------- -------- @implements I --------
interface type I interface type I
is implemented by basic type lib.Type is implemented by basic type lib.Type
is implemented by interface type main.I
implements main.I

View File

@ -42,7 +42,7 @@ defined here
-------- @pointsto p -------- -------- @pointsto p --------
this *int may point to these objects: this *int may point to these objects:
main.a imports.a
-------- @describe ref-pkg -------- -------- @describe ref-pkg --------
reference to package "lib" reference to package "lib"

View File

@ -26,7 +26,7 @@ This channel of type chan *int may be:
-------- @pointsto pointsto-rA -------- -------- @pointsto pointsto-rA --------
this *int may point to these objects: this *int may point to these objects:
main.a2 peers.a2
a1 a1
-------- @peers peer-recv-chB -------- -------- @peers peer-recv-chB --------

View File

@ -3,33 +3,33 @@
Error: pointer analysis wants an expression of reference type; got untyped float Error: pointer analysis wants an expression of reference type; got untyped float
-------- @pointsto func-ref-main -------- -------- @pointsto func-ref-main --------
this func() may point to these objects: this func() may point to these objects:
main.main pointsto.main
-------- @pointsto func-ref-*C.f -------- -------- @pointsto func-ref-*C.f --------
this func() may point to these objects: this func() may point to these objects:
(*main.C).f (*pointsto.C).f
-------- @pointsto func-ref-D.f -------- -------- @pointsto func-ref-D.f --------
this func() may point to these objects: this func() may point to these objects:
(main.D).f (pointsto.D).f
-------- @pointsto func-ref-I.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 -------- -------- @pointsto func-ref-d.f --------
this func() may point to these objects: this func() may point to these objects:
(main.D).f (pointsto.D).f
-------- @pointsto func-ref-i.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 -------- -------- @pointsto ref-lexical-d.f --------
this func() may point to these objects: this func() may point to these objects:
(main.D).f (pointsto.D).f
-------- @pointsto ref-anon -------- -------- @pointsto ref-anon --------
this func() may point to these objects: this func() may point to these objects:
main.main$1 pointsto.main$1
-------- @pointsto ref-global -------- -------- @pointsto ref-global --------
this *string may point to these objects: this *string may point to these objects:

View File

@ -1,18 +1,18 @@
-------- @pointsto mrv -------- -------- @pointsto mrv --------
this reflect.Value may contain these dynamic types: this reflect.Value may contain these dynamic types:
*bool, may point to: *bool, may point to:
main.b reflection.b
*int, may point to: *int, may point to:
main.a reflection.a
map[*int]*bool, may point to: map[*int]*bool, may point to:
makemap makemap
-------- @pointsto p1 -------- -------- @pointsto p1 --------
this interface{} may contain these dynamic types: this interface{} may contain these dynamic types:
*bool, may point to: *bool, may point to:
main.b reflection.b
*int, may point to: *int, may point to:
main.a reflection.a
map[*int]*bool, may point to: map[*int]*bool, may point to:
makemap makemap
@ -23,7 +23,7 @@ this []reflect.Value may point to these objects:
-------- @pointsto p3 -------- -------- @pointsto p3 --------
this reflect.Value may contain these dynamic types: this reflect.Value may contain these dynamic types:
*int, may point to: *int, may point to:
main.a reflection.a
-------- @pointsto p4 -------- -------- @pointsto p4 --------
this reflect.Type may contain these dynamic types: this reflect.Type may contain these dynamic types: