...

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

Documentation: cmd/go/testdata/script

     1# This test makes sure workspace mode's handling of the module graph
     2# is compatible with module pruning. The graph we load from either of
     3# the workspace modules should be the same, even if their graphs
     4# don't overlap.
     5#
     6# This is the module graph in the test:
     7#
     8#  example.com/a -> example.com/b v1.0.0 -> example.com/q v1.1.0
     9#  example.com/p -> example.com/q v1.0.0
    10#
    11# If we didn't load the whole graph and didn't load the dependencies of b
    12# when loading p, we would end up loading q v1.0.0, rather than v1.1.0,
    13# which is selected by MVS.
    14
    15go list -m -f '{{.Version}}' example.com/q
    16stdout '^v1.1.0$'
    17
    18-- go.work --
    19go 1.18
    20
    21use (
    22	./a
    23	./p
    24)
    25-- a/go.mod --
    26module example.com/a
    27
    28go 1.18
    29
    30require example.com/b v1.0.0
    31
    32replace example.com/b v1.0.0 => ../b
    33-- a/foo.go --
    34package main
    35
    36import "example.com/b"
    37
    38func main() {
    39	b.B()
    40}
    41-- b/go.mod --
    42module example.com/b
    43
    44go 1.18
    45
    46require example.com/q v1.1.0
    47
    48replace example.com/q v1.0.0 => ../q1_0_0
    49replace example.com/q v1.1.0 => ../q1_1_0
    50-- b/b.go --
    51package b
    52
    53func B() {
    54}
    55-- b/b_test.go --
    56package b
    57
    58import "example.com/q"
    59
    60func TestB() {
    61	q.PrintVersion()
    62}
    63-- p/go.mod --
    64module example.com/p
    65
    66go 1.18
    67
    68require example.com/q v1.0.0
    69
    70replace example.com/q v1.0.0 => ../q1_0_0
    71replace example.com/q v1.1.0 => ../q1_1_0
    72-- p/main.go --
    73package main
    74
    75import "example.com/q"
    76
    77func main() {
    78	q.PrintVersion()
    79}
    80-- q1_0_0/go.mod --
    81module example.com/q
    82
    83go 1.18
    84-- q1_0_0/q.go --
    85package q
    86
    87import "fmt"
    88
    89func PrintVersion() {
    90	fmt.Println("version 1.0.0")
    91}
    92-- q1_1_0/go.mod --
    93module example.com/q
    94
    95go 1.18
    96-- q1_1_0/q.go --
    97package q
    98
    99import "fmt"
   100
   101func PrintVersion() {
   102	fmt.Println("version 1.1.0")
   103}

View as plain text