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

     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.
    12  go work use -r .
    13  cmp 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.
    17  go work use vendor/example.com/dep
    18  cmp go.work go.work.want_explicit_vendor
    19  
    20  # Scenario 3: Re-running recursive use from clean state should produce
    21  # consistent results.
    22  cp go.work.clean go.work
    23  go work use -r .
    24  cmp go.work go.work.want_recursive
    25  
    26  -- go.work --
    27  go 1.24
    28  
    29  -- go.work.clean --
    30  go 1.24
    31  
    32  -- go.work.want_recursive --
    33  go 1.24
    34  
    35  use (
    36  	.
    37  	./myvendor
    38  	./notvendor
    39  	./sub
    40  	./subdir
    41  )
    42  -- go.work.want_explicit_vendor --
    43  go 1.24
    44  
    45  use (
    46  	.
    47  	./myvendor
    48  	./notvendor
    49  	./sub
    50  	./subdir
    51  	./vendor/example.com/dep
    52  )
    53  -- go.mod --
    54  module example.com/main
    55  
    56  go 1.24
    57  
    58  -- main.go --
    59  package main
    60  
    61  -- sub/go.mod --
    62  module example.com/sub
    63  
    64  go 1.24
    65  
    66  -- sub/main.go --
    67  package sub
    68  
    69  -- subdir/go.mod --
    70  module example.com/subdir
    71  
    72  go 1.24
    73  
    74  -- subdir/main.go --
    75  package 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 --
    81  module example.com/vendored
    82  
    83  go 1.24
    84  
    85  -- subdir/vendor/example.com/vendored/vendored.go --
    86  package vendored
    87  
    88  -- vendor/example.com/dep/go.mod --
    89  module example.com/dep
    90  
    91  go 1.24
    92  
    93  -- vendor/example.com/dep/dep.go --
    94  package dep
    95  
    96  -- sub/vendor/example.com/subdep/go.mod --
    97  module example.com/subdep
    98  
    99  go 1.24
   100  
   101  -- sub/vendor/example.com/subdep/subdep.go --
   102  package subdep
   103  
   104  -- vendor/example.com/dep/vendor/example.com/transitive/go.mod --
   105  module example.com/transitive
   106  
   107  go 1.24
   108  
   109  -- vendor/example.com/dep/vendor/example.com/transitive/transitive.go --
   110  package transitive
   111  
   112  -- notvendor/go.mod --
   113  module example.com/notvendor
   114  
   115  go 1.24
   116  
   117  -- notvendor/main.go --
   118  package notvendor
   119  
   120  -- myvendor/go.mod --
   121  module example.com/myvendor
   122  
   123  go 1.24
   124  
   125  -- myvendor/main.go --
   126  package myvendor
   127  

View as plain text