Skip to content

Commit 300f5d5

Browse files
author
Jay Conrod
committed
cmd/go: add 'go generate' commands to modfile_flag test
Verify that 'go generate' works with -modfile. Also check that go commands starts with 'go generate' do not inherit -modfile, but they should still work if -modfile is set in GOFLAGS. Updates #34506 Change-Id: I5e1f897b4e38e4fdaccc0fbb7a71b8d0e9fc0660 Reviewed-on: https://go-review.googlesource.com/c/go/+/208236 Run-TryBot: Jay Conrod <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Bryan C. Mills <[email protected]>
1 parent 3922c00 commit 300f5d5

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/cmd/go/testdata/script/modfile_flag.txt

+18-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,19 @@ exists vendor
4444
go mod edit -require rsc.io/[email protected]
4545
! go list .
4646
go list -mod=mod
47+
rm vendor
48+
49+
50+
# 'go generate' should use the alternate file when resolving packages.
51+
# Recursive go commands started with 'go generate' should not get an explicitly
52+
# passed -modfile, but they should see arguments from GOFLAGS.
53+
cp go.alt.mod go.gen.mod
54+
env OLD_GOFLAGS=$GOFLAGS
55+
env GOFLAGS=-modfile=go.gen.mod
56+
go generate -modfile=go.alt.mod .
57+
env GOFLAGS=$OLD_GOFLAGS
58+
grep example.com/exclude go.gen.mod
59+
! grep example.com/exclude go.alt.mod
4760

4861

4962
# The original files should not have been modified.
@@ -62,6 +75,10 @@ stderr '-modfile=goaltmod: file does not have .mod extension'
6275
-- go.sum --
6376
ʕ◔ϖ◔ʔ
6477
-- use.go --
65-
package use
78+
package main
6679

6780
import _ "rsc.io/quote"
81+
-- gen.go --
82+
//go:generate go mod edit -exclude example.com/[email protected]
83+
84+
package main

0 commit comments

Comments
 (0)