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