1
0
mirror of https://github.com/golang/go synced 2024-10-02 08:28:36 -06:00
Commit Graph

3416 Commits

Author SHA1 Message Date
Michael Matloob
680468b755 go/packages: fix flaky TestJSON and reenable it on Go 1.10
The fallback driver wasn't returning the roots in a
deterministic order because it was using sticking them in
a map and then iterating over that map to get each element.
Put them into a slice instead (and make a few small
associated changes) to preserve behavior.

Fixes golang/go#28040
Fixes golang/go#28609

Change-Id: Ib8f8c88d65b7a48b2b04ca91e2d3c316d5bb5803
Reviewed-on: https://go-review.googlesource.com/c/148880
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-11-12 16:24:42 +00:00
Diogo Pinela
6d71ab8aad go/internal/gcimporter: ensure tests pass even if GOROOT is read-only
This mainly entails writing compiler output files to a temporary
directory, as well as the corrupted files in TestVersionHandling.

This is a backport of CL 146119.

Fixes golang/go#28644

Change-Id: I5701fe3fda7d6364411eef8265c575c279dbf9a1
Reviewed-on: https://go-review.googlesource.com/c/149017
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2018-11-11 00:37:25 +00:00
Alan Donovan
92d8274bd7 go/analysis/passes/printf: preload with facts for std lib
This change adds to the list of standard library functions known to be
print or printf wrappers.

Although the printf Analyzer is capable of identifying wrapper
functions in the standard library, some drivers (e.g. Bazel) do not
apply analyzers to the standard packages. Really this is a  bug
in those drivers but it is not likely to be fixed for a while.

Change-Id: I2032d0cb5fcb50e7b9933a75809becdd680380ec
Reviewed-on: https://go-review.googlesource.com/c/148572
Run-TryBot: Alan Donovan <adonovan@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
2018-11-09 20:29:20 +00:00
Alan Donovan
a00bb74625 go/analysis/cmd/vet-lite: make CLI closer to cmd/vet
Details:
- Add -source, -v, and -all flags to vet-lite.
  These have no effect and issue a warning.
- Add usage message to vet-lite that lists all
  analyzers and explains -foo.enable and other flags.
- Factor this help message (common to vet-lite and
  multichecker) into analysisflags.
- Add legacy aliases of new flags.
  e.g. -printfuncs is now -printf.funcs
  The old names work but issue a warning when used.

Also: update comments to say -vettool not$GOVETTOOL

I think we should probably do away with singlechecker
in a follow-up: a singleton multichecker is good enough,
and will allow us to remove cases in the flag-processing
logic.

Change-Id: Ib62f16b5e2f4c382a29e6300a6246b2db9e08049
Reviewed-on: https://go-review.googlesource.com/c/148559
Reviewed-by: Michael Matloob <matloob@golang.org>
2018-11-09 19:31:51 +00:00
Alan Donovan
4e34152f16 cmd/vet: lostcancel: suppress the check in the main.main function
When main.main returns, the process exits, so there's no need to cancel contexts.

This CL was originally reviewed as
  https://go-review.googlesource.com/c/go/+/106915
and then retried in
  https://go-review.googlesource.com/c/go/+/148758
but then reverted due to an embarrassing sequence
of careless moves.

Change-Id: Icdee0650996a442023e030697f10d2c31fd5fdff
Reviewed-on: https://go-review.googlesource.com/c/148877
Run-TryBot: Alan Donovan <adonovan@google.com>
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
2018-11-09 18:25:37 +00:00
Daniel Martí
d3a25d70bd go/packages: fix minor godoc typo
Spotted while reading some docs.

