Skip to content

Commit

Permalink
cmd/go: add 'go generate' commands to modfile_flag test
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
Jay Conrod committed Nov 22, 2019
1 parent 3922c00 commit 300f5d5
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/cmd/go/testdata/script/modfile_flag.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,19 @@ exists vendor
go mod edit -require rsc.io/[email protected]
! 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.
Expand All @@ -62,6 +75,10 @@ stderr '-modfile=goaltmod: file does not have .mod extension'
-- go.sum --
ʕ◔ϖ◔ʔ
-- use.go --
package use
package main

import _ "rsc.io/quote"
-- gen.go --
//go:generate go mod edit -exclude example.com/[email protected]

package main

0 comments on commit 300f5d5

Please sign in to comment.