Created
February 22, 2018 11:31
-
-
Save jasper-lyons/53afaeb2c9ca4de135b4f1722d6aa1a9 to your computer and use it in GitHub Desktop.
A lua testing framework in 30 lines
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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