Change-Id: I856c73b55f459fd980591ba5525d5170d035d79c
Reviewed-on: https://go-review.googlesource.com/c/148797
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-11-09 17:23:37 +00:00
Michael Stapelberg
138c20b932 go/callgraph/rta: fix comment
Change-Id: I52d37297118f9e99f3a71d3a9cf47a01da4aa72c
Reviewed-on: https://go-review.googlesource.com/c/38260
Reviewed-by: Alan Donovan <adonovan@google.com>
2018-11-09 15:26:31 +00:00
Nicholas Ng
8542fc29bd go/ssa: updated inconsistent docs after Program.Method rename
Fixes golang/go#20225

Change-Id: Ifd069546698981f3c6a3673dd73a1bd770560f8b
Reviewed-on: https://go-review.googlesource.com/c/42570
Reviewed-by: Alan Donovan <adonovan@google.com>
2018-11-09 15:25:51 +00:00
matematik7
84d77ece31 cmd/bundle: permit empty -prefix
This enables bundling of programs with `main` method to single file.
I used this to upload code for the new codejam.

Change-Id: I9e65ba8717c1d81d6fb9bef8f234c21fc5b91421
GitHub-Last-Rev: 5d0d623c46ff1629e7371693ddf0916df328e319
GitHub-Pull-Request: golang/tools#32
Reviewed-on: https://go-review.googlesource.com/c/105515
Reviewed-by: Alan Donovan <adonovan@google.com>
2018-11-09 15:23:16 +00:00
Alan Donovan
879803d4ad go/analysis/passes/unmarshal: port vet's unmarshal checker
The checker has been modified to avoid making two memory allocations
for every CallExpr in the program.

Originally: https://go-review.googlesource.com/c/139997
Updates golang/go#27564

Change-Id: I168869272a1d78d47d84c049aba619bb223cad70
Reviewed-on: https://go-review.googlesource.com/c/148562
Reviewed-by: Michael Matloob <matloob@golang.org>
2018-11-09 14:28:11 +00:00
Alan Donovan
77439c5518 go/analysis/passes/shadow: add shadow command
In vet, the shadow check is experimental, meaning not on by default.
The new analysis API has no concept of experimental, but you can
easily supply a different checker. By providing a shadow command, we
make it easy for users that want it to run it:

  $ go install golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow
  $ go vet -vettool $(which shadow) my/project

Change-Id: I25dc7f3c830296121c7217e4615e8ff90e1b7c79
Reviewed-on: https://go-review.googlesource.com/c/148565
Reviewed-by: Michael Matloob <matloob@golang.org>
2018-11-08 22:19:41 +00:00
Fazlul Shahriar
5b8b0ce6cc go/packages: pass TestConfigDefaultEnv on Plan 9
Change-Id: Ice0d44c97dc76bf0ebfe433577d55eb6763cb6d3
Reviewed-on: https://go-review.googlesource.com/c/132601
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-11-08 22:19:39 +00:00
Alan Donovan
fc0741f0ff go/analysis/printf: delete
The printf checker is in the passes/ subdirectory.

Change-Id: I0a912231280bc954fee3088050541ba5ecb17dde
Reviewed-on: https://go-review.googlesource.com/c/148571
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
2018-11-08 21:04:34 +00:00
Alan Donovan
353f99afd4 go/analysis/passes/cgocall: fix typo in comment
Change-Id: Ie71f93c1fa0d5e7de498ad2af611c4db8a27171d
Reviewed-on: https://go-review.googlesource.com/c/148561
Reviewed-by: Michael Matloob <matloob@golang.org>
2018-11-08 19:46:55 +00:00
Alan Donovan
e5d4b58ff5 go/analysis/passes/cgocall: analyze raw cgo files (again)
The cgocall analyzer was originally written in vet to analyze "raw" cgo files,
which are type-checked on a best-effort basis.  However, the go/analysis
API presents analyzers with "cooked" cgo files, which are well-typed
legal Go but obscure the relationship between a call C.f(...) and its arguments.
Prior to this CL, cgocall attempted to "uncook" the file, which was
as predictably fragile as it sounds, and it rapidly broke as the cgo
recipe evolved.

