Diferencia entre revisiones de «Módulo:QuickTest»

De Familia Sanchez Arjona
Saltar a: navegación, buscar
m (strings!)
m (fix error)
Línea 29: Línea 29:
 
end
 
end
  
function cat(title, cat)
+
function cat(title, cat, frame)
 
if frame:getParent():getTitle() == title then return cat end
 
if frame:getParent():getTitle() == title then return cat end
 
return ''
 
return ''
Línea 37: Línea 37:
 
local testResult, title = p.run(frame)
 
local testResult, title = p.run(frame)
 
if testResult == true then
 
if testResult == true then
return '[[File:Accept.png|16px|alt=Ok]]: Tests passed. C.f. [[COM:LUA/T#auto]]' .. cat(title, '[[Category:Lua modules with tests passed]]')
+
return '[[File:Accept.png|16px|alt=Ok]]: Tests passed. C.f. [[COM:LUA/T#auto]]' .. cat(title, '[[Category:Lua modules with tests passed]]', frame)
 
elseif testResult == false then
 
elseif testResult == false then
return '[[File:Bug error.png|16px|alt=Bug]]: Tests failed. Run <code>=p.runTests()</code> in the LUA console on [[' .. title .. ']] for more details.' .. cat(title, '[[Category:Lua modules with tests failed]]')
+
return '[[File:Bug error.png|16px|alt=Bug]]: Tests failed. Run <code>=p.runTests()</code> in the LUA console on [[' .. title .. ']] for more details.' .. cat(title, '[[Category:Lua modules with tests failed]]', frame)
 
elseif testResult == 'error' then
 
elseif testResult == 'error' then
return '[[File:Error.png|16px|alt=Error]]: Error executing tests.' .. cat(title, '[[Category:Lua modules with errors executing tests]]')
+
return '[[File:Error.png|16px|alt=Error]]: Error executing tests.' .. cat(title, '[[Category:Lua modules with errors executing tests]]', frame)
 
else
 
else
return testResult .. cat(title, '[[Category:Lua modules without test API]]')
+
return testResult .. cat(title, '[[Category:Lua modules without test API]]', frame)
 
end
 
end
 
end
 
end
  
 
return p
 
return p

Revisión del 17:48 20 dic 2013

La documentación para este módulo puede ser creada en Módulo:QuickTest/doc

-- Tests whether a module has a test API, and if so, runs these tests

local p = {}

function p.run(frame)
	local title = frame:getParent():getTitle()
	local titlesplit = mw.text.split(title, '/', true)
	if titlesplit[1] ~= 'Module:' then return '' end
	if titlesplit[#titlesplit] == 'doc' then
		table.remove(titlesplit)
	end
	title = table.concat(titlesplit, '/')
	
	-- Load the module
	local m = require(title)
	local testFunction = m['runTests']
	local testFunctionType = type(testFunction)
	if ( testFunctionType ~= 'function' and not ( testFunctionType == 'table' and getmetatable(testFunction).__call ) ) then
		return '', title
	end
	
	-- Execute the test function
	local ok, result = pcall(testFunction)
	if ok then
		return result, title
	else
		return 'error', title
	end
end

function cat(title, cat, frame)
	if frame:getParent():getTitle() == title then return cat end
	return ''
end

function p.testModule(frame)
	local testResult, title = p.run(frame)
	if testResult == true then
		return '[[File:Accept.png|16px|alt=Ok]]: Tests passed. C.f. [[COM:LUA/T#auto]]' .. cat(title, '[[Category:Lua modules with tests passed]]', frame)
	elseif testResult == false then
		return '[[File:Bug error.png|16px|alt=Bug]]: Tests failed. Run <code>=p.runTests()</code> in the LUA console on [[' .. title .. ']] for more details.' .. cat(title, '[[Category:Lua modules with tests failed]]', frame)
	elseif testResult == 'error' then
		return '[[File:Error.png|16px|alt=Error]]: Error executing tests.' .. cat(title, '[[Category:Lua modules with errors executing tests]]', frame)
	else
		return testResult .. cat(title, '[[Category:Lua modules without test API]]', frame)
	end
end

return p