...

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

Documentation: cmd/go/testdata/script

     1# Return an error if the user tries to list a go source file directly in $GOROOT/src.
     2# Tests golang.org/issue/36587
     3
     4env GOROOT=$WORK/goroot
     5env GOPATH=$WORK/gopath
     6
     7go env GOROOT
     8stdout $WORK[/\\]goroot
     9
    10# switch to GOROOT/src
    11cd $GOROOT/src
    12
    13# In module mode, 'go list ./...' should not treat .go files in GOROOT/src as an
    14# importable package, since that directory has no valid import path.
    15env GO111MODULE=on
    16go list ...
    17stdout -count=1 '^.+$'
    18stdout '^fmt$'
    19! stdout foo
    20
    21go list ./...
    22stdout -count=1 '^.+$'
    23stdout '^fmt$'
    24! stdout foo
    25
    26go list std
    27stdout -count=1 '^.+$'
    28stdout '^fmt$'
    29
    30! go list .
    31stderr '^GOROOT/src is not an importable package$'
    32
    33# In GOPATH mode, 'go list ./...' should synthesize a legacy GOPATH-mode path —
    34# not a standard-library or empty path — for the errant package.
    35env GO111MODULE=off
    36go list ./...
    37stdout -count=2 '^.+$' # Both 'fmt' and GOROOT/src should be listed.
    38stdout '^fmt$'
    39[!GOOS:windows] stdout ^_$WORK/goroot/src$
    40[GOOS:windows] stdout goroot/src$ # On windows the ":" in the volume name is mangled
    41
    42go list ...
    43! stdout goroot/src
    44
    45go list std
    46! stdout goroot/src
    47
    48go list .
    49[!GOOS:windows] stdout ^_$WORK/goroot/src$
    50[GOOS:windows] stdout goroot/src$
    51
    52# switch to GOPATH/src
    53cd $GOPATH/src
    54
    55# GO111MODULE=off,GOPATH
    56env GO111MODULE=off
    57go list ./...
    58[!GOOS:windows] stdout ^_$WORK/gopath/src$
    59[GOOS:windows] stdout gopath/src$
    60
    61go list all
    62! stdout gopath/src
    63
    64-- $WORK/goroot/src/go.mod --
    65module std
    66
    67go 1.14
    68-- $WORK/goroot/src/foo.go --
    69package foo
    70-- $WORK/goroot/src/fmt/fmt.go --
    71package fmt
    72-- $WORK/goroot/src/cmd/README --
    73This directory must exist in order for the 'cmd' pattern to have something to
    74match against.
    75-- $GOPATH/src/foo.go --
    76package foo

View as plain text