[short] skip
env GO111MODULE=on

# Download everything to avoid "finding" messages in stderr later.
cp go.mod.orig go.mod
go mod download
go mod download example.com@v1.0.0
go mod download example.com/badchain/a@v1.1.0
go mod download example.com/badchain/b@v1.1.0
go mod download example.com/badchain/c@v1.1.0

# Try to update example.com/badchain/a (and its dependencies).
! go get -d example.com/badchain/a
cmp stderr update-a-expected
cmp go.mod go.mod.orig

# Try to update the main module. This updates everything, including
# modules that aren't direct requirements, so the error stack is shorter.
! go get -d -u ./...
cmp stderr update-main-expected
cmp go.mod go.mod.orig

# Update manually. Listing modules should produce an error.
go mod edit -require=example.com/badchain/a@v1.1.0
! go list -m
cmp stderr list-expected

# Try listing a package that imports a package
# in a module without a requirement.
go mod edit -droprequire example.com/badchain/a
! go list m/use
cmp stderr list-missing-expected

! go list -test m/testuse
cmp stderr list-missing-test-expected

-- go.mod.orig --
module m

go 1.13

require example.com/badchain/a v1.0.0
-- use/use.go --
package use

import _ "example.com/badchain/c"
-- testuse/testuse.go --
package testuse
-- testuse/testuse_test.go --
package testuse

import (
	"testing"
	_ "example.com/badchain/c"
)

func Test(t *testing.T) {}
-- update-main-expected --
go: example.com/badchain/c upgrade => v1.1.0
go get: example.com/badchain/c@v1.0.0 updating to
	example.com/badchain/c@v1.1.0: parsing go.mod:
	module declares its path as: badchain.example.com/c
	        but was required as: example.com/badchain/c
-- update-a-expected --
go: example.com/badchain/a upgrade => v1.1.0
go get: example.com/badchain/a@v1.1.0 requires
	example.com/badchain/b@v1.1.0 requires
	example.com/badchain/c@v1.1.0: parsing go.mod:
	module declares its path as: badchain.example.com/c
	        but was required as: example.com/badchain/c
-- list-expected --
go: example.com/badchain/a@v1.1.0 requires
	example.com/badchain/b@v1.1.0 requires
	example.com/badchain/c@v1.1.0: parsing go.mod:
	module declares its path as: badchain.example.com/c
	        but was required as: example.com/badchain/c
-- list-missing-expected --
go: finding module for package example.com/badchain/c
go: found example.com/badchain/c in example.com/badchain/c v1.1.0
go: m/use imports
	example.com/badchain/c: example.com/badchain/c@v1.1.0: parsing go.mod:
	module declares its path as: badchain.example.com/c
	        but was required as: example.com/badchain/c
-- list-missing-test-expected --
go: finding module for package example.com/badchain/c
go: found example.com/badchain/c in example.com/badchain/c v1.1.0
go: m/testuse tested by
	m/testuse.test imports
	example.com/badchain/c: example.com/badchain/c@v1.1.0: parsing go.mod:
	module declares its path as: badchain.example.com/c
	        but was required as: example.com/badchain/c
