...

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

Documentation: cmd/go/testdata/script

     1# https://golang.org/issue/36876: As of Go 1.17, vendor/modules.txt should
     2# indicate the language version used by each dependency.
     3
     4[short] skip
     5
     6# Control case: without a vendor directory, need117 builds and bad114 doesn't.
     7
     8go build example.net/need117
     9! go build example.net/bad114
    10stderr '^bad114[/\\]bad114.go:15:2: duplicate method .?Y.?( .*)?$'
    11
    12
    13# With a vendor/modules.txt lacking language versions, the world is topsy-turvy,
    14# because we have to guess a uniform version for everything.
    15#
    16# We always guess Go 1.16, because that was the last version for which
    17# 'go mod vendor' failed to record dependency versions, and it has most of
    18# the language features added since modules were introduced in Go 1.11.
    19#
    20# Even so, modules that declare 'go 1.17' and use 1.17 features spuriously fail
    21# to build, and modules that declare an older version and use features from a
    22# newer one spuriously build (instead of failing as they ought to).
    23
    24go mod vendor
    25
    26! grep 1.17 vendor/modules.txt
    27! go build example.net/need117
    28stderr '^vendor[/\\]example\.net[/\\]need117[/\\]need117.go:5:1[89]:'
    29stderr 'conversion of slice to array pointer requires go1\.17 or later'
    30
    31! grep 1.13 vendor/modules.txt
    32go build example.net/bad114
    33
    34
    35# Upgrading the main module to 1.17 adds version annotations.
    36# Then everything is once again consistent with the non-vendored world.
    37
    38go mod edit -go=1.17
    39go mod vendor
    40
    41grep '^## explicit; go 1.17$' vendor/modules.txt
    42go build example.net/need117
    43
    44grep '^## explicit; go 1.13$' vendor/modules.txt
    45! go build example.net/bad114
    46stderr '^vendor[/\\]example\.net[/\\]bad114[/\\]bad114.go:15:2: duplicate method .?Y.?( .*)?$'
    47
    48-- go.mod --
    49module example.net/m
    50
    51go 1.16
    52
    53require (
    54	example.net/bad114 v0.1.0
    55	example.net/need117 v0.1.0
    56)
    57
    58replace (
    59	example.net/bad114 v0.1.0 => ./bad114
    60	example.net/need117 v0.1.0 => ./need117
    61)
    62-- m.go --
    63package m
    64
    65import _ "example.net/bad114"
    66import _ "example.net/need117"
    67
    68-- bad114/go.mod --
    69// Module bad114 requires Go 1.14 or higher, but declares Go 1.13.
    70module example.net/bad114
    71
    72go 1.13
    73-- bad114/bad114.go --
    74package bad114
    75
    76type XY interface {
    77	X()
    78	Y()
    79}
    80
    81type YZ interface {
    82	Y()
    83	Z()
    84}
    85
    86type XYZ interface {
    87	XY
    88	YZ
    89}
    90
    91-- need117/go.mod --
    92// Module need117 requires Go 1.17 or higher.
    93module example.net/need117
    94
    95go 1.17
    96-- need117/need117.go --
    97package need117
    98
    99func init() {
   100		 s := make([]byte, 4)
   101		 _ = (*[4]byte)(s)
   102}

View as plain text