From 8bec3911ad478b6fef8df96e4dc89f8080229133 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Tue, 17 Mar 2020 08:05:11 +0100 Subject: 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. --- pkg/ast/parser_test.go | 4 ++-- pkg/ast/test_util.go | 12 +++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) (limited to 'pkg/ast') 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) } } -- cgit mrf-deployment