aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAlbert Krewinkel <albert@zeitkraut.de>2021-11-17 08:47:30 +0100
committerAlbert Krewinkel <albert@zeitkraut.de>2021-11-17 10:03:04 +0100
commitcd91f72843359c5305842fa8afbec4a2d72629fa (patch)
treefbce914ef589cd7173d36bd572466bbfd36ab803 /test
parent3ac7deadce6cf2fbf6aaa3c7bacebaacb5c68214 (diff)
downloadpandoc-cd91f72843359c5305842fa8afbec4a2d72629fa.tar.gz
Lua: set `lpeg`, `re` as globals; allow shared lib access via require
The `lpeg` and `re` modules are loaded into globals of the respective name, but they are not necessarily registered as loaded packages. This ensures that - the built-in library versions are preferred when setting the globals, - a shared library is used if pandoc has been compiled without `lpeg`, and - the `require` mechanism can be used to load the shared library if available, falling back to the internal version if possible and necessary.
Diffstat (limited to 'test')
-rw-r--r--test/Tests/Lua.hs24
1 files changed, 17 insertions, 7 deletions
diff --git a/test/Tests/Lua.hs b/test/Tests/Lua.hs
index 6ee07f8fa..5e81cec6a 100644
--- a/test/Tests/Lua.hs
+++ b/test/Tests/Lua.hs
@@ -17,7 +17,7 @@ module Tests.Lua ( runLuaTest, tests ) where
import Control.Monad (when)
import HsLua as Lua hiding (Operation (Div), error)
import System.FilePath ((</>))
-import Test.Tasty (TestTree, localOption)
+import Test.Tasty (TestTree, testGroup, localOption)
import Test.Tasty.HUnit ((@=?), Assertion, HasCallStack, assertEqual, testCase)
import Test.Tasty.QuickCheck (QuickCheckTests (..), ioProperty, testProperty)
import Text.Pandoc.Arbitrary ()
@@ -211,13 +211,23 @@ tests = map (localOption (QuickCheckTests 20))
ty <- Lua.ltype Lua.top
Lua.liftIO $ assertEqual "module should be a table" Lua.TypeTable ty
- , testCase "module 'lpeg' is loaded into a global" . runLuaTest $ do
- s <- Lua.dostring "assert(type(lpeg)=='table');assert(lpeg==require'lpeg')"
- Lua.liftIO $ Lua.OK @=? s
+ , testGroup "global modules"
+ [ testCase "module 'lpeg' is loaded into a global" . runLuaTest $ do
+ s <- Lua.dostring "assert(type(lpeg)=='table')"
+ Lua.liftIO $ Lua.OK @=? s
- , testCase "module 're' is available" . runLuaTest $ do
- s <- Lua.dostring "require 're'"
- Lua.liftIO $ Lua.OK @=? s
+ , testCase "module 're' is loaded into a global" . runLuaTest $ do
+ s <- Lua.dostring "assert(type(re)=='table')"
+ Lua.liftIO $ Lua.OK @=? s
+
+ , testCase "module 'lpeg' is available via `require`" . runLuaTest $ do
+ s <- Lua.dostring "require 'lpeg'"
+ Lua.liftIO $ Lua.OK @=? s
+
+ , testCase "module 're' is available via `require`" . runLuaTest $ do
+ s <- Lua.dostring "require 're'"
+ Lua.liftIO $ Lua.OK @=? s
+ ]
, testCase "informative error messages" . runLuaTest $ do
Lua.pushboolean True