aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoralandonovan <adonovan@google.com>2018-12-17 12:42:36 -0500
committerGitHub <noreply@github.com>2018-12-17 12:42:36 -0500
commitf817a90cc1dd428784244707ce9ca4ac6f38722a (patch)
tree31e5ff444208e2ee6d6eb28bfa2c6e84ec2f5346
parent88085a499633e675c9b29c3ff8ea2073480047a5 (diff)
downloadstarlark-go-f817a90cc1dd428784244707ce9ca4ac6f38722a.tar.gz
internal/chunkedfile: print newline before file:line:col errors (#75)
The test framework adds its own such prefix, confusing editors. Putting them on separate lines makes it easier to step through.
-rw-r--r--internal/chunkedfile/chunkedfile.go14
1 files changed, 9 insertions, 5 deletions
diff --git a/internal/chunkedfile/chunkedfile.go b/internal/chunkedfile/chunkedfile.go
index a13cea9..a591524 100644
--- a/internal/chunkedfile/chunkedfile.go
+++ b/internal/chunkedfile/chunkedfile.go
@@ -50,6 +50,10 @@ type Reporter interface {
// Read parses a chunked file and returns its chunks.
// It reports failures using the reporter.
+//
+// Error messages of the form "file.star:line:col: ..." are prefixed
+// by a newline so that the Go source position added by (*testing.T).Errorf
+// appears on a separate line so as not to confused editors.
func Read(filename string, report Reporter) (chunks []Chunk) {
data, err := ioutil.ReadFile(filename)
if err != nil {
@@ -78,12 +82,12 @@ func Read(filename string, report Reporter) (chunks []Chunk) {
rest := strings.TrimSpace(line[hashes+len("###"):])
pattern, err := strconv.Unquote(rest)
if err != nil {
- report.Errorf("%s:%d: not a quoted regexp: %s", filename, linenum, rest)
+ report.Errorf("\n%s:%d: not a quoted regexp: %s", filename, linenum, rest)
continue
}
rx, err := regexp.Compile(pattern)
if err != nil {
- report.Errorf("%s:%d: %v", filename, linenum, err)
+ report.Errorf("\n%s:%d: %v", filename, linenum, err)
continue
}
wantErrs[linenum] = rx
@@ -104,10 +108,10 @@ func (chunk *Chunk) GotError(linenum int, msg string) {
if rx, ok := chunk.wantErrs[linenum]; ok {
delete(chunk.wantErrs, linenum)
if !rx.MatchString(msg) {
- chunk.report.Errorf("%s:%d: error %q does not match pattern %q", chunk.filename, linenum, msg, rx)
+ chunk.report.Errorf("\n%s:%d: error %q does not match pattern %q", chunk.filename, linenum, msg, rx)
}
} else {
- chunk.report.Errorf("%s:%d: unexpected error: %v", chunk.filename, linenum, msg)
+ chunk.report.Errorf("\n%s:%d: unexpected error: %v", chunk.filename, linenum, msg)
}
}
@@ -115,6 +119,6 @@ func (chunk *Chunk) GotError(linenum int, msg string) {
// Done reports expected errors that did not occur to the chunk's reporter.
func (chunk *Chunk) Done() {
for linenum, rx := range chunk.wantErrs {
- chunk.report.Errorf("%s:%d: expected error matching %q", chunk.filename, linenum, rx)
+ chunk.report.Errorf("\n%s:%d: expected error matching %q", chunk.filename, linenum, rx)
}
}