diff options
author | David Crawshaw <crawshaw@golang.org> | 2017-09-13 19:04:25 -0400 |
---|---|---|
committer | David Crawshaw <crawshaw@golang.org> | 2017-09-15 17:18:43 +0000 |
commit | 27e80f7c4d8001598367e15a1617fa524bd0fb11 (patch) | |
tree | 30eaac4762d4fd16c635ef629f358d2b7bdc09fa /src/cmd/compile/internal/syntax/parser_test.go | |
parent | af860838123548e67232373d86453cdc4838e9d6 (diff) | |
download | go-27e80f7c4d8001598367e15a1617fa524bd0fb11.tar.gz go-27e80f7c4d8001598367e15a1617fa524bd0fb11.zip |
cmd/compile: replace GOROOT in //line directives
The compiler replaces any path of the form /path/to/goroot/src/net/port.go
with GOROOT/src/net/port.go so that the same object file is
produced if the GOROOT is moved. It was skipping this transformation
for any absolute path into the GOROOT that came from //line directives,
such as those generated by cmd/cgo.
Fixes #21373
Fixes #21720
Fixes #21825
Change-Id: I2784c701b4391cfb92e23efbcb091a84957d61dd
Reviewed-on: https://go-review.googlesource.com/63693
Run-TryBot: David Crawshaw <crawshaw@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Diffstat (limited to 'src/cmd/compile/internal/syntax/parser_test.go')
-rw-r--r-- | src/cmd/compile/internal/syntax/parser_test.go | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/src/cmd/compile/internal/syntax/parser_test.go b/src/cmd/compile/internal/syntax/parser_test.go index 4c317dab60..0478088ec8 100644 --- a/src/cmd/compile/internal/syntax/parser_test.go +++ b/src/cmd/compile/internal/syntax/parser_test.go @@ -131,7 +131,7 @@ func verifyPrint(filename string, ast1 *File) { panic(err) } - ast2, err := ParseBytes(src.NewFileBase(filename, filename), buf1.Bytes(), nil, nil, 0) + ast2, err := ParseBytes(src.NewFileBase(filename, filename), buf1.Bytes(), nil, nil, nil, 0) if err != nil { panic(err) } @@ -155,7 +155,7 @@ func verifyPrint(filename string, ast1 *File) { } func TestIssue17697(t *testing.T) { - _, err := ParseBytes(nil, nil, nil, nil, 0) // return with parser error, don't panic + _, err := ParseBytes(nil, nil, nil, nil, nil, 0) // return with parser error, don't panic if err == nil { t.Errorf("no error reported") } @@ -199,8 +199,16 @@ func TestLineDirectives(t *testing.T) { // test effect of //line directive on (relative) position information {"//line foo:123\n foo", "syntax error: package statement must be first", "foo", 123 - linebase, 3}, {"//line foo:123\n//line bar:345\nfoo", "syntax error: package statement must be first", "bar", 345 - linebase, 0}, + + {"//line " + runtime.GOROOT() + "/src/a/a.go:123\n foo", "syntax error: package statement must be first", "$GOROOT/src/a/a.go", 123 - linebase, 3}, } { - _, err := ParseBytes(nil, []byte(test.src), nil, nil, 0) + fileh := func(name string) string { + if strings.HasPrefix(name, runtime.GOROOT()) { + return "$GOROOT" + name[len(runtime.GOROOT()):] + } + return name + } + _, err := ParseBytes(nil, []byte(test.src), nil, nil, fileh, 0) if err == nil { t.Errorf("%s: no error reported", test.src) continue |