cmd/guru: always import tests in initial referrers import

If test files are not included here,
then results in those files will be missing
for queries within a single package.

This work supported by Sourcegraph.

Change-Id: I8136ea250ba980179228d9b408d9e7409c49a873
Reviewed-on: https://go-review.googlesource.com/97799
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:
Josh Bleecher Snyder 2018-04-23 09:31:51 -07:00
parent 7e5e8df4df
commit 71f44073ef
4 changed files with 14 additions and 0 deletions

View File

@ -34,6 +34,12 @@ func referrers(q *Query) error {
return err return err
} }
// Load tests of the query package
// even if the query location is not in the tests.
for path := range lconf.ImportPkgs {
lconf.ImportPkgs[path] = true
}
// Load/parse/type-check the query package. // Load/parse/type-check the query package.
lprog, err := lconf.Load() lprog, err := lconf.Load()
if err != nil { if err != nil {

View File

@ -5,4 +5,6 @@ import "lib"
func _() { func _() {
// This reference should be found by the ref-method query. // This reference should be found by the ref-method query.
_ = (lib.Type).Method // ref from internal test package _ = (lib.Type).Method // ref from internal test package
_ = notexported
} }

View File

@ -25,6 +25,8 @@ func main() {
s2.f = 1 s2.f = 1
} }
var notexported int // @referrers unexported-from-test "notexported"
// Test //line directives: // Test //line directives:
type U int // @referrers ref-type-U "U" type U int // @referrers ref-type-U "U"

View File

@ -54,6 +54,10 @@ references to field f int
_ = s{}.f // @referrers ref-field "f" _ = s{}.f // @referrers ref-field "f"
s2.f = 1 s2.f = 1
-------- @referrers unexported-from-test --------
references to var notexported int
_ = notexported
-------- @referrers ref-type-U -------- -------- @referrers ref-type-U --------
references to type U int references to type U int
open nosuchfile.y: no such file or directory (+ 1 more refs in this file) open nosuchfile.y: no such file or directory (+ 1 more refs in this file)