diff options
author | Albert Krewinkel <albert@zeitkraut.de> | 2020-03-25 22:16:27 +0100 |
---|---|---|
committer | Albert Krewinkel <albert@zeitkraut.de> | 2020-04-17 21:52:48 +0200 |
commit | fb54f3d6792d2f8e7b05e458b59142f8ae6bb3e2 (patch) | |
tree | b5403849735559bd28050fe8bccf068bdf37f48a /test/Tests | |
parent | 2877ca70ecaf5b6715b38f41165974f89206d18b (diff) | |
download | pandoc-fb54f3d6792d2f8e7b05e458b59142f8ae6bb3e2.tar.gz |
API change: use PandocError for exceptions in Lua subsystem
The PandocError type is used throughout the Lua subsystem, all Lua
functions throw an exception of this type if an error occurs. The
`LuaException` type is removed and no longer exported from
`Text.Pandoc.Lua`. In its place, a new constructor `PandocLuaError` is
added to PandocError.
Diffstat (limited to 'test/Tests')
-rw-r--r-- | test/Tests/Lua.hs | 15 |
1 files changed, 8 insertions, 7 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 |