Skip to content

Commit 3ddd84c

Browse files
fesilycarsakiller
andauthored
add: busted and luassert definitions (#1556)
* add meta 3rd: busted * add: tons of documentation * fix: mock return type - Also removed unnecessary unique type for stub instances * merge upstream * fix:add luassert top api * chore: cleanup and more aliases * add: array assertions * add: matchers * Move the file to the correct location * fix constructor * allow Infinite Nested API * add assert.string Co-authored-by: carsakiller <[email protected]> Co-authored-by: fesily <[email protected]>
1 parent 7c6d63a commit 3ddd84c

File tree

10 files changed

+1444
-0
lines changed

10 files changed

+1444
-0
lines changed

meta/3rd/busted/config.lua

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
files = {
2+
".*_spec%.lua",
3+
".*_test%.lua",
4+
}
5+
6+
configs = {
7+
{
8+
key = "Lua.workspace.library",
9+
action = "add",
10+
value = "${3rd}/luassert/library",
11+
},
12+
}

meta/3rd/busted/library/busted.lua

+298
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,298 @@
1+
---@meta
2+
3+
assert = require("luassert")
4+
spy = require("luassert.spy")
5+
stub = require("luassert.stub")
6+
mock = require("luassert.mock")
7+
8+
---Undocumented feature with unknown purpose.
9+
---@param filename string
10+
function file(filename) end
11+
12+
---Mark a test as placeholder.
13+
---
14+
---This will not fail or pass, it will simply be marked as "pending".
15+
---@param name string
16+
---@param block fun()
17+
function pending(name, block) end
18+
19+
---Define the start of an asynchronous test.
20+
---
21+
---Call `done()` at the end of your test to complete it.
22+
---
23+
---## Example
24+
---```
25+
---it("Makes an http request", function()
26+
--- async()
27+
--- http.get("https://github.com.", function()
28+
--- print("Got Website!")
29+
--- done()
30+
--- end)
31+
---end)
32+
---```
33+
function async() end
34+
35+
---Mark the end of an asynchronous test.
36+
---
37+
---Should be paired with a call to `async()`.
38+
function done() end
39+
40+
---Used to define a set of tests. Can be nested to define sub-tests.
41+
---
42+
---## Example
43+
---```
44+
---describe("Test Item Class", function()
45+
--- it("Creates an item", function()
46+
--- --...
47+
--- end)
48+
--- describe("Test Tags", function()
49+
--- it("Creates a tag", function()
50+
--- --...
51+
--- end)
52+
--- end)
53+
---end)
54+
---```
55+
---@param name string
56+
---@param block fun()
57+
function describe(name, block) end
58+
59+
context = describe
60+
61+
---Functions like `describe()` except it exposes the test's environment to
62+
---outer contexts
63+
---
64+
---## Example
65+
---```
66+
---describe("Test exposing", function()
67+
--- expose("Exposes a value", function()
68+
--- _G.myValue = 10
69+
--- end)
70+
---
71+
---end)
72+
---
73+
---describe("Another test in the same file", function()
74+
--- assert.are.equal(10, myValue)
75+
---end)
76+
---```
77+
---@param name string
78+
---@param block fun()
79+
function expose(name, block) end
80+
81+
---Functions like `describe()` except it insulates the test's environment to
82+
---only this context.
83+
---
84+
---This is the default behaviour of `describe()`.
85+
---
86+
---## Example
87+
---```
88+
---describe("Test exposing", function()
89+
--- insulate("Insulates a value", function()
90+
--- _G.myValue = 10
91+
--- end)
92+
---
93+
---end)
94+
---
95+
---describe("Another test in the same file", function()
96+
--- assert.is.Nil(myValue)
97+
---end)
98+
---```
99+
---@param name string
100+
---@param block fun()
101+
function insulate(name, block) end
102+
103+
---Randomize tests nested in this block.
104+
---
105+
---## Example
106+
---```
107+
---describe("A randomized test", function()
108+
--- randomize()
109+
--- it("My order is random", function() end)
110+
--- it("My order is also random", function() end)
111+
---end)
112+
---```
113+
function randomize() end
114+
115+
---Define a test that will pass, fail, or error.
116+
---
117+
---You can also use `spec()` and `test()` as aliases.
118+
---
119+
---## Example
120+
---```
121+
---describe("Test something", function()
122+
--- it("Runs a test", function()
123+
--- assert.is.True(10 == 10)
124+
--- end)
125+
---end)
126+
---```
127+
---@param name string
128+
---@param block fun()
129+
function it(name, block) end
130+
131+
spec = it
132+
test = it
133+
134+
---Define a function to run before each child test, this includes tests nested
135+
---in a child describe block.
136+
---
137+
---## Example
138+
---```
139+
---describe("Test Array Class", function()
140+
--- local a
141+
--- local b
142+
---
143+
--- before_each(function()
144+
--- a = Array.new(1, 2, 3, 4)
145+
--- b = Array.new(11, 12, 13, 14)
146+
--- end)
147+
---
148+
--- it("Assures instance is an Array", function()
149+
--- assert.True(Array.isArray(a))
150+
--- assert.True(Array.isArray(b))
151+
--- end)
152+
---
153+
--- describe("Nested tests", function()
154+
--- it("Also runs before_each", function()
155+
--- assert.are.same(
156+
--- { 1, 2, 3, 4, 11, 12, 13, 14 },
157+
--- a:concat(b))
158+
--- end)
159+
--- end)
160+
---end)
161+
---```
162+
---@param block fun()
163+
function before_each(block) end
164+
165+
---Define a function to run after each child test, this includes tests nested
166+
---in a child describe block.
167+
---
168+
---## Example
169+
---```
170+
---describe("Test saving", function()
171+
--- local game
172+
---
173+
--- after_each(function()
174+
--- game.save.reset()
175+
--- end)
176+
---
177+
--- it("Creates game", function()
178+
--- game = game.new()
179+
--- game.save.save()
180+
--- end)
181+
---
182+
--- describe("Saves metadata", function()
183+
--- it("Saves objects", function()
184+
--- game = game.new()
185+
--- game.save.save()
186+
--- assert.is_not.Nil(game.save.objects)
187+
--- end)
188+
--- end)
189+
---end)
190+
---```
191+
---@param block fun()
192+
function after_each(block) end
193+
194+
---Runs first in a context block before any tests.
195+
---
196+
---Will always run even if there are no child tests to run. If you don't want
197+
---them to run regardless, you can use `lazy_setup()` or use the `--lazy` flag
198+
---when running.
199+
---
200+
---## Example
201+
---```
202+
---describe("Test something", function()
203+
--- local helper
204+
---
205+
--- setup(function()
206+
--- helper = require("helper")
207+
--- end)
208+
---
209+
--- it("Can use helper", function()
210+
--- assert.is_not.Nil(helper)
211+
--- end)
212+
---end)
213+
---```
214+
---@param block fun()
215+
function setup(block) end
216+
217+
strict_setup = setup
218+
219+
---Runs first in a context block before any tests. Only runs if there are child
220+
---tests to run.
221+
---
222+
---## Example
223+
---```
224+
---describe("Test something", function()
225+
--- local helper
226+
---
227+
--- -- Will not run because there are no tests
228+
--- lazy_setup(function()
229+
--- helper = require("helper")
230+
--- end)
231+
---
232+
---end)
233+
---```
234+
---@param block fun()
235+
function lazy_setup(block) end
236+
237+
---Runs last in a context block after all tests.
238+
---
239+
---Will run ever if no tests were run in this context. If you don't want this
240+
---to run regardless, you can use `lazy_teardown()` or use the `--lazy` flag
241+
---when running.
242+
---
243+
---## Example
244+
---```
245+
---describe("Remove persistent value", function()
246+
--- local persist
247+
---
248+
--- it("Sets a persistent value", function()
249+
--- persist = "hello"
250+
--- end)
251+
---
252+
--- teardown(function()
253+
--- persist = nil
254+
--- end)
255+
---
256+
---end)
257+
---```
258+
---@param block fun()
259+
function teardown(block) end
260+
261+
strict_teardown = teardown
262+
263+
---Runs last in a context block after all tests.
264+
---
265+
---Will only run if tests were run in this context.
266+
---
267+
---## Example
268+
---```
269+
---describe("Remove persistent value", function()
270+
--- local persist
271+
---
272+
--- -- Will not run because no tests were run
273+
--- lazy_teardown(function()
274+
--- persist = nil
275+
--- end)
276+
---
277+
---end)
278+
---```
279+
---@param block fun()
280+
function lazy_teardown(block) end
281+
282+
---Runs last in a context block regardless of test outcome
283+
---
284+
---## Example
285+
---```
286+
---it("Read File Contents",function()
287+
--- local f = io.open("file", "r")
288+
---
289+
--- -- always close file after test
290+
--- finally(function()
291+
--- f:close()
292+
--- end)
293+
---
294+
--- -- do stuff with f
295+
---end)
296+
---```
297+
---@param block fun()
298+
function finally(block) end

meta/3rd/luassert/config.lua

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
words = { "assert.%w+" }

0 commit comments

Comments
 (0)