summaryrefslogtreecommitdiff
path: root/libgo/go/cmd/go/testdata/script/modfile_flag.txt
diff options
context:
space:
mode:
Diffstat (limited to 'libgo/go/cmd/go/testdata/script/modfile_flag.txt')
-rw-r--r--libgo/go/cmd/go/testdata/script/modfile_flag.txt84
1 files changed, 84 insertions, 0 deletions
diff --git a/libgo/go/cmd/go/testdata/script/modfile_flag.txt b/libgo/go/cmd/go/testdata/script/modfile_flag.txt
new file mode 100644
index 00000000000..1409be9599c
--- /dev/null
+++ b/libgo/go/cmd/go/testdata/script/modfile_flag.txt
@@ -0,0 +1,84 @@
+# Tests the behavior of the -modfile flag in commands that support it.
+# The go.mod file exists but should not be read or written.
+# Same with go.sum.
+
+env GOFLAGS=-modfile=go.alt.mod
+cp go.mod go.mod.orig
+cp go.sum go.sum.orig
+
+
+# go mod init should create a new file, even though go.mod already exists.
+go mod init example.com/m
+grep example.com/m go.alt.mod
+
+# go mod edit should operate on the alternate file
+go mod edit -require rsc.io/quote@v1.5.2
+grep rsc.io/quote go.alt.mod
+
+# other 'go mod' commands should work. 'go mod vendor' is tested later.
+go mod download rsc.io/quote
+go mod graph
+stdout rsc.io/quote
+go mod tidy
+grep rsc.io/quote go.alt.sum
+go mod verify
+go mod why rsc.io/quote
+
+
+# 'go list' and other commands with build flags should work.
+# They should update the alternate go.mod when a dependency is missing.
+go mod edit -droprequire rsc.io/quote
+go list .
+grep rsc.io/quote go.alt.mod
+go build -n .
+go test -n .
+go get -d rsc.io/quote
+
+
+# 'go mod vendor' should work.
+go mod vendor
+exists vendor
+
+# Automatic vendoring should be broken by editing an explicit requirement
+# in the alternate go.mod file.
+go mod edit -require rsc.io/quote@v1.5.1
+! go list .
+go list -mod=mod
+rm vendor
+
+
+# 'go generate' should use the alternate file when resolving packages.
+# Recursive go commands started with 'go generate' should not get an explicitly
+# passed -modfile, but they should see arguments from GOFLAGS.
+cp go.alt.mod go.gen.mod
+env OLD_GOFLAGS=$GOFLAGS
+env GOFLAGS=-modfile=go.gen.mod
+go generate -modfile=go.alt.mod .
+env GOFLAGS=$OLD_GOFLAGS
+grep example.com/exclude go.gen.mod
+! grep example.com/exclude go.alt.mod
+
+
+# The original files should not have been modified.
+cmp go.mod go.mod.orig
+cmp go.sum go.sum.orig
+
+
+# If the altnernate mod file does not have a ".mod" suffix, an error
+# should be reported.
+cp go.alt.mod goaltmod
+! go mod tidy -modfile=goaltmod
+stderr '-modfile=goaltmod: file does not have .mod extension'
+
+-- go.mod --
+ʕ◔ϖ◔ʔ
+-- go.sum --
+ʕ◔ϖ◔ʔ
+-- use.go --
+package main
+
+import _ "rsc.io/quote"
+-- gen.go --
+//go:generate go mod edit -exclude example.com/exclude@v1.0.0
+
+package main