summaryrefslogtreecommitdiff
path: root/libgo/go/cmd/go/testdata/script/mod_outside.txt
diff options
context:
space:
mode:
Diffstat (limited to 'libgo/go/cmd/go/testdata/script/mod_outside.txt')
-rw-r--r--libgo/go/cmd/go/testdata/script/mod_outside.txt167
1 files changed, 118 insertions, 49 deletions
diff --git a/libgo/go/cmd/go/testdata/script/mod_outside.txt b/libgo/go/cmd/go/testdata/script/mod_outside.txt
index 4182e71dde1..03ef576168c 100644
--- a/libgo/go/cmd/go/testdata/script/mod_outside.txt
+++ b/libgo/go/cmd/go/testdata/script/mod_outside.txt
@@ -17,7 +17,7 @@ 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
+! go list ./needmod
stderr 'cannot find main module'
# 'go list all' lists the transitive import graph of the main module,
@@ -25,8 +25,6 @@ stderr 'cannot find main module'
go list all
! stdout .
stderr 'warning: "all" matched no packages'
-go list -m all
-stderr 'warning: pattern "all" matched no module dependencies'
# 'go list' on standard-library packages should work, since they do not depend
# on the contents of any module.
@@ -38,7 +36,7 @@ go list $GOROOT/src/fmt
stdout '^fmt$'
# 'go list' should work with file arguments.
-go list ./foo/foo.go
+go list ./needmod/needmod.go
stdout 'command-line-arguments'
# 'go list -m' with an explicit version should resolve that version.
@@ -49,12 +47,22 @@ stdout 'example.com/version v1.1.0'
go list -m -versions example.com/version
stdout 'v1.0.0\s+v1.0.1\s+v1.1.0'
-# 'go list -m <mods> all' does not include the dependencies of <mods> in the computation of 'all'.
-go list -m example.com/printversion@v1.0.0 all
-stdout 'example.com/printversion v1.0.0'
-stderr 'warning: pattern "all" matched no module dependencies'
+# 'go list -m all' should fail. "all" is not meaningful outside of a module.
+! go list -m all
+stderr 'go: cannot match "all": working directory is not part of a module'
+
+# 'go list -m <mods> all' should also fail.
+! go list -m example.com/printversion@v1.0.0 all
+stderr 'go: cannot match "all": working directory is not part of a module'
! stdout 'example.com/version'
+# 'go list -m' with wildcards should fail. Wildcards match modules in the
+# build list, so they aren't meaningful outside a module.
+! go list -m ...
+stderr 'go: cannot match "...": working directory is not part of a module'
+! go list -m rsc.io/quote/...
+stderr 'go: cannot match "rsc.io/quote/...": working directory is not part of a module'
+
# 'go clean' should skip the current directory if it isn't in a module.
go clean -n
@@ -66,10 +74,9 @@ go mod graph
! stdout .
! stderr .
-# 'go mod why' should report that nothing is a dependency.
-go mod why -m example.com/version
-stdout 'does not need'
-
+# 'go mod why' should fail, since there is no main module to depend on anything.
+! go mod why -m example.com/version
+stderr 'cannot find main module'
# 'go mod edit', 'go mod tidy', and 'go mod fmt' should fail:
# there is no go.mod file to edit.
@@ -81,21 +88,30 @@ stderr 'cannot find main module'
stderr 'cannot find main module'
+# 'go mod download' without arguments should report an error.
+! go mod download
+stderr 'no modules specified'
+
# 'go mod download' should download exactly the requested module without dependencies.
rm -r $GOPATH/pkg/mod/cache/download/example.com
go mod download example.com/printversion@v1.0.0
exists $GOPATH/pkg/mod/cache/download/example.com/printversion/@v/v1.0.0.zip
! exists $GOPATH/pkg/mod/cache/download/example.com/version/@v/v1.0.0.zip
+# 'go mod download all' should fail. "all" is not meaningful outside of a module.
+! go mod download all
+stderr 'go: cannot match "all": working directory is not part of a module'
+
+
# 'go mod vendor' should fail: it starts by clearing the existing vendor
# directory, and we don't know where that is.
! go mod vendor
stderr 'cannot find main module'
-# 'go mod verify' should succeed: we have no modules to verify.
-go mod verify
-stdout 'all modules verified'
-! stderr .
+
+# 'go mod verify' should fail: we have no modules to verify.
+! go mod verify
+stderr 'cannot find main module'
# 'go get' without arguments implicitly operates on the main module, and thus
@@ -104,14 +120,13 @@ stdout 'all modules verified'
stderr 'cannot find main module'
! go get -u
stderr 'cannot find main module'
-! go get -u ./foo
+! go get -u ./needmod
stderr 'cannot find main module'
# 'go get -u all' upgrades the transitive import graph of the main module,
# which is empty.
-go get -u all
-! stdout .
-stderr 'warning: "all" matched no packages'
+! go get -u all
+stderr 'go get all: cannot match "all": working directory is not part of a module'
# 'go get' should check the proposed module graph for consistency,
# even though we won't write it anywhere.
@@ -126,35 +141,75 @@ exists $GOPATH/pkg/mod/example.com/version@v1.0.0
# 'go build' without arguments implicitly operates on the current directory, and should fail.
-cd foo
+cd needmod
! go build
stderr 'cannot find main module'
cd ..
# 'go build' of a non-module directory should fail too.
-! go build ./foo
+! go build ./needmod
stderr 'cannot find main module'
-# However, 'go build' should succeed for standard-library packages.
+# 'go build' of source files should fail if they import anything outside std.
+! go build -n ./needmod/needmod.go
+stderr 'needmod[/\\]needmod.go:10:2: cannot find module providing package example.com/version: working directory is not part of a module'
+
+# 'go build' of source files should succeed if they do not import anything outside std.
+go build -n -o ignore ./stdonly/stdonly.go
+
+# 'go build' should succeed for standard-library packages.
go build -n fmt
-# TODO(golang.org/issue/28992): 'go doc' should document the latest version.
-# For now it does not.
+# 'go doc' without arguments implicitly operates on the current directory, and should fail.
+# TODO(golang.org/issue/32027): currently, it succeeds.
+cd needmod
+go doc
+cd ..
+
+# 'go doc' of a non-module directory should also succeed.
+go doc ./needmod
+
+# 'go doc' should succeed for standard-library packages.
+go doc fmt
+
+# 'go doc' should fail for a package path outside a module.
! go doc example.com/version
-stderr 'no such package'
+stderr 'doc: cannot find module providing package example.com/version: working directory is not part of a module'
# 'go install' with a version should fail due to syntax.
! go install example.com/printversion@v1.0.0
stderr 'can only use path@version syntax with'
+# 'go install' should fail if a package argument must be resolved to a module.
+! go install example.com/printversion
+stderr 'cannot find module providing package example.com/printversion: working directory is not part of a module'
+
+# 'go install' should fail if a source file imports a package that must be
+# resolved to a module.
+! go install ./needmod/needmod.go
+stderr 'needmod[/\\]needmod.go:10:2: cannot find module providing package example.com/version: working directory is not part of a module'
+
+
+# 'go run' with a verison should fail due to syntax.
+! go run example.com/printversion@v1.0.0
+stderr 'can only use path@version syntax with'
+
+# 'go run' should fail if a package argument must be resolved to a module.
+! go run example.com/printversion
+stderr 'cannot find module providing package example.com/printversion: working directory is not part of a module'
+
+# 'go run' should fail if a source file imports a package that must be
+# resolved to a module.
+! go run ./needmod/needmod.go
+stderr 'needmod[/\\]needmod.go:10:2: cannot find module providing package example.com/version: working directory is not part of a module'
+
# 'go fmt' should be able to format files outside of a module.
-go fmt foo/foo.go
+go fmt needmod/needmod.go
# The remainder of the test checks dependencies by linking and running binaries.
-[short] stop
# 'go get' of a binary without a go.mod should install the requested version,
# resolving outside dependencies to the latest available versions.
@@ -180,39 +235,31 @@ stdout 'path is example.com/printversion'
stdout 'main is example.com/printversion v1.0.0'
stdout 'using example.com/version v1.0.1'
-# 'go install' without a version should install the latest version
-# using its minimal module requirements.
-go install example.com/printversion
-exec ../bin/printversion
-stdout 'path is example.com/printversion'
-stdout 'main is example.com/printversion v1.0.0'
-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
+# 'go run' should work with file arguments if they don't import anything
+# outside std.
+go run ./stdonly/stdonly.go
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.
-[exec:touch] go generate ./foo/foo.go
-[exec:touch] exists ./foo/gen.txt
+[exec:touch] go generate ./needmod/needmod.go
+[exec:touch] exists ./needmod/gen.txt
# 'go install' should work with file arguments.
-go install ./foo/foo.go
+go install ./stdonly/stdonly.go
# 'go test' should work with file arguments.
-go test -v ./foo/foo_test.go
-stdout 'foo was tested'
+go test -v ./stdonly/stdonly_test.go
+stdout 'stdonly was tested'
# 'go vet' should work with file arguments.
-go vet ./foo/foo.go
+go vet ./stdonly/stdonly.go
-- README.txt --
There is no go.mod file in the working directory.
--- foo/foo.go --
+-- needmod/needmod.go --
//go:generate touch gen.txt
package main
@@ -237,7 +284,28 @@ func main() {
}
}
--- foo/foo_test.go --
+-- stdonly/stdonly.go --
+package main
+
+import (
+ "fmt"
+ "os"
+ "runtime/debug"
+)
+
+func main() {
+ info, ok := debug.ReadBuildInfo()
+ if !ok {
+ panic("missing build info")
+ }
+ fmt.Fprintf(os.Stdout, "path is %s\n", info.Path)
+ fmt.Fprintf(os.Stdout, "main is %s %s\n", info.Main.Path, info.Main.Version)
+ for _, m := range info.Deps {
+ fmt.Fprintf(os.Stdout, "using %s %s\n", m.Path, m.Version)
+ }
+}
+
+-- stdonly/stdonly_test.go --
package main
import (
@@ -245,6 +313,7 @@ import (
"testing"
)
-func TestFoo(t *testing.T) {
- fmt.Println("foo was tested")
+func Test(t *testing.T) {
+ fmt.Println("stdonly was tested")
}
+