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

     1  # This file demonstrates the effect of lazy loading on the selected
     2  # versions of test dependencies.
     3  
     4  # The package import graph used in this test looks like:
     5  #
     6  # m ---- a
     7  #  \     |
     8  #   \    a_test ---- b
     9  #    \               |
    10  #     x              b_test
    11  #     |                    \
    12  #     x_test -------------- c
    13  #
    14  # And the module dependency graph looks like:
    15  #
    16  # m -- a.1 -- b.1 -- c.2
    17  #  \
    18  #   x.1 ------------ c.1
    19  
    20  # Control case: in Go 1.15, the version of c imported by 'go test x' is the
    21  # version required by module b, even though b_test is not relevant to the main
    22  # module. (The main module imports a, and a_test imports b, but all of the
    23  # packages and tests in the main module can be built without b.)
    24  
    25  go list -m c
    26  stdout '^c v0.2.0 '
    27  
    28  [!short] go test -v x
    29  [!short] stdout ' c v0.2.0$'
    30  
    31  # With lazy loading, the go.mod requirements are the same,
    32  # but the irrelevant dependency on c v0.2.0 should be pruned out,
    33  # leaving only the relevant dependency on c v0.1.0.
    34  
    35  go mod edit -go=1.17
    36  go list -m c
    37  stdout '^c v0.1.0'
    38  
    39  [!short] go test -v x
    40  [!short] stdout ' c v0.1.0$'
    41  
    42  -- m.go --
    43  package m
    44  
    45  import (
    46  	_ "a"
    47  	_ "x"
    48  )
    49  -- go.mod --
    50  module m
    51  
    52  go 1.15
    53  
    54  require (
    55  	a v0.1.0
    56  	x v0.1.0
    57  )
    58  
    59  replace (
    60  	a v0.1.0 => ./a1
    61  	b v0.1.0 => ./b1
    62  	c v0.1.0 => ./c1
    63  	c v0.2.0 => ./c2
    64  	x v0.1.0 => ./x1
    65  )
    66  -- a1/go.mod --
    67  module a
    68  
    69  go 1.17
    70  
    71  require b v0.1.0
    72  -- a1/a.go --
    73  package a
    74  -- a1/a_test.go --
    75  package a_test
    76  
    77  import _ "b"
    78  -- b1/go.mod --
    79  module b
    80  
    81  go 1.17
    82  
    83  require c v0.2.0
    84  -- b1/b.go --
    85  package b
    86  -- b1/b_test.go --
    87  package b_test
    88  
    89  import (
    90  	"c"
    91  	"testing"
    92  )
    93  
    94  func TestCVersion(t *testing.T) {
    95  	t.Log(c.Version)
    96  }
    97  -- c1/go.mod --
    98  module c
    99  
   100  go 1.17
   101  -- c1/c.go --
   102  package c
   103  
   104  const Version = "v0.1.0"
   105  -- c2/go.mod --
   106  module c
   107  
   108  go 1.17
   109  -- c2/c.go --
   110  package c
   111  
   112  const Version = "v0.2.0"
   113  -- x1/go.mod --
   114  module x
   115  
   116  go 1.17
   117  
   118  require c v0.1.0
   119  -- x1/x.go --
   120  package x
   121  -- x1/x_test.go --
   122  package x_test
   123  
   124  import (
   125  	"c"
   126  	"testing"
   127  )
   128  
   129  func TestCVersion(t *testing.T) {
   130  	t.Log("c", c.Version)
   131  }
   132  

View as plain text