This change causes cgocall to parse, modify, type-check and analyze "raw"
cgo files. The approach (based on dot-importing the "cooked" package)
is rather too clever but should be more robust than the one it replaces.

Fixes golang/go#28566

Change-Id: I3092a313c64d27153eaaa115fe8635abfed17023
Reviewed-on: https://go-review.googlesource.com/c/147317
Reviewed-by: Michael Matloob <matloob@golang.org>
2018-11-08 19:39:40 +00:00
Brad Fitzpatrick
dfbbb7b6d4 go/packages, go/analysis/internal/unitchecker: skip broken tests for now
Updates golang/go#28609
Updates golang/go#28676

Change-Id: Id0fbc6cb0ce14aed9b20afcd0488708df33d5a62
Reviewed-on: https://go-review.googlesource.com/c/148637
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-11-08 18:34:11 +00:00
Rebecca Stambler
c26e340d2f internal/lsp: refactor completion and move into source directory
The completion function belongs in internal/lsp/source, so move it
there. Some small refactoring of completion, by moving each type of
completion into helper functions that append to the list of results.

Change-Id: I8599092906609591d499183657fe2d21d1f74df1
Reviewed-on: https://go-review.googlesource.com/c/148397
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-11-08 16:15:53 +00:00
Heschi Kreinick
a28dfb48e0 revert "imports: create named imports for name/path mismatches"
This reverts CL 145699 (commit 864069cfd1)

Reason for revert: If the mismatch is bad enough that goimports can't find
it again, then the import is just removed, even if the user adds it back again.

Fixes #28645.

Change-Id: I6c8fc5434c2b56c73b260bcec2c12d8746fac4ad
Reviewed-on: https://go-review.googlesource.com/c/148237
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-11-07 22:50:58 +00:00
Dmitri Shuralyov
4ca49954c3 go/ast/astutil: allow AddNamedImport to add imports with different names
This change makes AddNamedImport more symmetrical to DeleteNamedImport
in behavior, signature, and documentation.

In Go, it is valid to import a package (identified by an import path)
with different names in a single .go file¹. For example, this is ok,
and the program will build as long as there are no unused imports²:

	import (
		"path"
		. "path"
		_ "path"
		pathpkg "path"
	)

The four imports (represented by ast.ImportSpec type) have the same
import path, but different names.

It's currently possible to use DeleteNamedImport to delete the exact
{name, import path} ast.ImportSpec from an AST.

Previously, it wasn't possible to use AddNamedImport to add an exact
{name, import path} ast.ImportSpec if the AST already has another
ast.ImportSpec with the same import path (but different name).
This change fixes that, making it possible to use AddNamedImport as
expected.

Rename the ipath parameter to path in AddNamedImport for consistency
with DeleteNamedImport. Also change the language used in its
documentation to be more precise and consistent with DeleteNamedImport.

Add test cases for this behavior. The DeleteNamedImport test cases
were passing before any changes to the astutil code.

Add test coverage for the return bool value of {Add,Delete}NamedImport.
Document the behavior of DeleteNamedImport when there are duplicate
matching imports.

Simplify string(buf.Bytes()) to buf.String() in test helper code.

¹ https://golang.org/ref/spec#Import_declarations
² https://play.golang.org/p/bi6L34rQbcD

Fixes golang/go#28605
Fixes golang/go#16411

Change-Id: I70e887f5174764ab1cf32a761c8c734e216eea67
Reviewed-on: https://go-review.googlesource.com/c/147448
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
2018-11-07 22:33:19 +00:00
Michael Matloob
34b416bd17 go/packages: change the driverResponse.Sizes to have type StdSizes
This will allow Sizes to be marshalled and unmarshalled. All the Sizes
we care about ane StdSizes anyways.

