1 # Check that when -trimpath and -mod=vendor are used together,
2 # paths in vendored packages are properly trimmed.
3 # Verifies golang.org/issue/36566.
4
5 [short] skip
6
7 # Only the main module has a root directory in vendor mode.
8 go mod vendor
9 go list -f {{.Module.Dir}} example.com/main
10 stdout $PWD
11 go list -f {{.Module.Dir}} example.com/stack
12 ! stdout .
13
14 # The program prints a file name from a vendored package.
15 # Without -trimpath, the name should include the vendor directory.
16 go run main.go
17 stdout vendor
18
19 # With -trimpath, everything before the package path should be trimmed.
20 # As with -mod=mod, the version should appear as part of the module path.
21 go run -mod=vendor -trimpath main.go
22 stdout '^example.com/stack@v1.0.0/stack.go$'
23
24 # With pristinely vendored source code, a trimmed binary built from vendored
25 # code should have the same behavior as one build from the module cache.
26 go run -mod=mod -trimpath main.go
27 stdout '^example.com/stack@v1.0.0/stack.go$'
28
29 -- go.mod --
30 module example.com/main
31
32 require example.com/stack v1.0.0
33
34 -- main.go --
35 package main
36
37 import (
38 "fmt"
39
40 "example.com/stack"
41 )
42
43 func main() {
44 fmt.Println(stack.TopFile())
45 }
46
View as plain text