From 115060400cbaa12c11847f05b12452f0dd5ff7d4 Mon Sep 17 00:00:00 2001 From: TSUYUSATO Kitsune Date: Thu, 31 Oct 2024 20:53:30 +0900 Subject: [PATCH] Fix test to expect parsing errors for testdata/*/bad_*.sql --- parser_test.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/parser_test.go b/parser_test.go index f5fabf72..66df1c39 100644 --- a/parser_test.go +++ b/parser_test.go @@ -7,6 +7,7 @@ import ( "log" "os" "path/filepath" + "strings" "testing" "github.com/cloudspannerecosystem/memefish" @@ -40,6 +41,7 @@ func testParser(t *testing.T, inputPath, resultPath string, parse func(p *memefi for _, in := range inputs { in := in + bad := strings.HasPrefix(in.Name(), "bad_") t.Run(in.Name(), func(t *testing.T) { t.Parallel() @@ -68,9 +70,17 @@ func testParser(t *testing.T, inputPath, resultPath string, parse func(p *memefi fmt.Fprintln(&buf) if err != nil { - fmt.Fprintln(&buf, "--- Error") - fmt.Fprint(&buf, err) - fmt.Fprintln(&buf) + if bad { + fmt.Fprintln(&buf, "--- Error") + fmt.Fprint(&buf, err) + fmt.Fprintln(&buf) + } else { + t.Errorf("unexpected error: %v", err) + } + } else { + if bad { + t.Errorf("error is expected, but parsing succeeded") + } } fmt.Fprintf(&buf, "--- AST\n")