I would like to write some unit tests for Lua code being used by ConTeXt, and would like to know if anyone else has done this and what may be require in setting up the framework.
The Lua code in particular is being stored in separate files (e.g. numbering.lua
), meaning that a test runner (e.g. Busted) can just include them with require
.
It may be worth noting (but probably does not matter) that I am using Python's unittest as a test runner with lunatic-python.
The inherent problem is that the globals defined by LuaTeX and ConTeXt are not naturally in Lua. Tables such as context
and texio
are simply not accessible without a require
that imports them from their corresponding files. (Which looks to be tex/texmf-context/tex/context/base/trac-log.lua
and ...who knows, respectively).
Has anyone done unit testing of ConTeXt + Lua? What Lua files might one need to include to get the variables? I would expect there to be an entry-point somewhere that would take care of most of the setup.
It looks like the .lua
files of relevance would generally be in ./tex/texmf-context/tex/context/base/
but I am just guessing, and since there are around 840 .lua
files I would be grateful for any guidance on where to start.
.lua
files, so why not require the unit test library, and run the test files through context?context
namespace this does make only limited sense because it relies on Luatex builtins from thetex
namespace only available during a TeX run. Also, don’t waste your time trying to run Context.lua
files on a regular Lua interpreter. They make use of many of the Luatex extensions even outside the TeX run. Basically, in order to use the fundamental Lua libraries you can run your scripts withmtxrun
directly, for everything more complicated you’re going to have to run Context itself.