mirror of
https://github.com/littensy/charm.git
synced 2026-10-20 17:51:37 +00:00
feat: use alien-signals
This commit is contained in:
parent
d7a1f62c3c
commit
861ee5acd7
76 changed files with 3112 additions and 1862 deletions
64
tests/suite.luau
Normal file
64
tests/suite.luau
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
local results: { string } = {}
|
||||
local stack: { string } = {}
|
||||
local errors: { string } = {}
|
||||
local tests = 0
|
||||
|
||||
local function log(result: string, index: number?)
|
||||
local index = index or #results + 1
|
||||
local indent = string.rep(" ", #stack - 1)
|
||||
|
||||
results[index] = indent .. result
|
||||
end
|
||||
|
||||
local function test(name: string, callback: () -> ())
|
||||
tests += 1
|
||||
table.insert(stack, name)
|
||||
|
||||
local success = xpcall(callback, function(err)
|
||||
local path = table.concat(stack, " > ")
|
||||
table.insert(errors, `\n🔴 {path}:\n{err}`)
|
||||
end)
|
||||
|
||||
if not success then
|
||||
log(`🔴 {name}`)
|
||||
end
|
||||
|
||||
table.remove(stack)
|
||||
end
|
||||
|
||||
local function describe(name: string, callback: () -> ())
|
||||
table.insert(stack, name)
|
||||
table.insert(results, name)
|
||||
|
||||
local index = #results
|
||||
local errorCount = #errors
|
||||
callback()
|
||||
|
||||
if #errors > errorCount then
|
||||
log(`🔴 {name}`, index)
|
||||
else
|
||||
log(`🟢 {name}`, index)
|
||||
end
|
||||
|
||||
table.remove(stack)
|
||||
end
|
||||
|
||||
local function finish()
|
||||
print(`\n🔵 {tests - #errors} / {tests} tests passed\n`)
|
||||
|
||||
for _, result in results do
|
||||
print(result)
|
||||
end
|
||||
|
||||
print()
|
||||
|
||||
if #errors > 0 then
|
||||
error(`{#errors} test(s) failed:\n{table.concat(errors, "\n")}\n`)
|
||||
end
|
||||
end
|
||||
|
||||
return {
|
||||
test = test,
|
||||
describe = describe,
|
||||
finish = finish,
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue