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

     1  # This test demonstrates dependency resolution when the main module imports a
     2  # new package from a previously-test-only dependency.
     3  #
     4  # When lazy loading is active, the loader will not load dependencies of any
     5  # module whose packages are *only* imported by tests outside the main module. If
     6  # the main module is changed to import a package from such a module, the
     7  # dependencies of that module will need to be reloaded.
     8  
     9  # The import graph used in this test looks like:
    10  #
    11  # m ---- a
    12  #  \     |
    13  #   \    a_test ---- b/x
    14  #    \
    15  #      --------------b/y (new) ---- c
    16  #
    17  # Where b/x and b/y are disjoint packages, but both contained in module b.
    18  #
    19  # The module dependency graph initially looks like:
    20  #
    21  # m ---- a.1 ---- b.1 ---- c.1
    22  #
    23  # This configuration is similar to that used in mod_lazy_new_import,
    24  # but the new import is from what is initially a test-only dependency.
    25  
    26  # Control case: in Go 1.14, the original go.mod is tidy,
    27  # and the dependency on c is eagerly loaded.
    28  
    29  cp go.mod go.mod.orig
    30  go mod tidy
    31  cmp go.mod.orig go.mod
    32  
    33  go list -m all
    34  stdout '^a v0.1.0 '
    35  stdout '^b v0.1.0 '
    36  stdout '^c v0.1.0 '
    37  
    38  # After adding a new import of b/y,
    39  # the import of c from b/y should resolve to the version required by b.
    40  
    41  cp m.go m.go.orig
    42  cp m.go.new m.go
    43  go mod tidy
    44  cmp go.mod.new go.mod
    45  
    46  go list -m all
    47  stdout '^a v0.1.0 '
    48  stdout '^b v0.1.0 '
    49  stdout '^c v0.1.0 '
    50  
    51  # With lazy loading, the go.mod requirements are the same,
    52  # but the dependency on c is initially pruned out.
    53  
    54  cp m.go.orig m.go
    55  cp go.mod.orig go.mod
    56  go mod edit -go=1.17
    57  go mod edit -go=1.17 go.mod.new
    58  
    59  cp go.mod go.mod.orig
    60  go mod tidy
    61  cmp go.mod.orig go.mod
    62  
    63  go list -m all
    64  stdout '^a v0.1.0 '
    65  stdout '^b v0.1.0 '
    66  ! stdout '^c '
    67  
    68  # After adding a new direct import of b/y,
    69  # the existing version of b should be promoted to a root,
    70  # bringing the version of c required by b into the build list.
    71  
    72  cp m.go.new m.go
    73  go mod tidy
    74  cmp go.mod.lazy go.mod
    75  
    76  go list -m all
    77  stdout '^a v0.1.0 '
    78  stdout '^b v0.1.0 '
    79  stdout '^c v0.1.0 '
    80  
    81  -- m.go --
    82  package main
    83  
    84  import (
    85  	"fmt"
    86  
    87  	_ "a"  // a_test imports b/x.
    88  )
    89  
    90  func main() {
    91  }
    92  -- m.go.new --
    93  package main
    94  
    95  import (
    96  	"fmt"
    97  
    98  	_ "a"  // a_test imports b/x.
    99  	"b/y"  // This is a new import, not yet reflected in the go.mod file.
   100  )
   101  
   102  func main() {
   103  	fmt.Println(b.CVersion())
   104  }
   105  -- go.mod --
   106  module m
   107  
   108  go 1.14
   109  
   110  require a v0.1.0
   111  
   112  replace (
   113  	a v0.1.0 => ./a1
   114  	b v0.1.0 => ./b1
   115  	c v0.1.0 => ./c1
   116  	c v0.2.0 => ./c2
   117  )
   118  -- go.mod.new --
   119  module m
   120  
   121  go 1.14
   122  
   123  require (
   124  	a v0.1.0
   125  	b v0.1.0
   126  )
   127  
   128  replace (
   129  	a v0.1.0 => ./a1
   130  	b v0.1.0 => ./b1
   131  	c v0.1.0 => ./c1
   132  	c v0.2.0 => ./c2
   133  )
   134  -- go.mod.lazy --
   135  module m
   136  
   137  go 1.17
   138  
   139  require (
   140  	a v0.1.0
   141  	b v0.1.0
   142  )
   143  
   144  require c v0.1.0 // indirect
   145  
   146  replace (
   147  	a v0.1.0 => ./a1
   148  	b v0.1.0 => ./b1
   149  	c v0.1.0 => ./c1
   150  	c v0.2.0 => ./c2
   151  )
   152  -- a1/go.mod --
   153  module a
   154  
   155  go 1.17
   156  
   157  require b v0.1.0
   158  -- a1/a.go --
   159  package a
   160  -- a1/a_test.go --
   161  package a_test
   162  
   163  import _ "b/x"
   164  -- b1/go.mod --
   165  module b
   166  
   167  go 1.17
   168  
   169  require c v0.1.0
   170  -- b1/x/x.go --
   171  package x
   172  -- b1/y/y.go --
   173  package y
   174  
   175  import "c"
   176  
   177  func CVersion() string {
   178  	return c.Version
   179  }
   180  -- c1/go.mod --
   181  module c
   182  
   183  go 1.17
   184  -- c1/c.go --
   185  package c
   186  
   187  const Version = "v0.1.0"
   188  -- c2/go.mod --
   189  This file should be unused.
   190  -- c2/c.go --
   191  This file should be unused.
   192  

View as plain text