aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/ast
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2020-03-17 08:05:11 +0100
committerDmitry Vyukov <dvyukov@google.com>2020-03-17 21:19:13 +0100
commit8bec3911ad478b6fef8df96e4dc89f8080229133 (patch)
treef7219cc336de08b708b776722588e090e745130a /pkg/ast
parent924f7606047a430a9b313c135b782e1e8f852bec (diff)
pkg/compiler: add tests for generation phase
Add errors3.txt with tests for errors that are produced during generation phase. Refactor tests to reduce duplication. Tidy struct/union size errors: better locations and make testable.
Diffstat (limited to 'pkg/ast')
-rw-r--r--pkg/ast/parser_test.go4
-rw-r--r--pkg/ast/test_util.go12
2 files changed, 9 insertions, 7 deletions
diff --git a/pkg/ast/parser_test.go b/pkg/ast/parser_test.go
index f1458e3e7..edbabf3d3 100644
--- a/pkg/ast/parser_test.go
+++ b/pkg/ast/parser_test.go
@@ -108,13 +108,13 @@ func TestErrors(t *testing.T) {
em := NewErrorMatcher(t, filepath.Join("testdata", name))
desc := Parse(em.Data, name, em.ErrorHandler)
if desc != nil && em.Count() != 0 {
- em.DumpErrors(t)
+ em.DumpErrors()
t.Fatalf("parsing succeed, but got errors")
}
if desc == nil && em.Count() == 0 {
t.Fatalf("parsing failed, but got no errors")
}
- em.Check(t)
+ em.Check()
})
}
}
diff --git a/pkg/ast/test_util.go b/pkg/ast/test_util.go
index 3ffefcccb..741bed553 100644
--- a/pkg/ast/test_util.go
+++ b/pkg/ast/test_util.go
@@ -14,6 +14,7 @@ import (
)
type ErrorMatcher struct {
+ t *testing.T
Data []byte
expect []*errorDesc
got []*errorDesc
@@ -56,6 +57,7 @@ func NewErrorMatcher(t *testing.T, file string) *ErrorMatcher {
t.Fatalf("failed to scan input file: %v", err)
}
return &ErrorMatcher{
+ t: t,
Data: stripped,
expect: errors,
}
@@ -79,7 +81,7 @@ func (em *ErrorMatcher) Count() int {
return len(em.got)
}
-func (em *ErrorMatcher) Check(t *testing.T) {
+func (em *ErrorMatcher) Check() {
nextErr:
for _, e := range em.got {
for _, want := range em.expect {
@@ -89,18 +91,18 @@ nextErr:
want.matched = true
continue nextErr
}
- t.Errorf("unexpected error:\n%v:%v:%v: %v", e.file, e.line, e.col, e.text)
+ em.t.Errorf("unexpected error:\n%v:%v:%v: %v", e.file, e.line, e.col, e.text)
}
for _, want := range em.expect {
if want.matched {
continue
}
- t.Errorf("unmatched error:\n%v:%v: %v", want.file, want.line, want.text)
+ em.t.Errorf("unmatched error:\n%v:%v: %v", want.file, want.line, want.text)
}
}
-func (em *ErrorMatcher) DumpErrors(t *testing.T) {
+func (em *ErrorMatcher) DumpErrors() {
for _, e := range em.got {
- t.Logf("%v:%v:%v: %v", e.file, e.line, e.col, e.text)
+ em.t.Logf("%v:%v:%v: %v", e.file, e.line, e.col, e.text)
}
}