...

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

Documentation: cmd/go/testdata/script

     1# Verify that the compiler resolves a relative filename in a //line directive
     2# against the directory of the file containing the directive, not against
     3# the compiler's working directory.
     4# See go.dev/issue/70478.
     5
     6# Build from the module root: the resolved path should include the package dir.
     7! go build ./sub
     8stderr 'sub[/\\]README\.md:1: '
     9
    10# Build from a sibling directory (still inside the module): same resolved path.
    11mkdir other
    12cd other
    13! go build ../sub
    14stderr 'sub[/\\]README\.md:1: '
    15cd ..
    16
    17# Build from inside the package directory: the resolved path is anchored at
    18# that directory (which would not be the case under the pre-#70478 behavior,
    19# where the bare README.md was reported regardless of the build CWD).
    20cd sub
    21! go build .
    22stderr '\.[/\\]README\.md:1: '
    23
    24-- go.mod --
    25module example.com/linedirtest
    26
    27go 1.21
    28-- sub/foo.go --
    29package sub
    30
    31//line README.md:1
    32invalid

View as plain text