...
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
11env GO111MODULE=on
12env GOPROXY=direct
13env GOSUMDB=off
14
15# Get the module without having to specify the subdir.
16cd a
17cp go.mod go.mod.orig
18go get vcs-test.golang.org/go/gitreposubdir@v1.2.3
19exists $GOPATH/pkg/mod/vcs-test.golang.org/go/gitreposubdir@v1.2.3
20go get vcs-test.golang.org/go/gitreposubdirv2/v2@v2.0.0
21exists $GOPATH/pkg/mod/vcs-test.golang.org/go/gitreposubdirv2/v2@v2.0.0
22
23# Import the module without having to specify the subdir.
24cp go.mod.orig go.mod
25go mod tidy
26
27# Run main.go which has the import.
28go run main.go
29stdout 'hello, world'
30stdout 'hello, world v2'
31
32# Fail if subdir is specified in get.
33! go get vcs-test.golang.org/go/gitreposubdir/foo/subdir
34stderr '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
36stderr '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.
39cd ../b
40! go mod tidy
41stderr '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'
42stderr '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 --
45package main
46
47import (
48 "fmt"
49 "vcs-test.golang.org/go/gitreposubdir"
50 "vcs-test.golang.org/go/gitreposubdirv2/v2"
51)
52
53func main() {
54 fmt.Println(greeter.Hello())
55 fmt.Println(greeterv2.Hello())
56}
57-- a/go.mod --
58module example
59
60go 1.24
61-- b/main.go --
62package main
63
64import (
65 "fmt"
66 "vcs-test.golang.org/go/gitreposubdir/foo/subdir"
67 "vcs-test.golang.org/go/gitreposubdirv2/v2/foo/subdir"
68)
69
70func main() {
71 fmt.Println(greeter.Hello())
72 fmt.Println(greeterv2.Hello())
73}
74-- b/go.mod --
75module example
76
77go 1.24
View as plain text