| 1 |
# golang.org/issue/34055 |
| 2 |
# Starting in Go 1.25, go-import meta tag support an optional subdirectory paramater. |
| 3 |
# The corresponding go-import meta tag is specified as |
| 4 |
# <meta name="go-import" content="vcs-test.golang.org/go/gitreposubdir git https://vcs-test.golang.org/git/gitreposubdir foo/subdir"> |
| 5 |
# and contains the module in vcs-test.golang.org/git/gitreposubdir/foo/subdir. |
| 6 |
# See testdata/vcstest/go/gitreposubdir.txt and testdata/vcstest/git/gitreposubdir.txt |
| 7 |
|
| 8 |
[short] skip 'builds a go program' |
| 9 |
[!git] skip |
| 10 |
|
| 11 |
env GO111MODULE=on |
| 12 |
env GOPROXY=direct |
| 13 |
env GOSUMDB=off |
| 14 |
|
| 15 |
# Get the module without having to specify the subdir. |
| 16 |
cd a |
| 17 |
cp go.mod go.mod.orig |
| 18 |
go get vcs-test.golang.org/go/[email protected] |
| 19 |
exists $GOPATH/pkg/mod/vcs-test.golang.org/go/[email protected] |
| 20 |
go get vcs-test.golang.org/go/gitreposubdirv2/[email protected] |
| 21 |
exists $GOPATH/pkg/mod/vcs-test.golang.org/go/gitreposubdirv2/[email protected] |
| 22 |
|
| 23 |
# Import the module without having to specify the subdir. |
| 24 |
cp go.mod.orig go.mod |
| 25 |
go mod tidy |
| 26 |
|
| 27 |
# Run main.go which has the import. |
| 28 |
go run main.go |
| 29 |
stdout 'hello, world' |
| 30 |
stdout 'hello, world v2' |
| 31 |
|
| 32 |
# Fail if subdir is specified in get. |
| 33 |
! go get vcs-test.golang.org/go/gitreposubdir/foo/subdir |
| 34 |
stderr 'module vcs-test.golang.org/go/gitreposubdir@upgrade found \(v1.2.3\), but does not contain package vcs-test.golang.org/go/gitreposubdir/foo/subdir' |
| 35 |
! go get vcs-test.golang.org/go/gitreposubdirv2/v2/foo/subdir |
| 36 |
stderr 'module vcs-test.golang.org/go/gitreposubdirv2/v2@upgrade found \(v2.0.0\), but does not contain package vcs-test.golang.org/go/gitreposubdirv2/v2/foo/subdir' |
| 37 |
|
| 38 |
# Fail if subdir is specified in the import. |
| 39 |
cd ../b |
| 40 |
! go mod tidy |
| 41 |
stderr 'module vcs-test.golang.org/go/gitreposubdir@latest found \(v1.2.3\), but does not contain package vcs-test.golang.org/go/gitreposubdir/foo/subdir' |
| 42 |
stderr 'module vcs-test.golang.org/go/gitreposubdirv2/v2@latest found \(v2.0.0\), but does not contain package vcs-test.golang.org/go/gitreposubdirv2/v2/foo/subdir' |
| 43 |
|
| 44 |
-- a/main.go -- |
| 45 |
package main |
| 46 |
|
| 47 |
import ( |
| 48 |
"fmt" |
| 49 |
"vcs-test.golang.org/go/gitreposubdir" |
| 50 |
"vcs-test.golang.org/go/gitreposubdirv2/v2" |
| 51 |
) |
| 52 |
|
| 53 |
func main() { |
| 54 |
fmt.Println(greeter.Hello()) |
| 55 |
fmt.Println(greeterv2.Hello()) |
| 56 |
} |
| 57 |
-- a/go.mod -- |
| 58 |
module example |
| 59 |
|
| 60 |
go 1.24 |
| 61 |
-- b/main.go -- |
| 62 |
package main |
| 63 |
|
| 64 |
import ( |
| 65 |
"fmt" |
| 66 |
"vcs-test.golang.org/go/gitreposubdir/foo/subdir" |
| 67 |
"vcs-test.golang.org/go/gitreposubdirv2/v2/foo/subdir" |
| 68 |
) |
| 69 |
|
| 70 |
func main() { |
| 71 |
fmt.Println(greeter.Hello()) |
| 72 |
fmt.Println(greeterv2.Hello()) |
| 73 |
} |
| 74 |
-- b/go.mod -- |
| 75 |
module example |
| 76 |
|
| 77 |
go 1.24 |