Skip to content

Module dev_lua_test.erl

Function Index

exec_test/2*Generate an EUnit test for a given function.
exec_test_/0*Main entrypoint for Lua tests.
new_state/1*Create a new Lua environment for a given script.
parse_spec/1Parse a string representation of test descriptions received from the command line via the LUA_TESTS environment variable.
suite/2*Generate an EUnit test suite for a given Lua script.
terminates_with/2*Check if a string terminates with a given suffix.

Function Details

exec_test/2 *

exec_test(State, Function) -> any()

Generate an EUnit test for a given function.

exec_test_/0 *

exec_test_() -> any()

Main entrypoint for Lua tests.

new_state/1 *

new_state(File) -> any()

Create a new Lua environment for a given script.

parse_spec/1

parse_spec(Str) -> any()

Parse a string representation of test descriptions received from the command line via the LUA_TESTS environment variable.

Supported syntax in loose BNF/RegEx:

Definitions := (ModDef,)+ ModDef := ModName(TestDefs)? ModName := ModuleInLUA_SCRIPTS|(FileName[.lua])? TestDefs := (:TestDef)+ TestDef := TestName

File names ending in .lua are assumed to be relative paths from the current working directory. Module names lacking the .lua extension are assumed to be modules found in the LUA_SCRIPTS environment variable (defaulting to scripts/).

For example, to run a single test one could call the following:

LUA_TESTS=~/src/LuaScripts/test.yourTest rebar3 lua-tests

To specify that one would like to run all of the tests in the scripts/test.lua file and two tests from the scripts/test2.lua file, the user could provide the following test definition:

LUA_TESTS="test,scripts/test2.userTest1|userTest2" rebar3 lua-tests

suite/2 *

suite(File, Funcs) -> any()

Generate an EUnit test suite for a given Lua script. If the Funcs is the atom tests we find all of the global functions in the script, then filter for those ending in _test in a similar fashion to Eunit.

terminates_with/2 *

terminates_with(String, Suffix) -> any()

Check if a string terminates with a given suffix.