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

     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
     8  stderr 'sub[/\\]README\.md:1: '
     9  
    10  # Build from a sibling directory (still inside the module): same resolved path.
    11  mkdir other
    12  cd other
    13  ! go build ../sub
    14  stderr 'sub[/\\]README\.md:1: '
    15  cd ..
    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).
    20  cd sub
    21  ! go build .
    22  stderr '\.[/\\]README\.md:1: '
    23  
    24  -- go.mod --
    25  module example.com/linedirtest
    26  
    27  go 1.21
    28  -- sub/foo.go --
    29  package sub
    30  
    31  //line README.md:1
    32  invalid
    33  

View as plain text