Change-Id: I79d1dcaebba32f7730de4375945e372eeefa78fe
Reviewed-on: https://go-review.googlesource.com/c/147978
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
2018-11-07 21:56:32 +00:00
Heschi Kreinick
42c3d2e9aa internal/gopathwalk: ignore $GOROOT/.../vendor/ in module mode
go list in module mode doesn't like looking at vendor directories in
GOROOT. Skip them.

Change-Id: Iec501fbab70914ea6dd76dcbed97ecda461358d0
Reviewed-on: https://go-review.googlesource.com/c/148159
Run-TryBot: Heschi Kreinick <heschi@google.com>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2018-11-07 20:51:50 +00:00
Heschi Kreinick
864069cfd1 imports: create named imports for name/path mismatches
For clarity and performance reasons, we want the fast path of goimports
to be purely syntactic. Packages whose import paths don't match their
package names make this harder. Before this CL, we parsed each imported
package to get its real package name. Now, we make named imports for
such packages, and on subsequent runs we don't have to do the extra
work.

A package name matches its import path if the name is the last segment
of the path, or the next-to-last before a version suffix vNN. gopkg.in
style .vNN suffixes are considered mismatching.

goimports already had almost exactly the desired logic, but only when
adding a new import. So the bulk of this change is simply removing the
logic that allowed it to recognize that a mismatched import satisfied
some uses. With that gone, it will remove those imports as unused, then
add a new renamed import. Some comments may be destroyed.

Fixes golang/go#28428

Change-Id: I53846e6046affb420f41719f84c71086c5b9e5e6
Reviewed-on: https://go-review.googlesource.com/c/145699
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-11-07 19:53:05 +00:00
Ian Cottrell
15ad1aa0cb internal/lsp: implement go to definition
This enables go to definition for the lsp.
It has one known non working case (where the filenames have $GOROOT in them)

Change-Id: I142c6e04b8691c5076dfcd55592ea710b4b361a4
Reviewed-on: https://go-review.googlesource.com/c/148158
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2018-11-07 18:43:41 +00:00
Ian Cottrell
d0600fd9f1 internal/lsp: make source independent of protocol
I realized this was a mistake, we should try to keep the source
directory independent of the LSP protocol itself, and adapt in
the outer layer.
This will keep us honest about capabilities, let us add the
caching and conversion layers easily, and also allow for a future
where we expose the source directory as a supported API for other
tools.
The outer lsp package then becomes the adapter from the core
features to the specifics of the LSP protocol.

Change-Id: I68fd089f1b9f2fd38decc1cbc13c6f0f86157b94
Reviewed-on: https://go-review.googlesource.com/c/148157
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2018-11-07 18:42:35 +00:00
Michael Matloob
aa0cdd1ef5 go/packages: remove contains: query. it's been superceeded by file=
Change-Id: I472787d50e799ef0ee663168201933dd70a1a487
Reviewed-on: https://go-review.googlesource.com/c/147977
Reviewed-by: Alan Donovan <adonovan@google.com>
2018-11-07 16:12:02 +00:00
Michael Matloob
e21233ffa6 go/packages: remove unnecessary TODO
See adonovan's comment here:
https://go-review.googlesource.com/c/tools/+/146757/6/go/packages/golist.go#330

Change-Id: I7885fc1e7787c6b265be345f8622476b69d14325
Reviewed-on: https://go-review.googlesource.com/c/147447
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2018-11-06 21:36:28 +00:00
Rebecca Stambler
6f4a86804e internal/lsp: add implementation of completion to LSP
Add an autocompletion implementation to the LSP. Also, add a function
that type-checks a package at a certain position, returning an *ast.File
and token.Pos for querying completion.

Change-Id: I288d4e6ed168e6014e79a4436f31f5b4a99b7139
Reviewed-on: https://go-review.googlesource.com/c/147657
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2018-11-06 21:04:51 +00:00
Michael Matloob
78dc5bac0c go/packages: determine sizes by calling go list
This is more reliable than looking in the environment.

