diff options
| author | Albert Krewinkel <albert@zeitkraut.de> | 2019-05-20 18:52:28 +0200 |
|---|---|---|
| committer | John MacFarlane <jgm@berkeley.edu> | 2019-05-20 12:52:28 -0400 |
| commit | 6208d4e7fcf1792203b3069d0002ad5cb1ec05dd (patch) | |
| tree | 4aa85637c54ffaf67b950c1ed3c9ff7ce9a940de /test/Tests | |
| parent | 90141e7b4fc48477106ee5481e3d9b1b4a54338e (diff) | |
| download | pandoc-6208d4e7fcf1792203b3069d0002ad5cb1ec05dd.tar.gz | |
Improve output of Lua tests (#5499)
This makes use of tasty-lua, a package to write tests in Lua
and integrate the results into Tasty output. Test output becomes
more informative: individual tests and test groups become visible
in test output. Failures are reported with helpful error messages.
Diffstat (limited to 'test/Tests')
| -rw-r--r-- | test/Tests/Lua.hs | 36 | ||||
| -rw-r--r-- | test/Tests/Lua/Module.hs | 27 |
2 files changed, 37 insertions, 26 deletions
diff --git a/test/Tests/Lua.hs b/test/Tests/Lua.hs index 4040c38ac..c585182e4 100644 --- a/test/Tests/Lua.hs +++ b/test/Tests/Lua.hs @@ -11,7 +11,7 @@ Unit and integration tests for pandoc's Lua subsystem. -} -module Tests.Lua ( tests ) where +module Tests.Lua ( runLuaTest, tests ) where import Prelude import Control.Monad (when) @@ -128,29 +128,13 @@ tests = map (localOption (QuickCheckTests 20)) (doc $ divWith ("", [], kv_before) (para "nil")) (doc $ divWith ("", [], kv_after) (para "nil")) - , testCase "Test module pandoc.utils" $ - assertFilterConversion "pandoc.utils doesn't work as expected." - "test-pandoc-utils.lua" - (doc $ para "doesn't matter") - (doc $ mconcat [ plain (str "blocks_to_inlines: OK") - , plain (str "hierarchicalize: OK") - , plain (str "normalize_date: OK") - , plain (str "pipe: OK") - , plain (str "failing pipe: OK") - , plain (str "read: OK") - , plain (str "failing read: OK") - , plain (str "sha1: OK") - , plain (str "stringify: OK") - , plain (str "to_roman_numeral: OK") - ]) - , testCase "Script filename is set" $ assertFilterConversion "unexpected script name" "script-name.lua" (doc $ para "ignored") (doc $ para (str $ "lua" </> "script-name.lua")) - , testCase "Pandoc version is set" . runLua' $ do + , testCase "Pandoc version is set" . runLuaTest $ do Lua.getglobal' "table.concat" Lua.getglobal "PANDOC_VERSION" Lua.push ("." :: String) -- separator @@ -158,13 +142,13 @@ tests = map (localOption (QuickCheckTests 20)) Lua.liftIO . assertEqual "pandoc version is wrong" pandocVersion =<< Lua.peek Lua.stackTop - , testCase "Pandoc types version is set" . runLua' $ do + , testCase "Pandoc types version is set" . runLuaTest $ do let versionNums = versionBranch pandocTypesVersion Lua.getglobal "PANDOC_API_VERSION" Lua.liftIO . assertEqual "pandoc-types version is wrong" versionNums =<< Lua.peek Lua.stackTop - , testCase "Allow singleton inline in constructors" . runLua' $ do + , testCase "Allow singleton inline in constructors" . runLuaTest $ do Lua.liftIO . assertEqual "Not the exptected Emph" (Emph [Str "test"]) =<< Lua.callFunc "pandoc.Emph" (Str "test") Lua.liftIO . assertEqual "Unexpected element" (Para [Str "test"]) @@ -178,19 +162,19 @@ tests = map (localOption (QuickCheckTests 20)) Lua.peek Lua.stackTop ) - , testCase "Elements with Attr have `attr` accessor" . runLua' $ do + , testCase "Elements with Attr have `attr` accessor" . runLuaTest $ do Lua.push (Div ("hi", ["moin"], []) [Para [Str "ignored"]]) Lua.getfield Lua.stackTop "attr" Lua.liftIO . assertEqual "no accessor" (("hi", ["moin"], []) :: Attr) =<< Lua.peek Lua.stackTop - , testCase "module `pandoc.system` is present" . runLua' $ do + , testCase "module `pandoc.system` is present" . runLuaTest $ do Lua.getglobal' "pandoc.system" ty <- Lua.ltype Lua.stackTop Lua.liftIO $ assertEqual "module should be a table" Lua.TypeTable ty - , testCase "informative error messages" . runLua' $ do + , testCase "informative error messages" . runLuaTest $ do Lua.pushboolean True err <- Lua.peekEither Lua.stackTop case (err :: Either String Pandoc) of @@ -212,7 +196,7 @@ roundtripEqual :: (Eq a, Lua.Peekable a, Lua.Pushable a) => a -> IO Bool roundtripEqual x = (x ==) <$> roundtripped where roundtripped :: (Lua.Peekable a, Lua.Pushable a) => IO a - roundtripped = runLua' $ do + roundtripped = runLuaTest $ do oldSize <- Lua.gettop Lua.push x size <- Lua.gettop @@ -223,8 +207,8 @@ roundtripEqual x = (x ==) <$> roundtripped Left e -> error (show e) Right y -> return y -runLua' :: Lua.Lua a -> IO a -runLua' op = runIOorExplode $ do +runLuaTest :: Lua.Lua a -> IO a +runLuaTest op = runIOorExplode $ do setUserDataDir (Just "../data") res <- runLua op case res of diff --git a/test/Tests/Lua/Module.hs b/test/Tests/Lua/Module.hs new file mode 100644 index 000000000..82c9330e5 --- /dev/null +++ b/test/Tests/Lua/Module.hs @@ -0,0 +1,27 @@ +{- | +Module : Tests.Lua.Module +Copyright : © 2019 Albert Krewinkel +License : GNU GPL, version 2 or above + +Maintainer : Albert Krewinkel <albert@zeitkraut.de> +Stability : alpha +Portability : portable + +Lua module tests +-} +module Tests.Lua.Module (tests) where + +import System.FilePath ((</>)) +import Test.Tasty (TestName, TestTree) +import Test.Tasty.Lua (testLuaFile) + +import Tests.Lua (runLuaTest) + +tests :: [TestTree] +tests = + [ testPandocLua "pandoc" ("lua" </> "module" </> "pandoc.lua") + , testPandocLua "pandoc.util" ("lua" </> "module" </> "pandoc.utils.lua") + ] + +testPandocLua :: TestName -> FilePath -> TestTree +testPandocLua = testLuaFile runLuaTest |
