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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
|
---@meta
assert = require("luassert")
spy = require("luassert.spy")
stub = require("luassert.stub")
mock = require("luassert.mock")
---Undocumented feature with unknown purpose.
---@param filename string
function file(filename) end
---Mark a test as placeholder.
---
---This will not fail or pass, it will simply be marked as "pending".
---@param name string
---@param block fun()
function pending(name, block) end
---Define the start of an asynchronous test.
---
---Call `done()` at the end of your test to complete it.
---
---## Example
---```
---it("Makes an http request", function()
--- async()
--- http.get("https://github.com", function()
--- print("Got Website!")
--- done()
--- end)
---end)
---```
function async() end
---Mark the end of an asynchronous test.
---
---Should be paired with a call to `async()`.
function done() end
---Used to define a set of tests. Can be nested to define sub-tests.
---
---## Example
---```
---describe("Test Item Class", function()
--- it("Creates an item", function()
--- --...
--- end)
--- describe("Test Tags", function()
--- it("Creates a tag", function()
--- --...
--- end)
--- end)
---end)
---```
---@param name string
---@param block fun()
function describe(name, block) end
context = describe
---Functions like `describe()` except it exposes the test's environment to
---outer contexts
---
---## Example
---```
---describe("Test exposing", function()
--- expose("Exposes a value", function()
--- _G.myValue = 10
--- end)
---
---end)
---
---describe("Another test in the same file", function()
--- assert.are.equal(10, myValue)
---end)
---```
---@param name string
---@param block fun()
function expose(name, block) end
---Functions like `describe()` except it insulates the test's environment to
---only this context.
---
---This is the default behaviour of `describe()`.
---
---## Example
---```
---describe("Test exposing", function()
--- insulate("Insulates a value", function()
--- _G.myValue = 10
--- end)
---
---end)
---
---describe("Another test in the same file", function()
--- assert.is.Nil(myValue)
---end)
---```
---@param name string
---@param block fun()
function insulate(name, block) end
---Randomize tests nested in this block.
---
---## Example
---```
---describe("A randomized test", function()
--- randomize()
--- it("My order is random", function() end)
--- it("My order is also random", function() end)
---end)
---```
function randomize() end
---Define a test that will pass, fail, or error.
---
---You can also use `spec()` and `test()` as aliases.
---
---## Example
---```
---describe("Test something", function()
--- it("Runs a test", function()
--- assert.is.True(10 == 10)
--- end)
---end)
---```
---@param name string
---@param block fun()
function it(name, block) end
spec = it
test = it
---Define a function to run before each child test, this includes tests nested
---in a child describe block.
---
---## Example
---```
---describe("Test Array Class", function()
--- local a
--- local b
---
--- before_each(function()
--- a = Array.new(1, 2, 3, 4)
--- b = Array.new(11, 12, 13, 14)
--- end)
---
--- it("Assures instance is an Array", function()
--- assert.True(Array.isArray(a))
--- assert.True(Array.isArray(b))
--- end)
---
--- describe("Nested tests", function()
--- it("Also runs before_each", function()
--- assert.are.same(
--- { 1, 2, 3, 4, 11, 12, 13, 14 },
--- a:concat(b))
--- end)
--- end)
---end)
---```
---@param block fun()
function before_each(block) end
---Define a function to run after each child test, this includes tests nested
---in a child describe block.
---
---## Example
---```
---describe("Test saving", function()
--- local game
---
--- after_each(function()
--- game.save.reset()
--- end)
---
--- it("Creates game", function()
--- game = game.new()
--- game.save.save()
--- end)
---
--- describe("Saves metadata", function()
--- it("Saves objects", function()
--- game = game.new()
--- game.save.save()
--- assert.is_not.Nil(game.save.objects)
--- end)
--- end)
---end)
---```
---@param block fun()
function after_each(block) end
---Runs first in a context block before any tests.
---
---Will always run even if there are no child tests to run. If you don't want
---them to run regardless, you can use `lazy_setup()` or use the `--lazy` flag
---when running.
---
---## Example
---```
---describe("Test something", function()
--- local helper
---
--- setup(function()
--- helper = require("helper")
--- end)
---
--- it("Can use helper", function()
--- assert.is_not.Nil(helper)
--- end)
---end)
---```
---@param block fun()
function setup(block) end
strict_setup = setup
---Runs first in a context block before any tests. Only runs if there are child
---tests to run.
---
---## Example
---```
---describe("Test something", function()
--- local helper
---
--- -- Will not run because there are no tests
--- lazy_setup(function()
--- helper = require("helper")
--- end)
---
---end)
---```
---@param block fun()
function lazy_setup(block) end
---Runs last in a context block after all tests.
---
---Will run ever if no tests were run in this context. If you don't want this
---to run regardless, you can use `lazy_teardown()` or use the `--lazy` flag
---when running.
---
---## Example
---```
---describe("Remove persistent value", function()
--- local persist
---
--- it("Sets a persistent value", function()
--- persist = "hello"
--- end)
---
--- teardown(function()
--- persist = nil
--- end)
---
---end)
---```
---@param block fun()
function teardown(block) end
strict_teardown = teardown
---Runs last in a context block after all tests.
---
---Will only run if tests were run in this context.
---
---## Example
---```
---describe("Remove persistent value", function()
--- local persist
---
--- -- Will not run because no tests were run
--- lazy_teardown(function()
--- persist = nil
--- end)
---
---end)
---```
---@param block fun()
function lazy_teardown(block) end
---Runs last in a context block regardless of test outcome
---
---## Example
---```
---it("Read File Contents",function()
--- local f = io.open("file", "r")
---
--- -- always close file after test
--- finally(function()
--- f:close()
--- end)
---
--- -- do stuff with f
---end)
---```
---@param block fun()
function finally(block) end
|