Change-Id: I96c093b89faaece6b6256eefb4a4aac4d66b9cc9
Reviewed-on: https://go-review.googlesource.com/c/146757
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
2018-11-05 23:00:42 +00:00
Ian Cottrell
e504f914a8 internal/lsp: make file a first class concept
A file is strongly associated with a view, and knows how to manage it's own
contents.
We can also now track files that are not "active"

Change-Id: Ib9474cd40e5caa3db6596548612a9f90168b8a19
Reviewed-on: https://go-review.googlesource.com/c/147204
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2018-11-05 21:38:40 +00:00
Ian Cottrell
9b5bafe36f internal/lsp: extract view to its own package
This allows us to write the lsp verbs in terms of a stable underlying source
management layer.
This should make it easier to refactor the underlying layer to add more powerful
caching and incremental modes as we go.

Change-Id: Iab97b061d80394a6fa6748a93a4c68f2deb46129
Reviewed-on: https://go-review.googlesource.com/c/147201
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2018-11-05 21:38:13 +00:00
Ainar Garipov
f1b4bd93c9 go/ssa: fix vet issues
The new go/analysis/cmd/vet tool found a few issues. Fix them by
explicitly ignoring results where needed and renaming examples in
accordance to package testing's guidelines to make them appear on the
godoc pages.

This change doesn't touch go/ssa/interp/external.go because the
possible misuse of package unsafe there looks intentional.

Change-Id: Id63109e3797818a5e869fe8ed1bc1476959541f2
Reviewed-on: https://go-review.googlesource.com/c/147297
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
2018-11-05 21:34:10 +00:00
Ian Cottrell
fc67db3d9a go/packages: fix crash
This is based on 147340 and has the same test, but with a different fix.
We now produce a nice error if there is an empty root, instead of
crashing, and the cause of empty roots in go list has been fixed.
The underlying call to go list is returning the same package more than
once, and we only fix the first entry in the root list, so the second
one got left blank.
The fix was to not add the second duplicate copy to the output of the
driver at all.

Change-Id: I9f1b2f0fd63635ba101cdd3c8a5108530e968ba9
Reviewed-on: https://go-review.googlesource.com/c/147440
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
2018-11-05 21:21:22 +00:00
Rebecca Stambler
c76e1ad98a internal/lsp: add copyright notices to files that were missing them
Change-Id: Ifb3bedeed7a38366da234b2329c4078931d1a208
Reviewed-on: https://go-review.googlesource.com/c/147441
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2018-11-05 19:56:57 +00:00
Rebecca Stambler
ebdbadb46e internal/lsp: fix LSP tests to be compatible with Go 1.10
Change golang/go#145697 added tests for diagnostics in the LSP implementation,
but these test did not work with Go 1.10. This change skips tests that
require Go 1.11.

Change-Id: I52bd2df484b5786395edac2c1c8592c83ac1aaa4
Reviewed-on: https://go-review.googlesource.com/c/147439
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2018-11-05 19:42:43 +00:00
Ian Cottrell
96e9e165b7 cmd/golsp: format logging for the lsp inspector
This improves the logging capabilities of the jsonrpc 2 library to always
include the method and also an optional elapsed time.
This is used to implement an lsp inspector compatible logging mode in the golsp.

Change-Id: I2f7ac8b9298c4364b1b89cf6f696b534557ed139
Reviewed-on: https://go-review.googlesource.com/c/146157
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2018-11-02 22:32:51 +00:00
Heschi Kreinick
1a6034dbfc go/packages: small fixes
For performance, bail out of runNamedQueries before running go env if
there's nothing to do.

Add t.Helper() calls to packagestest.TestAll.

Escape # in packagestest.Export. The testing package adds #NN suffixes
to subtests that have redundant names.

Log how long gopathwalk.Walk took for name= queries when debug is on.

