...

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

Documentation: cmd/go/testdata/script

     1# Test that mod files with invalid or missing paths produce an error.
     2
     3# Test that go list fails on a go.mod with no module declaration.
     4cd $WORK/gopath/src/mod
     5! go list .
     6stderr '^go: error reading go.mod: missing module declaration. To specify the module path:\n\tgo mod edit -module=example.com/mod$'
     7
     8# Test that go mod init in GOPATH doesn't add a module declaration
     9# with a path that can't possibly be a module path, because
    10# it isn't even a valid import path.
    11# The single quote and backtick are the only characters which are not allowed
    12# but are a valid Windows file name.
    13cd $WORK/'gopath/src/m''d'
    14! go mod init
    15stderr 'cannot determine module path'
    16
    17# Test that a go.mod file is rejected when its module declaration has a path that can't
    18# possibly be a module path, because it isn't even a valid import path
    19cd $WORK/gopath/src/badname
    20! go list .
    21stderr 'malformed module path'
    22
    23# Test that an import path containing an element with a leading dot is valid,
    24# but such a module path is not.
    25# Verifies #43985.
    26cd $WORK/gopath/src/dotname
    27go list ./.dot
    28stdout '^example.com/dotname/.dot$'
    29go list ./use
    30stdout '^example.com/dotname/use$'
    31! go list -m example.com/dotname/.dot@latest
    32stderr '^go: example.com/dotname/.dot@latest: malformed module path "example.com/dotname/.dot": leading dot in path element$'
    33go get example.com/dotname/.dot
    34go get example.com/dotname/use
    35go mod tidy
    36
    37-- mod/go.mod --
    38
    39-- mod/foo.go --
    40package foo
    41
    42-- m'd/foo.go --
    43package mad
    44
    45-- badname/go.mod --
    46
    47module .\.
    48
    49-- badname/foo.go --
    50package badname
    51
    52-- dotname/go.mod --
    53module example.com/dotname
    54
    55go 1.16
    56-- dotname/.dot/dot.go --
    57package dot
    58-- dotname/use/use.go --
    59package use
    60
    61import _ "example.com/dotname/.dot"

View as plain text