WARFRAME Wiki
Advertisement
WARFRAME Wiki


ModuleTest hosts the entry point to the unit test runner Module:TestHarness.

On this Wiki, ModuleTest is used in:

  • All module's /testcases/doc subpages

Usage

Direct Invocation

{{#invoke:ModuleTest|main}}

Additional Documentation

For use with Module:<Name>/doc and Module:<Name>/testcases.

Module:<Name>/doc contains an invocation to this module ({{#invoke:ModuleTest|main}}) and the Category:Lua test suites category. The invoke will automatically find Module:<Name>/testcases and run all of the tests in the module, printing out the test report and cases. Any failing test cases will put the page in the Category:Failing Lua test suites category.
See Module:Math/doc for reference.

Module:<Name>/testcases contains any tests for member functions or objects of p (p.func() or p.table). Local functions and member functions preceded by two underscores (local function func() or p.__func()) are not tested.
See Module:Math/testcases for reference.

Testcase format:

return {
    funcName = { -- Member being tested (p.funcName). Local functions and members starting with two underscores not tested (local function funcName and p.__funcName).
        options = {
        --  Important options to know (a mode type is non-optional)
            mode = 'invocation', -- Tests member as a Scribunto invocation ({{#invoke:ModuleName|funcName|1|2|3|arg1=arg1|arg2=arg2}})
            mode = 'method',     -- Tests member as a standalone Lua function (p.funcName({1, 2, 3, arg1, arg2}) or p.funcName(1, 2, 3, arg1, arg2))
            preprocess = true,   -- Preprocess expected text, false by default
            unpk = true,         -- Unpack the table argument in 'method' tests, false by default
            nowiki = false,      -- Apply nowiki formatting to report field, true by default
            
        --  Other options you likely won't use
            mode = 'table',      -- Tests method as a static Lua table
            template = true,     -- Skip to parent frame when applying test case arguments to parent frame first, false by default
            self = true,         -- Self-invoke the package function in 'method' tests, false by default
            deep = true,         -- Enable deep comparison for table cases in 'method' tests, false by default
        },
        tests = {
        --  { Input, Expected Output, {err = true, pp = true} },
            -- err: Whether a script error is expected in the test case, false by default
            -- pp:  Whether the expected output should be preprocessed before comparison, false by default
            
            -- 'invocation' mode
            { 'Hello World!', 'Hello World!' },
            { 'Hello|World', 'Hello' },
            
            -- 'method' mode
            { {'Hello World!'}, 'Hello World!' },
            { {'Hello', 'World'}, 'Hello' },
        }
    },
    funcName2 = {
        options = {
            mode = 'invocation',
            preprocess = true,   -- Preprocess expected text, false by default
        },
        tests = {
            { 'Hello World!', 'Hello World!' },
            { '1 + 2', '{{#expr: 1 + 2}}', {pp = true} },
        }
    },
    _funcName2 = {
        options = {
            mode = 'method',
            unpk = true,
        },
        tests = {
			{ {}, 'Not enough input arguments', {err = true} }
            { {'Hello World!'}, 'Hello World!' },
            { {'Hello', 'World'}, 'Hello' },
        }
    },
}

Documentation


Created with Docbuntu

See Also

Code


---	'''ModuleTest''' hosts the entry point to the unit test runner [[Module:TestHarness]].<br />
--	
--	On this Wiki, ModuleTest is used in:
--	* All module's <code>/testcases/doc</code> subpages
--	
--	@module		moduletest
--	@alias		p
--	@author		[[User:FINNER|FINNER]]
--	@require	[[w:c:dev:Module:Arguments|Module:Arguments]]
--	@release	stable

local p = {};

local getArgs = require('Dev:Arguments').getArgs;

function p.main(frame)
    local args = getArgs(frame); --frame:getParent().args;
    local title = mw.title.getCurrentTitle();
    local typ = string.lower(args[1] or '');
    local moduleName, functionName;

    if typ == 'scrib' then
        moduleName = 'Module:'..(args.modulename or title.rootText)..'/testcases';
        functionName = 'run';
        frame.args = {};
    elseif typ == 'unittest' then
        moduleName = 'Module:'..(args.modulename or title.rootText)..'/testcases';
        functionName = 'run_tests';
        frame.args = {
            differs_at = args.differs_at or '1',
        };
    elseif typ == 'sandbox' then
        moduleName = 'Module:TestHarness';
        functionName = 'run_tests';
        frame.args = {
            modulename = args.modulename or (title.rootText..'/sandbox'),
            testdata = args.testdata or (title.rootText..'/sandbox/testcases'),
            differs_at = args.differs_at or '1',
            display_mode = args.display_mode or '0'
        };
    else
        moduleName = 'Module:TestHarness';
        functionName = 'run_tests';
        frame.args = {
            modulename = args.modulename or title.rootText or '',
            testdata = args.testdata or '',
            differs_at = args.differs_at or '1',
            display_mode = args.display_mode or '0',
            pass_only = args.pass_only or '0'
        };
    end

    return require(moduleName)[functionName](frame);
end

return p;