diff options
author | Bryan C. Mills <bcmills@google.com> | 2018-12-10 15:02:38 -0500 |
---|---|---|
committer | Bryan C. Mills <bcmills@google.com> | 2018-12-11 21:45:00 +0000 |
commit | cee9dfc39bef7b53ffa4ee584ec7fdec03c95a5a (patch) | |
tree | 90a01e40cba0b4b45cf567a75cc7f8f73c6abfd3 /src/cmd/go/testdata/script/mod_outside.txt | |
parent | 353ebe721019ac833646bea829d7840e55f3da30 (diff) | |
download | go-cee9dfc39bef7b53ffa4ee584ec7fdec03c95a5a.tar.gz go-cee9dfc39bef7b53ffa4ee584ec7fdec03c95a5a.zip |
cmd/go: fix 'go test' and 'go fmt' with files outside a module
Use the actual loader result in findModule instead of making
assumptions about nesting in the build list.
As a side-effect, this produces much clearer error messages for
packages that (for one reason or another) failed to load.
Adjust the package and module path outside a module to
"command-line-arguments". That string already appears in the output of
a number of (module-mode and GOPATH-mode) commands for file arguments,
and as far as I can tell operation outside a module is currently the
only case in which the module path of a package is not actually a
prefix of the import path.
Fixes #28011
Fixes #27099
Fixes #28943
Updates #27102
Updates #28459
Updates #27063
Change-Id: I61d5556df7b1b7d1efdaffa892f0e3e95b612d87
Reviewed-on: https://go-review.googlesource.com/c/153459
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
Diffstat (limited to 'src/cmd/go/testdata/script/mod_outside.txt')
-rw-r--r-- | src/cmd/go/testdata/script/mod_outside.txt | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/cmd/go/testdata/script/mod_outside.txt b/src/cmd/go/testdata/script/mod_outside.txt index 25013b6271..db994a1656 100644 --- a/src/cmd/go/testdata/script/mod_outside.txt +++ b/src/cmd/go/testdata/script/mod_outside.txt @@ -12,8 +12,8 @@ stdout 'NUL|/dev/null' # which is not in a module. ! go list stderr 'cannot find main module' -! go list -m -stderr 'cannot find main module' +go list -m +stdout '^command-line-arguments$' # 'go list' in the working directory should fail even if there is a a 'package # main' present: without a main module, we do not know its package path. ! go list ./foo @@ -148,6 +148,10 @@ stderr 'no such package' stderr 'can only use path@version syntax with' +# 'go fmt' should be able to format files outside of a module. +go fmt foo/foo.go + + # The remainder of the test checks dependencies by linking and running binaries. [short] stop @@ -185,8 +189,8 @@ stdout 'using example.com/version v1.0.0' # 'go run' should use 'main' as the effective module and import path. go run ./foo/foo.go -stdout 'path is \.$' -stdout 'main is main \(devel\)' +stdout 'path is command-line-arguments$' +stdout 'main is command-line-arguments \(devel\)' stdout 'using example.com/version v1.1.0' # 'go generate' should work with file arguments. |