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