-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbourbon.lua
More file actions
86 lines (74 loc) · 1.65 KB
/
bourbon.lua
File metadata and controls
86 lines (74 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
local async = require './async'
local table = require 'table'
local string = require 'string'
local math = require 'math'
local fmt = string.format
local checked = 0
local asserts = {}
asserts.equal = function(a, b)
checked = checked + 1
assert(a == b)
end
asserts.ok = function(a)
checked = checked + 1
assert(a)
end
asserts.equals = function(a, b)
checked = checked + 1
assert(a == b)
end
asserts.array_equals = function(a, b)
checked = checked + 1
assert(#a == #b)
for k=1, #a do
assert(a[k] == b[k])
end
end
asserts.not_nil = function(a)
checked = checked + 1
assert(a ~= nil)
end
function is_test_key(k)
return type(k) == "string" and k:match("_*test.*")
end
local function get_tests(mod)
local ts = {}
for k,v in pairs(mod) do
if is_test_key(k) and type(v) == "function" then
ts[k] = v
end
end
ts.setup = rawget(mod, "setup")
ts.teardown = rawget(mod, "teardown")
ts.ssetup = rawget(mod, "suite_setup")
ts.steardown = rawget(mod, "suite_teardown")
return ts
end
local run_test = function(runner, callback)
p (fmt("Running %s", runner.name))
local test_baton = {}
test_baton.done = function()
callback()
end
runner.func(test_baton, asserts)
end
local run = function(mods)
local runners = {}
for k, v in pairs(get_tests(mods)) do
table.insert(runners, 1, { name = k, func = v })
end
async.forEachSeries(runners, function(runner, callback)
run_test(runner, callback)
end, function(err)
if err then
p(err)
return
end
p(fmt("Executed %s asserts", checked))
end)
end
-- Exports
local exports = {}
exports.asserts = asserts
exports.run = run
return exports