github.com/gagliardetto/golang-go@v0.0.0-20201020153340-53909ea70814/cmd/go/testdata/script/mod_ambiguous_import.txt (about)

     1  env GO111MODULE=on
     2  
     3  cd $WORK
     4  
     5  # An import provided by two different modules should be flagged as an error.
     6  ! go build ./importx
     7  stderr '^importx[/\\]importx.go:2:8: ambiguous import: found package example.com/a/x in multiple modules:\n\texample.com/a v0.1.0 \('$WORK'[/\\]a[/\\]x\)\n\texample.com/a/x v0.1.0 \('$WORK'[/\\]ax\)$'
     8  
     9  # However, it should not be an error if that import is unused.
    10  go build ./importy
    11  
    12  # An import provided by both the main module and the vendor directory
    13  # should be flagged as an error only when -mod=vendor is set.
    14  # TODO: This error message is a bit redundant.
    15  mkdir vendor/example.com/m/importy
    16  cp $WORK/importy/importy.go vendor/example.com/m/importy/importy.go
    17  go build example.com/m/importy
    18  ! go build -mod=vendor example.com/m/importy
    19  stderr '^can.t load package: package example.com/m/importy: ambiguous import: found package example.com/m/importy in multiple directories:\n\t'$WORK'[/\\]importy\n\t'$WORK'[/\\]vendor[/\\]example.com[/\\]m[/\\]importy$'
    20  
    21  -- $WORK/go.mod --
    22  module example.com/m
    23  go 1.13
    24  require (
    25  	example.com/a v0.1.0
    26  	example.com/a/x v0.1.0
    27  )
    28  replace (
    29  	example.com/a v0.1.0 => ./a
    30  	example.com/a/x v0.1.0 => ./ax
    31  )
    32  -- $WORK/importx/importx.go --
    33  package importx
    34  import _ "example.com/a/x"
    35  -- $WORK/importy/importy.go --
    36  package importy
    37  import _ "example.com/a/y"
    38  -- $WORK/a/go.mod --
    39  module example.com/a
    40  go 1.14
    41  -- $WORK/a/x/x.go --
    42  package x
    43  -- $WORK/a/y/y.go --
    44  package y
    45  -- $WORK/ax/go.mod --
    46  module example.com/a/x
    47  go 1.14
    48  -- $WORK/ax/x.go --
    49  package x