Jump to content

Module:ScribuntoUnit/testcases

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Danmichaelo (talk | contribs) at 08:33, 3 January 2014. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
local ScribuntoUnit = require('Module:ScribuntoUnit')

p = {}

--------------------------------------------------------------------------------
-- Test assertEquals

function p.testAssertEquals(msg, expected, actual, shouldFail)
	local out = msg .. ' '
	local errmsg = ''

	success, details = pcall(function ()
		local suite = ScribuntoUnit:new()
		suite:assertEquals(expected, actual)
	end)
	
	if type(details) ~= 'table' or not details.ScribuntoUnit then -- a real error, not a failed assertion
		success = false
		errmsg = 'Lua error: ' .. tostring(details)
	end
	
	if success and not shouldFail then
		out = out .. 'OK'
	else
		out = out .. 'FAIL'	.. (errmsg and ' -- ' .. errmsg or '')			
	end

	return out
end
	
function p.testAssertEqualsWithEqualStrings()
	
	return p.testAssertEquals(
		'Testing that assertEquals does not throw error for equal strings...',
		'abc',
		'abc',
		false
	)

end

function p.testAssertEqualsWithUnequalStrings()
	
	return p.testAssertEquals(
		'Testing that assertEquals throws error for unequal strings...',
		'abc',
		'def',
		true
	)

end

--------------------------------------------------------------------------------
-- TODO: Test more methods
--

return p