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

     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  mkdir vendor/example.com/m/importy
    15  cp $WORK/importy/importy.go vendor/example.com/m/importy/importy.go
    16  go build example.com/m/importy
    17  ! go build -mod=vendor example.com/m/importy
    18  stderr '^ambiguous import: found package example.com/m/importy in multiple directories:\n\t'$WORK'[/\\]importy\n\t'$WORK'[/\\]vendor[/\\]example.com[/\\]m[/\\]importy$'
    19  
    20  -- $WORK/go.mod --
    21  module example.com/m
    22  go 1.13
    23  require (
    24  	example.com/a v0.1.0
    25  	example.com/a/x v0.1.0
    26  )
    27  replace (
    28  	example.com/a v0.1.0 => ./a
    29  	example.com/a/x v0.1.0 => ./ax
    30  )
    31  -- $WORK/importx/importx.go --
    32  package importx
    33  import _ "example.com/a/x"
    34  -- $WORK/importy/importy.go --
    35  package importy
    36  import _ "example.com/a/y"
    37  -- $WORK/a/go.mod --
    38  module example.com/a
    39  go 1.14
    40  -- $WORK/a/x/x.go --
    41  package x
    42  -- $WORK/a/y/y.go --
    43  package y
    44  -- $WORK/ax/go.mod --
    45  module example.com/a/x
    46  go 1.14
    47  -- $WORK/ax/x.go --
    48  package x
    49  

View as plain text