...

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

Documentation: cmd/go/testdata/script

     1env GO111MODULE=on
     2
     3# 'go list' should not add requirements even if they can be resolved locally.
     4cp go.mod go.mod.orig
     5! go list all
     6cmp go.mod go.mod.orig
     7
     8# 'go list' should resolve imports using replacements.
     9go get
    10go list all
    11stdout 'example.com/a/b$'
    12stdout 'example.com/x/v3$'
    13stdout 'example.com/y/z/w$'
    14stdout 'example.com/v'
    15
    16# The selected modules should prefer longer paths,
    17# but should try shorter paths if needed.
    18# Modules with a major-version suffix should have a corresponding pseudo-version.
    19# Replacements that specify a version should use the latest such version.
    20go list -m all
    21stdout 'example.com/a/b v0.0.0-00010101000000-000000000000 => ./b'
    22stdout 'example.com/y v0.0.0-00010101000000-000000000000 => ./y'
    23stdout 'example.com/x/v3 v3.0.0-00010101000000-000000000000 => ./v3'
    24stdout 'example.com/v v1.12.0 => ./v12'
    25
    26# The go command should print an informative error when the matched
    27# module does not contain a package.
    28# TODO(#26909): Ideally these errors should include line numbers for the imports within the main module.
    29cd fail
    30! go mod tidy
    31stderr '^go: localhost.fail imports\n\tw: module w@latest found \(v0.0.0-00010101000000-000000000000, replaced by ../w\), but does not contain package w$'
    32stderr '^go: localhost.fail imports\n\tnonexist: nonexist@v0.1.0: replacement directory ../nonexist does not exist$'
    33
    34-- go.mod --
    35module example.com/m
    36
    37replace (
    38	example.com/a => ./a
    39	example.com/a/b => ./b
    40)
    41
    42replace (
    43	example.com/x => ./x
    44	example.com/x/v3 => ./v3
    45)
    46
    47replace (
    48	example.com/y/z/w => ./w
    49	example.com/y => ./y
    50)
    51
    52replace (
    53	example.com/v v1.11.0 => ./v11
    54	example.com/v v1.12.0 => ./v12
    55	example.com/v => ./v
    56)
    57
    58replace (
    59	example.com/i v2.0.0+incompatible => ./i2
    60)
    61
    62-- m.go --
    63package main
    64import (
    65	_ "example.com/a/b"
    66	_ "example.com/x/v3"
    67	_ "example.com/y/z/w"
    68	_ "example.com/v"
    69	_ "example.com/i"
    70)
    71func main() {}
    72
    73-- a/go.mod --
    74module a.localhost
    75-- a/a.go --
    76package a
    77-- a/b/b.go--
    78package b
    79
    80-- b/go.mod --
    81module a.localhost/b
    82-- b/b.go --
    83package b
    84
    85-- x/go.mod --
    86module x.localhost
    87-- x/x.go --
    88package x
    89-- x/v3.go --
    90package v3
    91import _ "x.localhost/v3"
    92
    93-- v3/go.mod --
    94module x.localhost/v3
    95-- v3/x.go --
    96package x
    97
    98-- w/go.mod --
    99module w.localhost
   100-- w/skip/skip.go --
   101// Package skip is nested below nonexistent package w.
   102package skip
   103
   104-- y/go.mod --
   105module y.localhost
   106-- y/z/w/w.go --
   107package w
   108
   109-- v12/go.mod --
   110module v.localhost
   111-- v12/v.go --
   112package v
   113
   114-- v11/go.mod --
   115module v.localhost
   116-- v11/v.go --
   117package v
   118
   119-- v/go.mod --
   120module v.localhost
   121-- v/v.go --
   122package v
   123
   124-- i2/go.mod --
   125module example.com/i
   126-- i2/i.go --
   127package i
   128
   129-- fail/m.go --
   130package main
   131
   132import (
   133	_ "w"
   134	_ "nonexist"
   135)
   136
   137func main() {}
   138
   139-- fail/go.mod --
   140module localhost.fail
   141
   142replace w => ../w
   143
   144replace nonexist v0.1.0 => ../nonexist

View as plain text