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

     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.
     4  cd $WORK/gopath/src/mod
     5  ! go list .
     6  stderr '^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.
    13  cd $WORK/'gopath/src/m''d'
    14  ! go mod init
    15  stderr '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
    19  cd $WORK/gopath/src/badname
    20  ! go list .
    21  stderr '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.
    26  cd $WORK/gopath/src/dotname
    27  go list ./.dot
    28  stdout '^example.com/dotname/.dot$'
    29  go list ./use
    30  stdout '^example.com/dotname/use$'
    31  ! go list -m example.com/dotname/.dot@latest
    32  stderr '^go: example.com/dotname/.dot@latest: malformed module path "example.com/dotname/.dot": leading dot in path element$'
    33  go get example.com/dotname/.dot
    34  go get example.com/dotname/use
    35  go mod tidy
    36  
    37  -- mod/go.mod --
    38  
    39  -- mod/foo.go --
    40  package foo
    41  
    42  -- m'd/foo.go --
    43  package mad
    44  
    45  -- badname/go.mod --
    46  
    47  module .\.
    48  
    49  -- badname/foo.go --
    50  package badname
    51  
    52  -- dotname/go.mod --
    53  module example.com/dotname
    54  
    55  go 1.16
    56  -- dotname/.dot/dot.go --
    57  package dot
    58  -- dotname/use/use.go --
    59  package use
    60  
    61  import _ "example.com/dotname/.dot"
    62  

View as plain text