aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/syntax/scanner_test.go
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2016-11-08 16:01:56 -0800
committerRobert Griesemer <gri@golang.org>2016-11-09 17:48:40 +0000
commit60a9bf9f957d48856839873c6dcb699afe7da359 (patch)
tree019a1a18499cc6238a505c845129977db25873d6 /src/cmd/compile/internal/syntax/scanner_test.go
parentad020477f4dfe731450b6dd3dd15ea43aab0d0f1 (diff)
downloadgo-60a9bf9f957d48856839873c6dcb699afe7da359.tar.gz
go-60a9bf9f957d48856839873c6dcb699afe7da359.zip
cmd/compile/internal/syntax: fix error handling for Read/Parse calls
- define syntax.Error for cleaner error reporting - abort parsing after first error if no error handler is installed - make sure to always report the first error, if any - document behavior of API calls - while at it: rename ReadXXX -> ParseXXX (clearer) - adjust cmd/compile noder.go accordingly Fixes #17774. Change-Id: I7893eedea454a64acd753e32f7a8bf811ddbb03c Reviewed-on: https://go-review.googlesource.com/32950 Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Diffstat (limited to 'src/cmd/compile/internal/syntax/scanner_test.go')
-rw-r--r--src/cmd/compile/internal/syntax/scanner_test.go17
1 files changed, 9 insertions, 8 deletions
diff --git a/src/cmd/compile/internal/syntax/scanner_test.go b/src/cmd/compile/internal/syntax/scanner_test.go
index 38a7e0da4c..0e81c4e613 100644
--- a/src/cmd/compile/internal/syntax/scanner_test.go
+++ b/src/cmd/compile/internal/syntax/scanner_test.go
@@ -322,21 +322,22 @@ func TestScanErrors(t *testing.T) {
} {
var s scanner
nerrors := 0
- s.init(&bytesReader{[]byte(test.src)}, func(pos, line int, msg string) {
+ s.init(&bytesReader{[]byte(test.src)}, func(err error) {
nerrors++
// only check the first error
+ e := err.(Error) // we know it's an Error
if nerrors == 1 {
- if msg != test.msg {
- t.Errorf("%q: got msg = %q; want %q", test.src, msg, test.msg)
+ if e.Msg != test.msg {
+ t.Errorf("%q: got msg = %q; want %q", test.src, e.Msg, test.msg)
}
- if pos != test.pos {
- t.Errorf("%q: got pos = %d; want %d", test.src, pos, test.pos)
+ if e.Pos != test.pos {
+ t.Errorf("%q: got pos = %d; want %d", test.src, e.Pos, test.pos)
}
- if line != test.line {
- t.Errorf("%q: got line = %d; want %d", test.src, line, test.line)
+ if e.Line != test.line {
+ t.Errorf("%q: got line = %d; want %d", test.src, e.Line, test.line)
}
} else if nerrors > 1 {
- t.Errorf("%q: got unexpected %q at pos = %d, line = %d", test.src, msg, pos, line)
+ t.Errorf("%q: got unexpected %q at pos = %d, line = %d", test.src, e.Msg, e.Pos, e.Line)
}
}, nil)