github.com/hikaru7719/go@v0.0.0-20181025140707-c8b2ac68906a/src/cmd/go/testdata/script/mod_replace.txt (about)

     1  env GO111MODULE=on
     2  
     3  go build -o a1.exe .
     4  exec ./a1.exe
     5  stdout 'Don''t communicate by sharing memory'
     6  
     7  # Modules can be replaced by local packages.
     8  go mod edit -replace=rsc.io/quote/v3=./local/rsc.io/quote/v3
     9  go build -o a2.exe .
    10  exec ./a2.exe
    11  stdout 'Concurrency is not parallelism.'
    12  
    13  # The module path of the replacement doesn't need to match.
    14  # (For example, it could be a long-running fork with its own import path.)
    15  go mod edit -replace=rsc.io/quote/v3=./local/not-rsc.io/quote/v3
    16  go build -o a3.exe .
    17  exec ./a3.exe
    18  stdout 'Clear is better than clever.'
    19  
    20  # However, the same module can't be used as two different paths.
    21  go mod edit -dropreplace=rsc.io/quote/v3 -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
    22  ! go build -o a4.exe .
    23  stderr 'rsc.io/quote/v3@v3.0.0 used for two different module paths \(not-rsc.io/quote/v3 and rsc.io/quote/v3\)'
    24  
    25  -- go.mod --
    26  module quoter
    27  
    28  require rsc.io/quote/v3 v3.0.0
    29  
    30  -- main.go --
    31  package main
    32  
    33  import (
    34  	"fmt"
    35  	"rsc.io/quote/v3"
    36  )
    37  
    38  func main() {
    39  	fmt.Println(quote.GoV3())
    40  }
    41  
    42  -- local/rsc.io/quote/v3/go.mod --
    43  module rsc.io/quote/v3
    44  
    45  require rsc.io/sampler v1.3.0
    46  
    47  -- local/rsc.io/quote/v3/quote.go --
    48  // Copyright 2018 The Go Authors. All rights reserved.
    49  // Use of this source code is governed by a BSD-style
    50  // license that can be found in the LICENSE file.
    51  
    52  // Package quote collects pithy sayings.
    53  package quote
    54  
    55  import "rsc.io/sampler"
    56  
    57  // Hello returns a greeting.
    58  func HelloV3() string {
    59  	return sampler.Hello()
    60  }
    61  
    62  // Glass returns a useful phrase for world travelers.
    63  func GlassV3() string {
    64  	// See http://www.oocities.org/nodotus/hbglass.html.
    65  	return "I can eat glass and it doesn't hurt me."
    66  }
    67  
    68  // Go returns a REPLACED Go proverb.
    69  func GoV3() string {
    70  	return "Concurrency is not parallelism."
    71  }
    72  
    73  // Opt returns a optimization truth.
    74  func OptV3() string {
    75  	// Wisdom from ken.
    76  	return "If a program is too slow, it must have a loop."
    77  }
    78  
    79  -- local/not-rsc.io/quote/v3/go.mod --
    80  module not-rsc.io/quote/v3
    81  
    82  -- local/not-rsc.io/quote/v3/quote.go --
    83  package quote
    84  
    85  func GoV3() string {
    86  	return "Clear is better than clever."
    87  }