...

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

Documentation: cmd/go/testdata/script

     1env GO111MODULE=on
     2
     3cd $WORK
     4
     5# An import provided by two different modules should be flagged as an error.
     6! go build ./importx
     7stderr '^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.
    10go 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.
    14mkdir vendor/example.com/m/importy
    15cp $WORK/importy/importy.go vendor/example.com/m/importy/importy.go
    16go build example.com/m/importy
    17! go build -mod=vendor example.com/m/importy
    18stderr '^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 --
    21module example.com/m
    22go 1.13
    23require (
    24	example.com/a v0.1.0
    25	example.com/a/x v0.1.0
    26)
    27replace (
    28	example.com/a v0.1.0 => ./a
    29	example.com/a/x v0.1.0 => ./ax
    30)
    31-- $WORK/importx/importx.go --
    32package importx
    33import _ "example.com/a/x"
    34-- $WORK/importy/importy.go --
    35package importy
    36import _ "example.com/a/y"
    37-- $WORK/a/go.mod --
    38module example.com/a
    39go 1.14
    40-- $WORK/a/x/x.go --
    41package x
    42-- $WORK/a/y/y.go --
    43package y
    44-- $WORK/ax/go.mod --
    45module example.com/a/x
    46go 1.14
    47-- $WORK/ax/x.go --
    48package x

View as plain text