diff options
author | John MacFarlane <jgm@berkeley.edu> | 2020-04-17 18:02:25 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-17 18:02:25 -0700 |
commit | 0d2b8e3fe1d6a27aac082be7711b7156783b3051 (patch) | |
tree | 459122371d6b88a7756eee954b81f2bba4bdfdca /test | |
parent | 8f40b4ba14fce10199a059a281c9bd10c884241d (diff) | |
parent | 62cf21cbaa9ac3fbc2ba7218a3037208364c80a4 (diff) | |
download | pandoc-0d2b8e3fe1d6a27aac082be7711b7156783b3051.tar.gz |
Merge pull request #6211 from tarleb/lua-pandocerror
API change: create PandocLua type, use PandocError for exceptions
Diffstat (limited to 'test')
-rw-r--r-- | test/Tests/Lua.hs | 15 | ||||
-rw-r--r-- | test/lua/module/pandoc-types.lua | 7 |
2 files changed, 11 insertions, 11 deletions
diff --git a/test/Tests/Lua.hs b/test/Tests/Lua.hs index 0943b17aa..14800f7bb 100644 --- a/test/Tests/Lua.hs +++ b/test/Tests/Lua.hs @@ -1,5 +1,6 @@ {-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE ScopedTypeVariables #-} {- | Module : Tests.Lua Copyright : © 2017-2020 Albert Krewinkel @@ -28,11 +29,13 @@ import Text.Pandoc.Builder (bulletList, definitionList, displayMath, divWith, import Text.Pandoc.Class (runIOorExplode, setUserDataDir) import Text.Pandoc.Definition (Block (BlockQuote, Div, Para), Inline (Emph, Str), Attr, Meta, Pandoc, pandocTypesVersion) +import Text.Pandoc.Error (PandocError (PandocLuaError)) import Text.Pandoc.Filter (Filter (LuaFilter), applyFilters) import Text.Pandoc.Lua (runLua) import Text.Pandoc.Options (def) import Text.Pandoc.Shared (pandocVersion) +import qualified Control.Monad.Catch as Catch import qualified Foreign.Lua as Lua import qualified Data.Text as T import qualified Data.Text.Encoding as TE @@ -197,12 +200,13 @@ tests = map (localOption (QuickCheckTests 20)) , testCase "informative error messages" . runLuaTest $ do Lua.pushboolean True - err <- Lua.peekEither Lua.stackTop - case (err :: Either String Pandoc) of - Left msg -> do + eitherPandoc <- Catch.try (Lua.peek Lua.stackTop :: Lua.Lua Pandoc) + case eitherPandoc of + Left (PandocLuaError msg) -> do let expectedMsg = "Could not get Pandoc value: " <> "table expected, got boolean" Lua.liftIO $ assertEqual "unexpected error message" expectedMsg msg + Left e -> error ("Expected a Lua error, but got " <> show e) Right _ -> error "Getting a Pandoc element from a bool should fail." ] @@ -223,10 +227,7 @@ roundtripEqual x = (x ==) <$> roundtripped size <- Lua.gettop when (size - oldSize /= 1) $ error ("not exactly one additional element on the stack: " ++ show size) - res <- Lua.peekEither (-1) - case res of - Left e -> error (show e) - Right y -> return y + Lua.peek (-1) runLuaTest :: Lua.Lua a -> IO a runLuaTest op = runIOorExplode $ do diff --git a/test/lua/module/pandoc-types.lua b/test/lua/module/pandoc-types.lua index 880dd567e..d4e063a5c 100644 --- a/test/lua/module/pandoc-types.lua +++ b/test/lua/module/pandoc-types.lua @@ -26,10 +26,9 @@ return { ) end), test('non-version string is rejected', function () - assert.error_matches( - function () Version '11friends' end, - '11friends' - ) + local success, msg = pcall(function () Version '11friends' end) + assert.is_falsy(success) + assert.is_truthy(tostring(msg):match('11friends')) end) }, |