Module:Testharness

-- -- Runs multiple unit tests using testdata from table. See Global modules/Testharness for help. --

local tester = require('Dev:UnitTests') local p ={}

local function isValidTable(table) return (table and type(table)=="table" and next(table)) end

function p.testSuite(moduleName,functionName,testCases,options,testType) local preprocess_many_testcases = {} if isValidTable(testCases) then tester["test_"..moduleName.."_"..functionName.."_"..testType] = function (tester) if type(tester[testType]) =="function" then if testType =="preprocess_equals_many" then for index, _ in pairs(testCases) do                       if #testCases[index]==2 then table.insert(preprocess_many_testcases,testCases[index]) else tester[testType](tester,unpack(testCases[index])) end end tester[testType](tester,'', preprocess_many_testcases ,options) else for index, _ in pairs(testCases) do                       table.insert(testCases[index], options) tester[testType](tester,unpack(testCases[index])) end end end end end end

function p.run_tests(frame) local moduleName = frame.args["modulename"] or mw.title.getCurrentTitle.baseText local testModule = require("Module:"..moduleName)

if testModule then local testdata = frame.args.testdata or "Module:"..moduleName .."/testcases" local sTestCases = require(testdata) for method,data in pairs(sTestCases) do           if not testModule[method] then error("Cannot test function `"..method..'` because it does not exist!') end if data and isValidTable(data.tests) then for testType,testData in pairs(data.tests) do                   p.testSuite(moduleName,method,testData,data.options,testType) end end end local differs_at = true return tester.run_tests(frame,differs_at) end end return p