|
| 1 | +# https://golang.org/issue/44106 |
| 2 | +# 'go get' should fetch the transitive dependencies of packages regardless of |
| 3 | +# tags, but shouldn't error out if the package is missing tag-guarded |
| 4 | +# dependencies. |
| 5 | + |
| 6 | +# Control case: just adding the top-level module to the go.mod file does not |
| 7 | +# fetch its dependencies. |
| 8 | + |
| 9 | +go mod edit -require example.net/ [email protected] |
| 10 | +! go list -deps example.net/cmd/tool |
| 11 | +stderr '^module example\.net/cmd provides package example\.net/cmd/tool and is replaced but not required; to add it:\n\tgo get example\.net/cmd@v0\.1\.0$' |
| 12 | +go mod edit -droprequire example.net/tools |
| 13 | + |
| 14 | + |
| 15 | +# 'go get -d' makes a best effort to fetch those dependencies, but shouldn't |
| 16 | +# error out if dependencies of tag-guarded files are missing. |
| 17 | + |
| 18 | +go get -d example.net/ [email protected] |
| 19 | + |
| 20 | +! go list example.net/tools |
| 21 | +stderr '^package example.net/tools: build constraints exclude all Go files in .*[/\\]tools$' |
| 22 | + |
| 23 | +go list -tags=tools -e -deps example.net/tools |
| 24 | +stdout '^example.net/cmd/tool$' |
| 25 | +stdout '^example.net/missing$' |
| 26 | + |
| 27 | +go list -deps example.net/cmd/tool |
| 28 | + |
| 29 | +! go list example.net/missing |
| 30 | +stderr '^no required module provides package example.net/missing; to add it:\n\tgo get example.net/missing$' |
| 31 | + |
| 32 | + |
| 33 | +# https://golang.org/issue/29268 |
| 34 | +# 'go get' should fetch modules whose roots contain test-only packages, but |
| 35 | +# without the -t flag shouldn't error out if the test has missing dependencies. |
| 36 | + |
| 37 | +go get -d example.net/ [email protected] |
| 38 | + |
| 39 | +# With the -t flag, the test dependencies must resolve successfully. |
| 40 | +! go get -d -t example.net/ [email protected] |
| 41 | +stderr '^example.net/testonly tested by\n\texample.net/testonly\.test imports\n\texample.net/missing: cannot find module providing package example.net/missing$' |
| 42 | + |
| 43 | + |
| 44 | +# 'go get -d' should succeed for a module path that does not contain a package, |
| 45 | +# but fail for a non-package subdirectory of a module. |
| 46 | + |
| 47 | +! go get -d example.net/missing/ [email protected] |
| 48 | +stderr '^go get: module example.net/ [email protected] found \(replaced by ./missing\), but does not contain package example.net/missing/subdir$' |
| 49 | + |
| 50 | +go get -d example.net/ [email protected] |
| 51 | + |
| 52 | + |
| 53 | +# Getting the subdirectory should continue to fail even if the corresponding |
| 54 | +# module is already present in the build list. |
| 55 | + |
| 56 | +! go get -d example.net/missing/ [email protected] |
| 57 | +stderr '^go get: module example.net/ [email protected] found \(replaced by ./missing\), but does not contain package example.net/missing/subdir$' |
| 58 | + |
| 59 | + |
| 60 | +-- go.mod -- |
| 61 | +module example.net/m |
| 62 | + |
| 63 | +go 1.15 |
| 64 | + |
| 65 | +replace ( |
| 66 | + example.net/tools v0.1.0 => ./tools |
| 67 | + example.net/cmd v0.1.0 => ./cmd |
| 68 | + example.net/testonly v0.1.0 => ./testonly |
| 69 | + example.net/missing v0.1.0 => ./missing |
| 70 | +) |
| 71 | + |
| 72 | +-- tools/go.mod -- |
| 73 | +module example.net/tools |
| 74 | + |
| 75 | +go 1.15 |
| 76 | + |
| 77 | +// Requirements intentionally omitted. |
| 78 | + |
| 79 | +-- tools/tools.go -- |
| 80 | +// +build tools |
| 81 | + |
| 82 | +package tools |
| 83 | + |
| 84 | +import ( |
| 85 | + _ "example.net/cmd/tool" |
| 86 | + _ "example.net/missing" |
| 87 | +) |
| 88 | + |
| 89 | +-- cmd/go.mod -- |
| 90 | +module example.net/cmd |
| 91 | + |
| 92 | +go 1.16 |
| 93 | +-- cmd/tool/tool.go -- |
| 94 | +package main |
| 95 | + |
| 96 | +func main() {} |
| 97 | + |
| 98 | +-- testonly/go.mod -- |
| 99 | +module example.net/testonly |
| 100 | + |
| 101 | +go 1.15 |
| 102 | +-- testonly/testonly_test.go -- |
| 103 | +package testonly_test |
| 104 | + |
| 105 | +import _ "example.net/missing" |
| 106 | + |
| 107 | +func Test(t *testing.T) {} |
| 108 | + |
| 109 | +-- missing/go.mod -- |
| 110 | +module example.net/missing |
| 111 | + |
| 112 | +go 1.15 |
| 113 | +-- missing/README.txt -- |
| 114 | +There are no Go source files here. |
| 115 | +-- missing/subdir/README.txt -- |
| 116 | +There are no Go source files here either. |
0 commit comments