aboutsummaryrefslogtreecommitdiff
path: root/pandoc-lua-engine/test
diff options
context:
space:
mode:
authorAlbert Krewinkel <[email protected]>2025-07-31 11:49:20 +0200
committerJohn MacFarlane <[email protected]>2025-08-01 10:04:14 -0700
commit75aee7a23c96ff31aa9fcb7608891c33a011d6a1 (patch)
tree155da93d4f6b5e262498aba353e6e92447fb2dc9 /pandoc-lua-engine/test
parent57e7d895db367eb09cb4cb31678ac3b5f6dc9ef7 (diff)
Lua: use proper interface functions to access the CommonState.
- The `PANDOC_STATE` is no longer a userdata object, but a table that behaves like the old object. - Log messages in `PANDOC_STATE.log` are now in temporal order.
Diffstat (limited to 'pandoc-lua-engine/test')
-rw-r--r--pandoc-lua-engine/test/Tests/Lua.hs5
-rw-r--r--pandoc-lua-engine/test/lua/module/globals.lua4
-rw-r--r--pandoc-lua-engine/test/lua/module/pandoc-log.lua6
3 files changed, 7 insertions, 8 deletions
diff --git a/pandoc-lua-engine/test/Tests/Lua.hs b/pandoc-lua-engine/test/Tests/Lua.hs
index 990a1d039..82b815219 100644
--- a/pandoc-lua-engine/test/Tests/Lua.hs
+++ b/pandoc-lua-engine/test/Tests/Lua.hs
@@ -24,8 +24,7 @@ import Text.Pandoc.Builder (bulletList, definitionList, displayMath, divWith,
linebreak, math, orderedList, para, plain, rawBlock,
singleQuoted, space, str, strong,
HasMeta (setMeta))
-import Text.Pandoc.Class ( CommonState (stVerbosity)
- , modifyCommonState, runIOorExplode, setUserDataDir)
+import Text.Pandoc.Class ( runIOorExplode, setUserDataDir, setVerbosity )
import Text.Pandoc.Definition (Attr, Block (BlockQuote, Div, Para), Pandoc,
Inline (Emph, Str), pandocTypesVersion)
import Text.Pandoc.Error (PandocError (PandocLuaError))
@@ -242,7 +241,7 @@ runLuaTest :: HasCallStack => Lua.LuaE PandocError a -> IO a
runLuaTest op = runIOorExplode $ do
-- Disable printing of warnings on stderr: some tests will generate
-- warnings, we don't want to see those messages.
- modifyCommonState $ \st -> st { stVerbosity = ERROR }
+ setVerbosity ERROR
res <- runLua $ do
setGlobals [ PANDOC_WRITER_OPTIONS def ]
op
diff --git a/pandoc-lua-engine/test/lua/module/globals.lua b/pandoc-lua-engine/test/lua/module/globals.lua
index 4df133e46..11b003981 100644
--- a/pandoc-lua-engine/test/lua/module/globals.lua
+++ b/pandoc-lua-engine/test/lua/module/globals.lua
@@ -110,8 +110,8 @@ return {
},
group 'PANDOC_STATE' {
- test('is a userdata object', function ()
- assert.are_equal(type(PANDOC_STATE), 'userdata')
+ test('is a table object', function ()
+ assert.are_equal(type(PANDOC_STATE), 'table')
end),
test('has property "input_files"', function ()
assert.are_equal(type(PANDOC_STATE.input_files), 'table')
diff --git a/pandoc-lua-engine/test/lua/module/pandoc-log.lua b/pandoc-lua-engine/test/lua/module/pandoc-log.lua
index 923f03cd9..1daf6240d 100644
--- a/pandoc-lua-engine/test/lua/module/pandoc-log.lua
+++ b/pandoc-lua-engine/test/lua/module/pandoc-log.lua
@@ -22,13 +22,13 @@ return {
end),
test('reports a warning', function ()
log.info('info test')
- local msg = json.decode(json.encode(PANDOC_STATE.log[1]))
+ local msg = json.decode(json.encode(PANDOC_STATE.log:at(-1)))
assert.are_equal(msg.message, 'info test')
assert.are_equal(msg.type, 'ScriptingInfo')
end),
test('info includes the correct number', function ()
log.info('line number test')
- local msg = json.decode(json.encode(PANDOC_STATE.log[1]))
+ local msg = json.decode(json.encode(PANDOC_STATE.log:at(-1)))
-- THIS NEEDS UPDATING if lines above are shifted.
assert.are_equal(msg.line, 30)
end),
@@ -40,7 +40,7 @@ return {
end),
test('reports a warning', function ()
log.warn('testing')
- local msg = json.decode(json.encode(PANDOC_STATE.log[1]))
+ local msg = json.decode(json.encode(PANDOC_STATE.log:at(-1)))
assert.are_equal(msg.message, 'testing')
assert.are_equal(msg.type, 'ScriptingWarning')
end),