Change-Id: I37cb0ed11cf58e1693e29dea04697e5885ecc62b
Reviewed-on: https://go-review.googlesource.com/c/147203
Run-TryBot: Heschi Kreinick <heschi@google.com>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2018-11-02 22:11:10 +00:00
Rebecca Stambler
f7a8a58e8d internal/lsp: use packagestest markers to test diagnostics
Add some basic tests for diagnostics using the new
go/packages/packagestest framework.

Change-Id: I6a7bfba6c392928a9eb123ab71ceb73785c12600
Reviewed-on: https://go-review.googlesource.com/c/145697
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2018-11-02 21:57:01 +00:00
Heschi Kreinick
633a9364ed go/packages: disable network, improve debug logging
When the name= query constructs the temporary module, it may find things
that don't resolve. In at least some cases (#28518), allowing go list
to access the network results in not just bad performance but actual
failures. Default GOPROXY to "off" when doing queries on the temporary
module to try to address that.

Also, add some more debug logging, including various environment
variables, so that it's easier to reproduce failing commands.

Change-Id: I1a6d3ffa5c845271ce48e9fe802a2491ccadcd7c
Reviewed-on: https://go-review.googlesource.com/c/146477
Run-TryBot: Heschi Kreinick <heschi@google.com>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2018-11-02 21:01:51 +00:00
Alan Donovan
c3ef14e642 go/analysis/passes/cgocall: disable test in go1.12
The test correctly identified a problem.
Suppressing test to keep dashboard cleean, pending a fix.

Updates golang/go#28566

Change-Id: Ib3a8dbdd617c9f5701b5d6673434917d284dfb32
Reviewed-on: https://go-review.googlesource.com/c/147199
Run-TryBot: Alan Donovan <adonovan@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
2018-11-02 19:56:55 +00:00
Alan Donovan
896f44f055 go/analysis/.../unitchecker: suppress test unless go1.12
Change-Id: I1af89b9e077cf7eddeeeed72e66cd88f650492a2
Reviewed-on: https://go-review.googlesource.com/c/147197
Reviewed-by: Michael Matloob <matloob@golang.org>
Run-TryBot: Michael Matloob <matloob@golang.org>
2018-11-02 19:17:09 +00:00
Ian Cottrell
619897c5a2 go/packages/packagestest: add marker support
This adds a library that allows markers and actions inside comments in go source
files.
It then also adds an easy way to use that library for tests using packagestest.Expect
This is used to easily write code inspection and manipulation tests in a
language that is common to all tests.

Change-Id: I755caaad1557c9b8779ad9ecda2b3309550d6976
Reviewed-on: https://go-review.googlesource.com/c/142998
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
2018-11-02 18:21:53 +00:00
Alan Donovan
15a0f8a7f1 go/analysis/internal/unitchecker: a 'go vet'-compatible driver
Also:
- add cmd/vet-lite, a version of cmd/vet that doesn't depend on
  go/packages and must be run under "go vet". This will be vendored
  into $GOROOT/src/cmd/vet.
- add an integration test for a unitchecker-based command under "go vet".

Change-Id: Id613dac2812816c6d6372fa6d1536c8d4e4c2676
Reviewed-on: https://go-review.googlesource.com/c/143418
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
2018-11-02 17:49:05 +00:00
Agniva De Sarker
92b943e6bf cmd/tip: enable playground on tip.golang.org
Updates golang/go#28536

Change-Id: I3ece72aacd4635f4580be404672394a47791a1e8
Reviewed-on: https://go-review.googlesource.com/c/146917
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-11-02 05:00:50 +00:00
Ian Cottrell
d51e88b5ae go/packages: make visit order stable
Change-Id: Iee9b29364dd986e1f1676ff0aa989267c4149c30
Reviewed-on: https://go-review.googlesource.com/c/146357
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
2018-11-02 02:37:01 +00:00
David Symonds
45ff765b48 cmd/stringer: accept simple type conversion expressions in constant ValueSpec
This permits constants of the form `const X = T(A)` to add `X` to the
stringer output for type `T`.

