/
init.lua
117 lines (93 loc) · 2.76 KB
/
init.lua
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
-- Expose luassert elements as part of global interfcae
assert = require('luassert')
spy = require('luassert.spy')
mock = require('luassert.mock')
stub = require('luassert.stub')
-- Load default language pack
require('busted.languages.en')
-- Load and expose busted core as part of global interface
busted = require('busted.core')
busted._COPYRIGHT = "Copyright (c) 2012 Olivine Labs, LLC."
busted._DESCRIPTION = "A unit testing framework with a focus on being easy to use."
busted._VERSION = "Busted 1.4"
local current_context = busted.root_context
-- Global functions
describe = function(description, callback)
local match = current_context.run
local parent = current_context
if busted.options.tags and #busted.options.tags > 0 then
for i,t in ipairs(busted.options.tags) do
if description:find("#"..t) then
match = true
end
end
else
match = true
end
local local_context = {
description = description,
callback = callback,
type = "describe",
run = match,
before_each_stack = {},
after_each_stack = {}
}
for i,v in pairs(current_context.before_each_stack) do
table.insert(local_context.before_each_stack, v)
end
for i,v in pairs(current_context.after_each_stack) do
table.insert(local_context.after_each_stack, v)
end
table.insert(current_context, local_context)
current_context = local_context
callback()
current_context = parent
end
it = function(description, callback)
local match = current_context.run
if not match then
if busted.options.tags and #busted.options.tags > 0 then
for i,t in ipairs(busted.options.tags) do
if description:find("#"..t) then
match = true
end
end
end
end
if current_context.description and match then
table.insert(current_context, { description = description, callback = callback, type = "test" })
elseif match then
test(description, callback)
end
end
pending = function(description, callback)
local debug_info = debug.getinfo(callback)
local info = {
source = debug_info.source,
short_src = debug_info.short_src,
linedefined = debug_info.linedefined,
}
local test_status = {
description = description,
type = "pending",
info = info,
callback = function(self)
if not busted.options.defer_print then
busted.output.currently_executing(self, busted.options)
end
end
}
table.insert(current_context, test_status)
end
before_each = function(callback)
table.insert(current_context.before_each_stack, callback)
end
after_each = function(callback)
table.insert(current_context.after_each_stack, callback)
end
setup = function(callback)
current_context.setup = callback
end
teardown = function(callback)
current_context.teardown = callback
end