1
0
mirror of https://github.com/golang/go synced 2024-10-01 01:38:33 -06:00
Commit Graph

10 Commits

Author SHA1 Message Date
Alan Donovan
8e53eb937b go/ssa: support custom TestMain functions in test packages
Supporting user-defined TestMain functions requires that we generate a
"testmain" package for each testable package, rather than a single one
for the entire program.  This entails these API changes:

1. (*ssa.Program).{CreateTestMainPackage,FindTests} both now
   accept only a single package.  Existing clients that pass them
   multiple packages must call them from a loop.

2. (*ssa.Program).FindTests returns an additional result, the the
   optional TestMain *ssa.Function.  Existing clients may discard it.

Also:
- Test the new logic using the SSA interpreter
- add ssautil.MainPackages helper
- callgraph: allow multiple main packages, and analyze them all
- ssadump -run: allow multiple main/test packages, and run each in a new interpreter
- minor simplifications to some callers (e.g. guru)

Fixes golang/go#9553

Change-Id: Ia7de9bd27448fb08b8d172ba5cdbcf37a762b7a0
Reviewed-on: https://go-review.googlesource.com/25102
Reviewed-by: Robert Griesemer <gri@golang.org>
2016-10-19 17:50:59 +00:00
Alan Donovan
27f88d9b7a cmd/guru: if query file is not beneath GOPATH, treat it as a package
This allows type-based guru queries to work on arbitrary files at the
root or even outside of a GOPATH workspace (as "go run foo.go" does).

Fixes golang/go#15797

Change-Id: I2be28f7259448e6398aae84d6ae7e71d8649967a
Reviewed-on: https://go-review.googlesource.com/30451
Reviewed-by: Robert Griesemer <gri@golang.org>
2016-10-05 18:29:27 +00:00
Alan Donovan
2da0720e4f cmd/guru: support streaming plain and -json output
Visible changes:
- "referrers" queries now emit a stream of results,
  so they start appearing quickly even in large queries.
  We no longer report the total number of matches.
- packageReferrers now also uses AfterTypeCheck hook and streaming.
- XML support has been dropped.
- The -format flag has been replaced by -json.

JSON protocol changes:
- The enclosing Result struct has been removed.
- Likewise the 'mode' field (since the caller knows it already)
- "freevars" and "referrers" now emit a stream of objects
  In the case of referrers, the first object has a different from the rest.
- The "referrers" results include the text of the matching line
  (parity with -json=false)

Implementation details:
- the concurrency-safe q.Output function can be called
  many times, each with a queryResult to print.
- fset is no longer saved in Query (cleaner)
- queryResult methods renamed PrintPlain, JSON

Change-Id: I41a4e3f57f266fcf043ece4045bca82c6f6a356f
Reviewed-on: https://go-review.googlesource.com/21397
Reviewed-by: Michael Matloob <matloob@golang.org>
2016-04-11 19:51:55 +00:00
Alan Donovan
6c84e9e3e0 cmd/guru: make fastQueryPos indirect through the -modified map
This fixes a bug in which guru reports a "query position beyond end of
file" error when making a query from an unsaved editor buffer at an
offset greater than the length of the file on disk.

Change-Id: I908c024d8dd14baa657b4227e3231fa760443732
Reviewed-on: https://go-review.googlesource.com/20167
Reviewed-by: Daniel Morsing <daniel.morsing@gmail.com>
2016-03-03 19:00:43 +00:00
Alan Donovan
3f95c66345 cmd/guru: allow foo/... and -foo patterns in scope argument
Also, document -scope argument.

Depends on CL 19746 (buildutil.ExpandPatterns)

Change-Id: I3c9000e94d87cca5c2c49fe8de12a77fc43f7257
Reviewed-on: https://go-review.googlesource.com/19747
Reviewed-by: Daniel Morsing <daniel.morsing@gmail.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
2016-02-22 20:17:58 +00:00
Alan Donovan
fb3df4a89d cmd/guru: definition: try parser-based resolution first
The parser does intra-file resolution.  It's only a best-effort but
it's extremely fast, so we try it first and fall back to the loader-based
implementation if it fails.

Also:
- factor definitionResult so it doesn't depend on either go/types.Object
  or go/ast.Object.
- guessImportPath: make importPath=="" result an error,
  since you can't import the empty string.  Simplify importQueryPackage.
- Make fastQueryPos continue in face of minor parse errors.
- describe: eliminate old TODO; suppress log statement.

Change-Id: I30a32487e9fd9d5308b1580ec12220cad2c16299
Reviewed-on: https://go-review.googlesource.com/19507
Reviewed-by: Daniel Morsing <daniel.morsing@gmail.com>
2016-02-16 00:29:23 +00:00
Alan Donovan
e08a7ae6bc cmd/guru: add support for loading modified files
The -modified flag causes guru to read a simple archive file from stdin.
This archive specifies alternative contents for one or more file names.
The build.Context checks this table before delegating to the usual
behavior.

This will not work for files that import "C" since cgo accesses the
file system directly.

Added end-to-end test via Emacs.

Simplify findQueryPos (now: fileOffsetToPos)

Credit: Daniel Morsing, for the prototype of this feature.

Change-Id: I5ae818ed5e8bb81001781893dded2d085e9cf8d6
Reviewed-on: https://go-review.googlesource.com/19498
Reviewed-by: Daniel Morsing <daniel.morsing@gmail.com>
2016-02-15 15:04:13 +00:00
Alan Donovan
1d6b8698af cmd/guru: remove vestiges of -pos flag
It's a positional parameter now.

Also, update -help message to address
https://go-review.googlesource.com/#/c/19474 comments

Change-Id: Ie5947aa3c37180961e780747ca02be54f7030c21
Reviewed-on: https://go-review.googlesource.com/19493
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-02-12 22:00:14 +00:00
Alan Donovan
37bb37ec1c cmd/guru: fix bad import, and run gofmt
Change-Id: Ieb5c732bad494942f7b45ac5a1b605e810436e87
Reviewed-on: https://go-review.googlesource.com/19478
Reviewed-by: Alan Donovan <adonovan@google.com>
2016-02-12 03:58:01 +00:00
Alan Donovan
7347379304 cmd/guru: rename oracle to guru, copying it to a single package
See plans at:
https://docs.google.com/document/d/1UErU12vR7jTedYvKHVNRzGPmXqdMASZ6PfE7B-p6sIg/edit#heading=h.t5rbcuy7di7j

Change-Id: I369747e0ce8cd42a2975eb0f651a2e5fba47cf9e
Reviewed-on: https://go-review.googlesource.com/19475
Reviewed-by: Alan Donovan <adonovan@google.com>
2016-02-12 03:38:58 +00:00