1
Fork 0

switch tests to hspec, improve error messages

This commit is contained in:
Jake Wheat 2024-02-04 16:00:59 +00:00
parent fadd010942
commit c11bee4a9c
36 changed files with 2570 additions and 1809 deletions

View file

@ -20,26 +20,28 @@ doc _ (Group nm _) | "generated" `T.isInfixOf` nm = []
doc n (Group nm is) =
Heading n (L.fromStrict nm)
: concatMap (doc (n + 1)) is
doc _ (TestScalarExpr _ str e) =
doc _ (TestScalarExpr _ str e _) =
[Row (L.fromStrict str) (L.pack $ ppShow e)]
doc _ (TestQueryExpr _ str e) =
doc _ (TestQueryExpr _ str e _) =
[Row (L.fromStrict str) (L.pack $ ppShow e)]
doc _ (TestStatement _ str e) =
doc _ (TestStatement _ str e _) =
[Row (L.fromStrict str) (L.pack $ ppShow e)]
doc _ (TestStatements _ str e) =
doc _ (TestStatements _ str e _) =
[Row (L.fromStrict str) (L.pack $ ppShow e)]
doc _ (ParseQueryExpr d str) =
doc _ (ParseQueryExpr d str _) =
[Row (L.fromStrict str) (showResult $ P.parseQueryExpr d "" Nothing str)]
doc _ (ParseQueryExprFails d str) =
doc _ (ParseQueryExprFails d str _) =
[Row (L.fromStrict str) (showResult $ P.parseQueryExpr d "" Nothing str)]
doc _ (ParseScalarExprFails d str) =
doc _ (ParseScalarExprFails d str _) =
[Row (L.fromStrict str) (showResult $ P.parseScalarExpr d "" Nothing str)]
doc _ (LexTest d str _) =
[Row (L.fromStrict str) (showResultL $ L.lexSQL d "" Nothing str)]
doc _ (LexTest d str _ _) =
[Row (L.fromStrict str) (showResultL $ L.lexSQL d False "" Nothing str)]
doc _ (LexFails d str _) =
[Row (L.fromStrict str) (showResultL $ L.lexSQL d False "" Nothing str)]
doc _ (GeneralParseFailTest {}) = []
doc _ (LexFails d str) =
[Row (L.fromStrict str) (showResultL $ L.lexSQL d "" Nothing str)]
showResult :: Show a => Either P.ParseError a -> L.Text
showResult = either (("Left\n" <>) . L.fromStrict . P.prettyError) (L.pack . ppShow)

View file

@ -184,6 +184,8 @@ generally available to work on these, so you should either make a pull
request, or find someone willing to implement the features and make a
pull request.
Bug reports of confusing or poor parse errors are also encouraged.
There is a related tutorial on implementing a SQL parser here:
<http://jakewheat.github.io/intro_to_parsing/> (TODO: this is out of
date, in the process of being updated)
@ -210,6 +212,13 @@ Or use the makefile target
make test
~~~~
To skip some of the slow lexer tests, which you usually only need to
run before each commit, use:
~~~~
make fast-test
~~~~
When you add support for new syntax: add some tests. If you modify or
fix something, and it doesn't have tests, add some. If the syntax
isn't in ANSI SQL, guard it behind a dialect flag. If you add

View file

@ -1,7 +1,7 @@
cabal-version: 2.2
name: simple-sql-parser
version: 0.7.1
version: 0.8.0
executable RenderTestCases
main-is: RenderTestCases.hs
@ -13,9 +13,11 @@ executable RenderTestCases
parser-combinators,
mtl,
containers,
tasty,
tasty-hunit,
hspec,
hspec-megaparsec,
pretty-show,
hspec-expectations,
raw-strings-qq,
default-language: Haskell2010
ghc-options: -Wall -O0
@ -47,3 +49,6 @@ executable RenderTestCases
Language.SQL.SimpleSQL.TestTypes
Language.SQL.SimpleSQL.Tests
Language.SQL.SimpleSQL.Tpch
Language.SQL.SimpleSQL.Expectations
Language.SQL.SimpleSQL.TestRunners
Language.SQL.SimpleSQL.ErrorMessages