...

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

Documentation: cmd/go/testdata/script

     1# Test that 'go work use -r' skips vendor directories.
     2# See https://go.dev/issue/51710.
     3
     4# Scenario 1: Basic recursive use should skip all vendor directories.
     5# - Top-level vendor/ should be excluded.
     6# - Nested vendor/ under submodules (sub/vendor/) should be excluded.
     7# - Deeply nested vendor/a/vendor/ should be excluded (already unreachable via SkipDir).
     8# - vendor/ under a non-module directory (subdir/vendor/) should also be excluded,
     9#   because d.Name() == "vendor" skips all directories named "vendor" regardless
    10#   of whether the parent is a module.
    11# - A directory named "notvendor" or "myvendor" should NOT be excluded.
    12go work use -r .
    13cmp go.work go.work.want_recursive
    14
    15# Scenario 2: Non-recursive 'go work use' on a directory named "vendor"
    16# should still work — the vendor skip only applies to -r walks.
    17go work use vendor/example.com/dep
    18cmp go.work go.work.want_explicit_vendor
    19
    20# Scenario 3: Re-running recursive use from clean state should produce
    21# consistent results.
    22cp go.work.clean go.work
    23go work use -r .
    24cmp go.work go.work.want_recursive
    25
    26-- go.work --
    27go 1.24
    28
    29-- go.work.clean --
    30go 1.24
    31
    32-- go.work.want_recursive --
    33go 1.24
    34
    35use (
    36	.
    37	./myvendor
    38	./notvendor
    39	./sub
    40	./subdir
    41)
    42-- go.work.want_explicit_vendor --
    43go 1.24
    44
    45use (
    46	.
    47	./myvendor
    48	./notvendor
    49	./sub
    50	./subdir
    51	./vendor/example.com/dep
    52)
    53-- go.mod --
    54module example.com/main
    55
    56go 1.24
    57
    58-- main.go --
    59package main
    60
    61-- sub/go.mod --
    62module example.com/sub
    63
    64go 1.24
    65
    66-- sub/main.go --
    67package sub
    68
    69-- subdir/go.mod --
    70module example.com/subdir
    71
    72go 1.24
    73
    74-- subdir/main.go --
    75package subdir
    76
    77# subdir/vendor/ contains a module, but it is skipped by 'go work use -r'
    78# because all directories named "vendor" are skipped, not just those at
    79# the root of a module with an existing vendor directory.
    80-- subdir/vendor/example.com/vendored/go.mod --
    81module example.com/vendored
    82
    83go 1.24
    84
    85-- subdir/vendor/example.com/vendored/vendored.go --
    86package vendored
    87
    88-- vendor/example.com/dep/go.mod --
    89module example.com/dep
    90
    91go 1.24
    92
    93-- vendor/example.com/dep/dep.go --
    94package dep
    95
    96-- sub/vendor/example.com/subdep/go.mod --
    97module example.com/subdep
    98
    99go 1.24
   100
   101-- sub/vendor/example.com/subdep/subdep.go --
   102package subdep
   103
   104-- vendor/example.com/dep/vendor/example.com/transitive/go.mod --
   105module example.com/transitive
   106
   107go 1.24
   108
   109-- vendor/example.com/dep/vendor/example.com/transitive/transitive.go --
   110package transitive
   111
   112-- notvendor/go.mod --
   113module example.com/notvendor
   114
   115go 1.24
   116
   117-- notvendor/main.go --
   118package notvendor
   119
   120-- myvendor/go.mod --
   121module example.com/myvendor
   122
   123go 1.24
   124
   125-- myvendor/main.go --
   126package myvendor

View as plain text