While those constants can be rewritten as `const X T = T(A)`, that
becomes tedious and visually noisy when `T` is a long name. It is quite
easy to address this easy and common case, while not attempting to solve
this with full generality.

Fixes #11581.

Change-Id: Ifb8e43515f05493de190e02577260d94dd851581
Reviewed-on: https://go-review.googlesource.com/c/146577
Run-TryBot: David Symonds <dsymonds@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
2018-11-01 07:19:27 +00:00
Ian Cottrell
3a10b9bf0a go/packages: change so no results are sorted
We do insist that drivers are stable (not sorted, just stable) and that
refine is also stable, which allows us to promise a stable output.
I also changed refine so it returns the root set in the same order that
the original root id list was supplied, as this seems to be a strictly
better experience.

Change-Id: I8eb0bffd7547865d14a6c6f18646018b9af140bd
Reviewed-on: https://go-review.googlesource.com/c/145877
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
2018-10-31 16:53:50 +00:00
Heschi Kreinick
6c7e314b65 go/packages/packagestest: make versioned modules
If a Module's Name ends with a version suffix (v2), create its module
with an appropriate version number (v2.0.0).

Change-Id: I1a16f054fac5717e79871ba1bf9a6343c0ce2f5b
Reviewed-on: https://go-review.googlesource.com/c/146097
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2018-10-30 22:17:26 +00:00
Paul Jolly
240a8bfde1 cmd/stringer: move away from using os.Args[0]
stringer's usage currently uses os.Args[0] to refer to the program name
as a defensive measure in case stringer is compiled and then run using a
name other than stringer, e.g. mystringer. However, the following lines
of the usage docs hardcode "stringer." So it seems this has little
benefit.

Indeed this style of using os.Args[0] can make the usage information of
stringer extremely ugly when stringer itself is invoked with an absolute
path:

Usage of /tmp/tmp.ahddh3ZjE7/.gobincache/golang.org/x/tools/@v/v0.0.0-20181030000716-a0a13e073c7b/golang.org/x/tools/cmd/stringer/stringer:
        stringer [flags] -type T [directory]
        stringer [flags] -type T files... # Must be a single package

...

Instead, opt for the simpler approach of hardcoding stringer throughout.

Change-Id: Ia296c8d9a91c94e77b7cc2b6242908c959fb5985
Reviewed-on: https://go-review.googlesource.com/c/145799
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Alan Donovan <adonovan@google.com>
Reviewed-by: Rob Pike <r@golang.org>
2018-10-30 21:27:03 +00:00
Ian Cottrell
bb28844c46 go/packages: make packagestest.Export call t.Helper
Change-Id: Ib95ab480899ee14fb8ae841b0210734ecbc0d0d9
Reviewed-on: https://go-review.googlesource.com/c/145698
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
2018-10-30 15:17:51 +00:00
Heschi Kreinick
a0a13e073c imports: make tests compatible with modules
Tweak the goimports tests to be more module-compatible. This should be
the last big change to the tests; they all pass with the new
implementation.

The primary change is to avoid using packages not provided by the test's
modules. Other modules will be downloaded at test time, which is
nonhermetic and quite slow.

Other miscellanea:

- The appengine grouping tests have to be split out so
they can be GOPATH-only, because modules have to have dots in their
names.
- The tests for .goimportsignore and node_modules are GOPATH-only
because we decided not to include those behaviors in go/packages in
module mode.
- Some vendoring tests are GOPATH-only because vendoring is not a thing
in module mode.
- TestFindImportInLocalGoFiles changes content, because the existing
test was incorrect: bogus.net/bytes was a viable candidate even though
it isn't on disk. I'm not sure why it wasn't flaky.

Change-Id: I35a3aac92d3fb7f70a1a8f027f0b423282420a4d
Reviewed-on: https://go-review.googlesource.com/c/145138
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-10-30 00:07:16 +00:00