Skip to content

Instantly share code, notes, and snippets.

@jasper-lyons
Created February 22, 2018 11:31
Show Gist options
  • Save jasper-lyons/53afaeb2c9ca4de135b4f1722d6aa1a9 to your computer and use it in GitHub Desktop.
Save jasper-lyons/53afaeb2c9ca4de135b4f1722d6aa1a9 to your computer and use it in GitHub Desktop.
A lua testing framework in 30 lines
local function describe(name, descriptor)
local errors = {}
local successes = {}
function it(spec_line, spec)
local status = xpcall(spec, function (err)
table.insert(errors, string.format("\t%s\n\t\t%s\n", spec_line, err))
end)
if status then
table.insert(successes, string.format("\t%s\n", spec_line))
end
end
local status = xpcall(descriptor, function (err)
table.insert(errors, err)
end, it)
print(name)
if #errors > 0 then
print('Failures:')
print(table.concat(errors))
end
if #successes > 0 then
print('Successes:')
print(table.concat(successes))
end
end
return describe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment