...

Text file src/cmd/go/testdata/script/mod_vendor_trimpath.txt

Documentation: cmd/go/testdata/script

     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.
     8go mod vendor
     9go list -f {{.Module.Dir}} example.com/main
    10stdout $PWD
    11go 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.
    16go run main.go
    17stdout 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.
    21go run -mod=vendor -trimpath main.go
    22stdout '^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.
    26go run -mod=mod -trimpath main.go
    27stdout '^example.com/stack@v1.0.0/stack.go$'
    28
    29-- go.mod --
    30module example.com/main
    31
    32go 1.17
    33
    34require example.com/stack v1.0.0
    35-- go.sum --
    36example.com/stack v1.0.0 h1:IEDLeew5NytZ8vrgCF/QVem3H3SR3QMttdu9HfJvk9I=
    37example.com/stack v1.0.0/go.mod h1:7wFEbaV5e5O7wJ8aBdqQOR//UXppm/pwnwziMKViuI4=
    38-- main.go --
    39package main
    40
    41import (
    42  "fmt"
    43
    44  "example.com/stack"
    45)
    46
    47func main() {
    48  fmt.Println(stack.TopFile())
    49}

View as plain text