2013-12-13 11:39:26 +01:00
|
|
|
|
2013-12-19 10:46:51 +01:00
|
|
|
This is the main tests module which exposes the test data plus the
|
|
|
|
Test.Framework tests. It also contains the code which converts the
|
|
|
|
test data to the Test.Framework tests.
|
2013-12-16 12:33:05 +01:00
|
|
|
|
2013-12-14 19:42:01 +01:00
|
|
|
> module Language.SQL.SimpleSQL.Tests
|
|
|
|
> (testData
|
|
|
|
> ,tests
|
|
|
|
> ,TestItem(..)
|
|
|
|
> ) where
|
2013-12-13 11:39:26 +01:00
|
|
|
|
2015-07-31 11:45:51 +02:00
|
|
|
> import qualified Test.Tasty as T
|
|
|
|
> import qualified Test.Tasty.HUnit as H
|
2013-12-13 11:39:26 +01:00
|
|
|
|
2013-12-17 11:16:03 +01:00
|
|
|
> --import Language.SQL.SimpleSQL.Syntax
|
2013-12-17 10:40:31 +01:00
|
|
|
> import Language.SQL.SimpleSQL.Pretty
|
2016-02-12 11:22:19 +01:00
|
|
|
> import Language.SQL.SimpleSQL.Parse
|
|
|
|
> import Language.SQL.SimpleSQL.Lex
|
2013-12-16 09:03:46 +01:00
|
|
|
|
2013-12-17 10:40:31 +01:00
|
|
|
> import Language.SQL.SimpleSQL.TestTypes
|
2013-12-13 23:58:12 +01:00
|
|
|
|
2013-12-17 10:40:31 +01:00
|
|
|
> import Language.SQL.SimpleSQL.FullQueries
|
2013-12-17 18:17:03 +01:00
|
|
|
> import Language.SQL.SimpleSQL.GroupBy
|
2013-12-17 10:40:31 +01:00
|
|
|
> import Language.SQL.SimpleSQL.Postgres
|
2013-12-17 10:48:40 +01:00
|
|
|
> import Language.SQL.SimpleSQL.QueryExprComponents
|
|
|
|
> import Language.SQL.SimpleSQL.QueryExprs
|
2013-12-17 10:40:31 +01:00
|
|
|
> import Language.SQL.SimpleSQL.TableRefs
|
2013-12-19 10:46:51 +01:00
|
|
|
> import Language.SQL.SimpleSQL.ValueExprs
|
2013-12-17 10:40:31 +01:00
|
|
|
> import Language.SQL.SimpleSQL.Tpch
|
2015-07-31 23:04:18 +02:00
|
|
|
> import Language.SQL.SimpleSQL.LexerTests
|
2013-12-13 23:58:12 +01:00
|
|
|
|
2015-08-01 17:08:54 +02:00
|
|
|
> import Language.SQL.SimpleSQL.SQL2011Queries
|
|
|
|
> import Language.SQL.SimpleSQL.SQL2011AccessControl
|
|
|
|
> import Language.SQL.SimpleSQL.SQL2011Bits
|
|
|
|
> import Language.SQL.SimpleSQL.SQL2011DataManipulation
|
|
|
|
> import Language.SQL.SimpleSQL.SQL2011Schema
|
2013-12-13 11:39:26 +01:00
|
|
|
|
2014-06-27 11:19:15 +02:00
|
|
|
> import Language.SQL.SimpleSQL.MySQL
|
|
|
|
|
2013-12-17 10:48:40 +01:00
|
|
|
Order the tests to start from the simplest first. This is also the
|
|
|
|
order on the generated documentation.
|
2013-12-13 17:50:41 +01:00
|
|
|
|
2013-12-13 11:39:26 +01:00
|
|
|
> testData :: TestItem
|
|
|
|
> testData =
|
|
|
|
> Group "parserTest"
|
2015-07-31 23:04:18 +02:00
|
|
|
> [lexerTests
|
|
|
|
> ,valueExprTests
|
2013-12-17 10:48:40 +01:00
|
|
|
> ,queryExprComponentTests
|
|
|
|
> ,queryExprsTests
|
2013-12-17 18:17:03 +01:00
|
|
|
> ,tableRefTests
|
|
|
|
> ,groupByTests
|
2013-12-17 10:48:40 +01:00
|
|
|
> ,fullQueriesTests
|
|
|
|
> ,postgresTests
|
2013-12-13 23:07:45 +01:00
|
|
|
> ,tpchTests
|
2015-08-01 17:08:54 +02:00
|
|
|
> ,sql2011QueryTests
|
|
|
|
> ,sql2011DataManipulationTests
|
|
|
|
> ,sql2011SchemaTests
|
|
|
|
> ,sql2011AccessControlTests
|
|
|
|
> ,sql2011BitsTests
|
2014-06-27 11:19:15 +02:00
|
|
|
> ,mySQLTests
|
2013-12-13 19:24:20 +01:00
|
|
|
> ]
|
2013-12-13 13:08:33 +01:00
|
|
|
|
2015-07-31 11:45:51 +02:00
|
|
|
> tests :: T.TestTree
|
2013-12-14 19:42:01 +01:00
|
|
|
> tests = itemToTest testData
|
2013-12-13 13:08:33 +01:00
|
|
|
|
2013-12-14 19:42:01 +01:00
|
|
|
> --runTests :: IO ()
|
|
|
|
> --runTests = void $ H.runTestTT $ itemToTest testData
|
2013-12-13 13:08:33 +01:00
|
|
|
|
2015-07-31 11:45:51 +02:00
|
|
|
> itemToTest :: TestItem -> T.TestTree
|
2013-12-13 13:08:33 +01:00
|
|
|
> itemToTest (Group nm ts) =
|
2015-07-31 11:45:51 +02:00
|
|
|
> T.testGroup nm $ map itemToTest ts
|
2014-06-27 11:19:15 +02:00
|
|
|
> itemToTest (TestValueExpr d str expected) =
|
|
|
|
> toTest parseValueExpr prettyValueExpr d str expected
|
|
|
|
> itemToTest (TestQueryExpr d str expected) =
|
|
|
|
> toTest parseQueryExpr prettyQueryExpr d str expected
|
2015-08-01 19:26:00 +02:00
|
|
|
> itemToTest (TestStatement d str expected) =
|
|
|
|
> toTest parseStatement prettyStatement d str expected
|
|
|
|
> itemToTest (TestStatements d str expected) =
|
|
|
|
> toTest parseStatements prettyStatements d str expected
|
2014-06-27 11:19:15 +02:00
|
|
|
> itemToTest (ParseQueryExpr d str) =
|
|
|
|
> toPTest parseQueryExpr prettyQueryExpr d str
|
2013-12-13 13:08:33 +01:00
|
|
|
|
2014-06-28 14:41:11 +02:00
|
|
|
> itemToTest (ParseQueryExprFails d str) =
|
|
|
|
> toFTest parseQueryExpr prettyQueryExpr d str
|
|
|
|
|
|
|
|
> itemToTest (ParseValueExprFails d str) =
|
|
|
|
> toFTest parseValueExpr prettyValueExpr d str
|
|
|
|
|
2016-02-15 19:31:06 +01:00
|
|
|
> itemToTest (LexTest d s ts) = makeLexerTest d s ts
|
|
|
|
> itemToTest (LexFails d s) = makeLexingFailsTest d s
|
2015-07-31 23:04:18 +02:00
|
|
|
|
|
|
|
> makeLexerTest :: Dialect -> String -> [Token] -> T.TestTree
|
|
|
|
> makeLexerTest d s ts = H.testCase s $ do
|
2015-08-01 11:13:53 +02:00
|
|
|
> let lx = either (error . show) id $ lexSQL d "" Nothing s
|
2015-07-31 23:04:18 +02:00
|
|
|
> H.assertEqual "" ts $ map snd lx
|
|
|
|
> let s' = prettyTokens d $ map snd lx
|
|
|
|
> H.assertEqual "pretty print" s s'
|
2014-06-28 14:41:11 +02:00
|
|
|
|
2016-02-15 19:31:06 +01:00
|
|
|
> makeLexingFailsTest :: Dialect -> String -> T.TestTree
|
|
|
|
> makeLexingFailsTest d s = H.testCase s $ do
|
|
|
|
> case lexSQL d "" Nothing s of
|
|
|
|
> Right x -> H.assertFailure $ "lexing should have failed: " ++ s ++ "\ngot: " ++ show x
|
|
|
|
> Left _ -> return ()
|
|
|
|
|
|
|
|
|
2013-12-13 18:21:44 +01:00
|
|
|
> toTest :: (Eq a, Show a) =>
|
2014-06-27 11:19:15 +02:00
|
|
|
> (Dialect -> String -> Maybe (Int,Int) -> String -> Either ParseError a)
|
|
|
|
> -> (Dialect -> a -> String)
|
|
|
|
> -> Dialect
|
2013-12-13 14:05:32 +01:00
|
|
|
> -> String
|
|
|
|
> -> a
|
2015-07-31 11:45:51 +02:00
|
|
|
> -> T.TestTree
|
|
|
|
> toTest parser pp d str expected = H.testCase str $ do
|
2014-06-27 11:19:15 +02:00
|
|
|
> let egot = parser d "" Nothing str
|
2013-12-13 13:08:33 +01:00
|
|
|
> case egot of
|
2013-12-13 18:21:44 +01:00
|
|
|
> Left e -> H.assertFailure $ peFormattedError e
|
2013-12-13 14:05:32 +01:00
|
|
|
> Right got -> do
|
|
|
|
> H.assertEqual "" expected got
|
2014-06-27 11:19:15 +02:00
|
|
|
> let str' = pp d got
|
|
|
|
> let egot' = parser d "" Nothing str'
|
2013-12-13 14:05:32 +01:00
|
|
|
> case egot' of
|
2014-04-15 12:47:34 +02:00
|
|
|
> Left e' -> H.assertFailure $ "pp roundtrip"
|
|
|
|
> ++ "\n" ++ str'
|
2013-12-16 09:03:46 +01:00
|
|
|
> ++ peFormattedError e'
|
2014-04-15 12:47:34 +02:00
|
|
|
> Right got' -> H.assertEqual
|
|
|
|
> ("pp roundtrip" ++ "\n" ++ str')
|
|
|
|
> expected got'
|
2013-12-13 17:50:41 +01:00
|
|
|
|
2013-12-13 18:21:44 +01:00
|
|
|
> toPTest :: (Eq a, Show a) =>
|
2014-06-27 11:19:15 +02:00
|
|
|
> (Dialect -> String -> Maybe (Int,Int) -> String -> Either ParseError a)
|
|
|
|
> -> (Dialect -> a -> String)
|
|
|
|
> -> Dialect
|
2013-12-13 17:50:41 +01:00
|
|
|
> -> String
|
2015-07-31 11:45:51 +02:00
|
|
|
> -> T.TestTree
|
|
|
|
> toPTest parser pp d str = H.testCase str $ do
|
2014-06-27 11:19:15 +02:00
|
|
|
> let egot = parser d "" Nothing str
|
2013-12-13 17:50:41 +01:00
|
|
|
> case egot of
|
2013-12-13 18:21:44 +01:00
|
|
|
> Left e -> H.assertFailure $ peFormattedError e
|
2013-12-13 17:50:41 +01:00
|
|
|
> Right got -> do
|
2014-06-27 11:19:15 +02:00
|
|
|
> let str' = pp d got
|
|
|
|
> let egot' = parser d "" Nothing str'
|
2013-12-13 17:50:41 +01:00
|
|
|
> case egot' of
|
2013-12-16 09:03:46 +01:00
|
|
|
> Left e' -> H.assertFailure $ "pp roundtrip "
|
2014-04-15 12:47:34 +02:00
|
|
|
> ++ "\n" ++ str' ++ "\n"
|
2013-12-16 09:03:46 +01:00
|
|
|
> ++ peFormattedError e'
|
2013-12-13 18:21:44 +01:00
|
|
|
> Right _got' -> return ()
|
2014-06-28 14:41:11 +02:00
|
|
|
|
|
|
|
|
|
|
|
> toFTest :: (Eq a, Show a) =>
|
|
|
|
> (Dialect -> String -> Maybe (Int,Int) -> String -> Either ParseError a)
|
|
|
|
> -> (Dialect -> a -> String)
|
|
|
|
> -> Dialect
|
|
|
|
> -> String
|
2015-07-31 11:45:51 +02:00
|
|
|
> -> T.TestTree
|
2015-07-31 23:04:18 +02:00
|
|
|
> toFTest parser _pp d str = H.testCase str $ do
|
2014-06-28 14:41:11 +02:00
|
|
|
> let egot = parser d "" Nothing str
|
|
|
|
> case egot of
|
2015-07-31 23:04:18 +02:00
|
|
|
> Left _e -> return ()
|
|
|
|
> Right _got ->
|
2014-06-28 14:41:11 +02:00
|
|
|
> H.assertFailure $ "parse didn't fail: " ++ show d ++ "\n" ++ str
|