...

Text file src/cmd/go/testdata/script/mod_replace.txt

Documentation: cmd/go/testdata/script

     1env GO111MODULE=on
     2[short] skip
     3
     4cp go.mod go.mod.orig
     5
     6# Make sure the test builds without replacement.
     7go build -mod=mod -o a1.exe .
     8exec ./a1.exe
     9stdout 'Don''t communicate by sharing memory'
    10
    11# Modules can be replaced by local packages.
    12cp go.mod.orig go.mod
    13go mod edit -replace=rsc.io/quote/v3=./local/rsc.io/quote/v3
    14go build -o a2.exe .
    15exec ./a2.exe
    16stdout 'Concurrency is not parallelism.'
    17
    18# The module path of the replacement doesn't need to match.
    19# (For example, it could be a long-running fork with its own import path.)
    20cp go.mod.orig go.mod
    21go mod edit -replace=rsc.io/quote/v3=./local/not-rsc.io/quote/v3
    22go build -o a3.exe .
    23exec ./a3.exe
    24stdout 'Clear is better than clever.'
    25
    26# However, the same module can't be used as two different paths.
    27cp go.mod.orig go.mod
    28go mod edit -replace=not-rsc.io/quote/v3@v3.0.0=rsc.io/quote/v3@v3.0.0 -require=not-rsc.io/quote/v3@v3.0.0
    29! go build -o a4.exe .
    30stderr 'rsc.io/quote/v3@v3.0.0 used for two different module paths \(not-rsc.io/quote/v3 and rsc.io/quote/v3\)'
    31
    32# Modules that do not (yet) exist upstream can be replaced too.
    33cp go.mod.orig go.mod
    34go mod edit -replace=not-rsc.io/quote/v3@v3.1.0=./local/rsc.io/quote/v3
    35go build -mod=mod -o a5.exe ./usenewmodule
    36! stderr 'finding not-rsc.io/quote/v3'
    37grep 'not-rsc.io/quote/v3 v3.1.0' go.mod
    38exec ./a5.exe
    39stdout 'Concurrency is not parallelism.'
    40
    41# Error messages for modules not found in replacements should
    42# indicate the replacement module.
    43cp go.mod.orig go.mod
    44go mod edit -replace=rsc.io/quote/v3=./local/rsc.io/quote/v3
    45! go get rsc.io/quote/v3/missing-package
    46stderr 'module rsc.io/quote/v3@upgrade found \(v3.0.0, replaced by ./local/rsc.io/quote/v3\), but does not contain package'
    47
    48# The reported Dir and GoMod for a replaced module should be accurate.
    49cp go.mod.orig go.mod
    50go mod edit -replace=rsc.io/quote/v3=not-rsc.io/quote@v0.1.0-nomod
    51go mod download rsc.io/quote/v3
    52go list -m -f '{{.Path}} {{.Version}} {{.Dir}} {{.GoMod}}{{with .Replace}} => {{.Path}} {{.Version}} {{.Dir}} {{.GoMod}}{{end}}' rsc.io/quote/v3
    53stdout '^rsc.io/quote/v3 v3.0.0 '$GOPATH'[/\\]pkg[/\\]mod[/\\]not-rsc.io[/\\]quote@v0.1.0-nomod '$GOPATH'[/\\]pkg[/\\]mod[/\\]cache[/\\]download[/\\]not-rsc.io[/\\]quote[/\\]@v[/\\]v0.1.0-nomod.mod => not-rsc.io/quote v0.1.0-nomod '$GOPATH'[/\\]pkg[/\\]mod[/\\]not-rsc.io[/\\]quote@v0.1.0-nomod '$GOPATH'[/\\]pkg[/\\]mod[/\\]cache[/\\]download[/\\]not-rsc.io[/\\]quote[/\\]@v[/\\]v0.1.0-nomod.mod$'
    54
    55-- go.mod --
    56module quoter
    57
    58require rsc.io/quote/v3 v3.0.0
    59
    60-- main.go --
    61package main
    62
    63import (
    64	"fmt"
    65	"rsc.io/quote/v3"
    66)
    67
    68func main() {
    69	fmt.Println(quote.GoV3())
    70}
    71
    72-- usenewmodule/main.go --
    73package main
    74
    75import (
    76	"fmt"
    77	"not-rsc.io/quote/v3"
    78)
    79
    80func main() {
    81	fmt.Println(quote.GoV3())
    82}
    83
    84-- local/rsc.io/quote/v3/go.mod --
    85module rsc.io/quote/v3
    86
    87require rsc.io/sampler v1.3.0
    88
    89-- local/rsc.io/quote/v3/quote.go --
    90// Copyright 2018 The Go Authors. All rights reserved.
    91// Use of this source code is governed by a BSD-style
    92// license that can be found in the LICENSE file.
    93
    94// Package quote collects pithy sayings.
    95package quote
    96
    97import "rsc.io/sampler"
    98
    99// Hello returns a greeting.
   100func HelloV3() string {
   101	return sampler.Hello()
   102}
   103
   104// Glass returns a useful phrase for world travelers.
   105func GlassV3() string {
   106	// See http://www.oocities.org/nodotus/hbglass.html.
   107	return "I can eat glass and it doesn't hurt me."
   108}
   109
   110// Go returns a REPLACED Go proverb.
   111func GoV3() string {
   112	return "Concurrency is not parallelism."
   113}
   114
   115// Opt returns a optimization truth.
   116func OptV3() string {
   117	// Wisdom from ken.
   118	return "If a program is too slow, it must have a loop."
   119}
   120
   121-- local/not-rsc.io/quote/v3/go.mod --
   122module not-rsc.io/quote/v3
   123
   124-- local/not-rsc.io/quote/v3/quote.go --
   125package quote
   126
   127func GoV3() string {
   128	return "Clear is better than clever."
   129}

View as plain text