1
0
mirror of https://github.com/golang/go synced 2024-11-07 12:36:27 -07:00

cmd/go: test that 'go mod tidy' uses transitive requirements from replacements

The existing mod_tidy test uses replacements, but doesn't replace
modules that can also be resolved by fetching from GOPROXY, and
doesn't check the differences between the internal and external views.

This new test clarifies that interaction with a more realistic example.

Change-Id: I2bb2028148f4b7b95c3bfcc54b3976a49515379a
Reviewed-on: https://go-review.googlesource.com/c/140859
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
This commit is contained in:
Bryan C. Mills 2018-10-09 14:23:34 -04:00
parent eecb5fd10e
commit 160ee5d7f5

View File

@ -0,0 +1,71 @@
env GO111MODULE=on
# From inside the module, 'go list -m all' should NOT include transitive
# requirements of modules that have been replaced.
go list -m all
stdout 'rsc.io/quote/v3 v3.0.0'
! stdout 'rsc.io/sampler'
! stdout 'golang.org/x/text'
# From outside the module, 'go list -m all' should include them.
cd outside
go list -m all
stdout 'rsc.io/quote/v3 v3.0.0'
stdout 'rsc.io/sampler v1.3.0'
stdout 'golang.org/x/text'
cd ..
# 'go list all' should add indirect requirements to satisfy the packages
# imported from replacement modules.
! grep 'rsc.io/sampler' go.mod
! grep 'golang.org/x/text' go.mod
go list all
grep 'rsc.io/sampler' go.mod
grep 'golang.org/x/text' go.mod
# 'go get' and 'go mod tidy' should follow the requirements of the replacements,
# not the originals, even if that results in a set of versions that are
# misleading or redundant without those replacements.
go get rsc.io/sampler@v1.2.0
go mod tidy
go list -m all
stdout 'rsc.io/quote/v3 v3.0.0'
stdout 'rsc.io/sampler v1.2.0'
stdout 'golang.org/x/text'
# The requirements seen from outside may be higher (or lower)
# than those seen from within the module.
grep 'rsc.io/sampler v1.2.0' go.mod
cd outside
go list -m all
stdout 'rsc.io/sampler v1.3.0'
-- go.mod --
module example.com/tidy
require rsc.io/quote/v3 v3.0.0
replace rsc.io/quote/v3 => ./not-rsc.io/quote/v3
-- imports.go --
package tidy
import _ "rsc.io/quote/v3"
-- outside/go.mod --
module example.com/tidy/outside
require example.com/tidy v0.0.0
replace example.com/tidy => ./..
-- not-rsc.io/quote/v3/go.mod --
module not-rsc.io/quote/v3
// No requirements specified!
-- not-rsc.io/quote/v3/quote.go --
package quote
import (
_ "rsc.io/sampler"
_ "golang.org/x/text/language"
)