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

     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  go 1.17
    33  
    34  require example.com/stack v1.0.0
    35  -- go.sum --
    36  example.com/stack v1.0.0 h1:IEDLeew5NytZ8vrgCF/QVem3H3SR3QMttdu9HfJvk9I=
    37  example.com/stack v1.0.0/go.mod h1:7wFEbaV5e5O7wJ8aBdqQOR//UXppm/pwnwziMKViuI4=
    38  -- main.go --
    39  package main
    40  
    41  import (
    42    "fmt"
    43  
    44    "example.com/stack"
    45  )
    46  
    47  func main() {
    48    fmt.Println(stack.TopFile())
    49  }
    50  

View as plain text