diff options
author | Jay Conrod <jayconrod@google.com> | 2018-12-06 16:18:12 -0500 |
---|---|---|
committer | Jay Conrod <jayconrod@google.com> | 2018-12-10 21:47:06 +0000 |
commit | 89df035464e63ea7c90b981266e9a77a227c456b (patch) | |
tree | a6985a1368542487c437da71d48845c9e69e6a60 /src/cmd/go/testdata/script/mod_outside.txt | |
parent | 6182d0821c60e2ec4d85e94b5c8e476ca7f75fc6 (diff) | |
download | go-89df035464e63ea7c90b981266e9a77a227c456b.tar.gz go-89df035464e63ea7c90b981266e9a77a227c456b.zip |
cmd/go: fix errors for commands run outside of modules
Since CL 148517, several commands (including list and get) work when
GO111MODULE=on even when no go.mod file is present. This broke an
assumption made by "fix" and "generate" which caused panics when run
with a list of .go files (whether or not the command was run inside a
module).
This change fixes those assumptions and adds test cases for other
commands run outside modules.
Fixes #29097
Change-Id: I7927559769c5d4617d73eb63f3b17e2f26d8c219
Reviewed-on: https://go-review.googlesource.com/c/153158
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Diffstat (limited to 'src/cmd/go/testdata/script/mod_outside.txt')
-rw-r--r-- | src/cmd/go/testdata/script/mod_outside.txt | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/cmd/go/testdata/script/mod_outside.txt b/src/cmd/go/testdata/script/mod_outside.txt index cc99ed6b00..25013b6271 100644 --- a/src/cmd/go/testdata/script/mod_outside.txt +++ b/src/cmd/go/testdata/script/mod_outside.txt @@ -36,6 +36,9 @@ stdout '^cmd/go$' go list $GOROOT/src/fmt stdout '^fmt$' +# 'go list' should work with file arguments. +go list ./foo/foo.go +stdout 'command-line-arguments' # 'go list -m' with an explicit version should resolve that version. go list -m example.com/version@latest @@ -186,11 +189,27 @@ stdout 'path is \.$' stdout 'main is main \(devel\)' stdout 'using example.com/version v1.1.0' +# 'go generate' should work with file arguments. +[exec:touch] go generate ./foo/foo.go +[exec:touch] exists ./foo/gen.txt + +# 'go install' should work with file arguments. +go install ./foo/foo.go + +# 'go test' should work with file arguments. +go test -v ./foo/foo_test.go +stdout 'foo was tested' + +# 'go vet' should work with file arguments. +go vet ./foo/foo.go + -- README.txt -- There is no go.mod file in the working directory. -- foo/foo.go -- +//go:generate touch gen.txt + package main import ( @@ -212,3 +231,15 @@ func main() { fmt.Fprintf(os.Stdout, "using %s %s\n", m.Path, m.Version) } } + +-- foo/foo_test.go -- +package main + +import ( + "fmt" + "testing" +) + +func TestFoo(t *testing.T) { + fmt.Println("foo was tested") +} |