Skip to content

Instantly share code, notes, and snippets.

@miratcan
Last active October 27, 2023 12:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miratcan/2f2d7a72eab6cb4853ea75e8abc0773f to your computer and use it in GitHub Desktop.
Save miratcan/2f2d7a72eab6cb4853ea75e8abc0773f to your computer and use it in GitHub Desktop.
Run tests on game before start on TIC-80
local testRunner = {
tests = {
test_foo = function() end,
test_bar = function() end,
test_zoo = function() end
},
init = function(self)
self._tests = {}
for n, f in pairs(self.tests) do
table.insert(self._tests, {n, f})
end
end,
idx = 1,
fail = false,
tic = function(self)
if self.idx <= #self._tests then
local n, f = table.unpack(self._tests[self.idx])
local s, e = pcall(f)
if s then
trace("Testing " .. n .. " passed.", 5)
else
trace("Testing " .. n .. " failed: ", 3)
trace(e, 3)
self.fail = true
end
self.idx = self.idx + 1
name, func = next(self.tests)
else
if self.fail then
cls(3)
print('Tests are failed, check traceback')
return 'FAILED'
else
return 'COMPLETED'
end
end
end
}
-- Initialize tests -----------------
local TESTS_COMPLETED = false
testRunner:init()
function TIC()
if READY == false then
READY = testRunner:tic() == 'COMPLETED'
return
end
cls()
print("HELLO WORLD!",84,84)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment