Модуль:No globals/testcases

Матеріал з Вікіпедія ЄСІТС
< Модуль:No globals
Версія від 12:52, 21 вересня 2020, створена Tviggy (обговорення | внесок) (Імпортовано 1 версія)
(різн.) ← Попередня версія | Поточна версія (різн.) | Новіша версія → (різн.)
Перейти до навігації Перейти до пошуку

Документацію для цього модуля можна створити у Модуль:No globals/testcases/документація

local p = require('Module:ScribuntoUnit'):new()

-- Allow test runner to use both the Module:XXX itself and Module:XXX/sandbox with the same testcases
function p:module()
	return self.frame and self.frame.args and self.frame.args.module or 'No globals'
end

function p:test()
	require('Module:' .. p:module())
	
	-- try returning undeclared variable
	self:assertThrows(function() return foo end, "Tried to read nil global foo", 'test1')
	
	-- try writing to an undeclared variable
	self:assertThrows(function() bar = 0 end, "Tried to write global bar", 'test2')
	
	-- try reading and writing to variable arg -- should be exempt, and cause no errors
	local tmp = arg
	arg = arg
end

return p