-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtests.lua
More file actions
232 lines (224 loc) · 8.43 KB
/
tests.lua
File metadata and controls
232 lines (224 loc) · 8.43 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
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
wowUnit.tests = {
["Test assertions"] = {
["assert"] = function()
wowUnit:assert(true, "True is indeed true")
wowUnit:assert(false, "False creates failure")
end,
["assertEquals"] = function()
wowUnit:assertEquals(1, 1, "1 and 1 are indeed equal")
wowUnit:assertEquals(1, 0, "1 and 0 are not equal")
wowUnit:assertEquals(1, "1", "1 and \"1\" are not equal")
end,
["assertSame"] = function()
local t1 = {
["a"] = {
1
}
}
local t2 = {
["a"] = {
1
}
}
local t3 = {
["a"] = {
}
}
wowUnit:assertSame(t1, t1, "same table should be equal")
wowUnit:assertSame(t1, t2, "similar table should be same")
wowUnit:assertEquals(t1, t2, "similar table should not be equal")
wowUnit:assertSame(t1, t3, "different table should not be equal")
wowUnit:assertSame(t3, t1, "different table should not be equal (reversed to make sure all table entries are checked both ways")
t3.a[1] = 2
wowUnit:assertSame(t1, t3, "still not same")
t3.a[1] = 1
wowUnit:assertSame(t1, t3, "should be the same now")
wowUnit._t1 = t1
wowUnit._t3 = t3
wowUnit:assertSame(1, 1, "2 equal non-tables should be considered same")
wowUnit:assertSame(1, 2, "2 non-equal non-tables should not be considered same")
end
},
["Test type checks"] = {
["isTable"] = function()
wowUnit:isTable(nil, "nil is not a table")
wowUnit:isTable(1, "1 is not a table")
wowUnit:isTable("a", "\"a\" is not a table")
wowUnit:isTable({}, "{} is a table")
end,
["isString"] = function()
wowUnit:isString(nil, "nil is not a string")
wowUnit:isString(1, "1 is not a string")
wowUnit:isString("a", "\"a\" is a string")
wowUnit:isString({}, "{} is not a string")
end,
["isNumber"] = function()
wowUnit:isNumber(nil, "nil is not a number")
wowUnit:isNumber(1, "1 is a number")
wowUnit:isNumber("a", "\"a\" is not a number")
wowUnit:isNumber({}, "{} is not a number")
end,
["isNil"] = function()
wowUnit:isNil(nil, "nil is nil")
wowUnit:isNil(1, "1 is not nil")
wowUnit:isNil("a", "\"a\" is not nil")
wowUnit:isNil({}, "{} is not nil")
end,
["isFunction"] = function()
wowUnit:isFunction(nil, "nil is not a function")
wowUnit:isFunction(1, "1 is not a function")
wowUnit:isFunction("a", "\"a\" is not a function")
wowUnit:isFunction({}, "{} is not a function")
wowUnit:isFunction(wowUnit.assert, "wowUnit.assert is a function")
end
},
["Test expectations"] = {
["No expectations"] = function()
wowUnit:assert(true, "true")
end,
["expectations met"] = function()
wowUnit:expect(1)
wowUnit:assert(true, "true")
end,
["expectations not met"] = function()
wowUnit:expect(2)
wowUnit:assert(true, "true")
end,
},
["Test empty categories"] = {},
["Test Lua errors"] = {
["Simple reference error"] = function()
iMnotafunction()
end,
["reference error with stack"] = function()
function func1()
func2()
end
function func2()
iMnotafunction()
end
func1()
end
},
["Some successful tests"] = {
["test 1"] = function()
wowUnit:expect(1)
wowUnit:assert(true, "The way it should be")
end,
["test 2"] = function()
wowUnit:expect(2)
wowUnit:assertEquals(1, 1, "The way it should be")
wowUnit:assertSame(1, 1, "The way it should be")
end,
["test 3"] = function()
--wowUnit:expect(3)
wowUnit:isNil(theNumberJ)
wowUnit:isNumber(9, "J is unfortunately not a number, Day[9]")
wowUnit:isString("J", "J, by itself, is a letter, which constitutes a string")
end
},
["Asynchronous testing"] = {
["asynch fails"] = function()
wowUnit:pauseTesting()
end,
["asynch succeeds"] = function()
local testID = wowUnit:pauseTesting()
wowUnit:expect(2)
local frameCount = 1
local testFrame = CreateFrame("Frame")
testFrame:Show()
testFrame:SetScript("OnUpdate", function(self, elapsed)
frameCount = frameCount - 1
if (frameCount <= 0) then
testFrame:SetScript("OnUpdate", nil)
wowUnit:resumeTesting(testID)
wowUnit:assert(true, "Asynch function terminated 1")
end
end)
end,
["asynch fails because of timeout"] = function()
local testID = wowUnit:pauseTesting()
local frameCount = 6
local testFrame = CreateFrame("Frame")
testFrame:Show()
testFrame:SetScript("OnUpdate", function(self, elapsed)
frameCount = frameCount - elapsed
if (frameCount <= 0) then
testFrame:SetScript("OnUpdate", nil)
wowUnit:resumeTesting(testID)
wowUnit:assert(true, "Asynch function terminated 2")
end
end)
end,
["asynch succeeds within timeframe"] = function()
local testID = wowUnit:pauseTesting(10)
wowUnit:expect(2)
local frameCount = 8
local testFrame = CreateFrame("Frame")
testFrame:Show()
testFrame:SetScript("OnUpdate", function(self, elapsed)
frameCount = frameCount - elapsed
if (frameCount <= 0) then
testFrame:SetScript("OnUpdate", nil)
wowUnit:resumeTesting(testID)
wowUnit:assert(true, "Asynch function terminated 3")
end
end)
end,
["asynch fails after timeframe"] = function()
local testID = wowUnit:pauseTesting(2)
wowUnit:expect(2)
local frameCount = 3
local testFrame = CreateFrame("Frame")
testFrame:Show()
testFrame:SetScript("OnUpdate", function(self, elapsed)
frameCount = frameCount - elapsed
if (frameCount <= 0) then
testFrame:SetScript("OnUpdate", nil)
wowUnit:resumeTesting(testID)
wowUnit:assert(true, "Asynch function terminated 4")
end
end)
end
},
["Setup and Teardown"] = {
setup = function()
wowUnit:Print("setup")
wowUnit.__setupTest = 3
wowUnit.__oldStartTests = wowUnit.StartTests
function iMnotafunction()
wowUnit:assert(true, "global function defined")
end
wowUnit.StartTests = function()
wowUnit:assert(true, "StartTests called")
end
end,
teardown = function()
wowUnit:Print("teardown")
wowUnit.__setupTest = nil
wowUnit.StartTests = wowUnit.__oldStartTests
iMnotafunction = nil
end,
["Check if setupped variable is correct"] = function()
wowUnit:assertEquals(wowUnit.__setupTest, 3, "Setup is working")
end,
["mocking a function the untidy way"] = function()
wowUnit:Print("mock")
wowUnit:expect(2)
iMnotafunction()
wowUnit:StartTests()
end
},
["Mocking"] = {
mock = {
UnitName = function(unit)
wowUnit:assert(true, "Mocked UnitName function was called.")
return "Pan-Galactic Gargle Blaster"
end
},
["Check mocked function"] = function()
wowUnit:assertEquals(UnitName('player'), "Pan-Galactic Gargle Blaster", "Our mocked function was called and returned the correct value")
wowUnit:expect(2)
end
},
}