Skip to content

Commit eb90ee5

Browse files
authored
Revert "feat: make tests run in coroutine to support asynchronous testing (#426)"
This reverts commit 1252cb3.
1 parent 9d81624 commit eb90ee5

File tree

3 files changed

+24
-119
lines changed

3 files changed

+24
-119
lines changed

TESTS_README.md

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -135,19 +135,3 @@ To test this in your `~/.config/nvim` configuration, try the suggested file stru
135135
lua/example/module.lua
136136
lua/spec/example/module_spec.lua
137137
```
138-
139-
# Asynchronous testing
140-
141-
Tests run in a coroutine, which can be yielded and resumed. This can be used to
142-
test code that uses asynchronous Neovim functionalities. For example, this can
143-
be done inside a test:
144-
145-
```lua
146-
local co = coroutine.running()
147-
vim.defer_fn(function()
148-
coroutine.resume(co)
149-
end, 1000)
150-
--The test will reach here immediately.
151-
coroutine.yield()
152-
--The test will only reach here after one second, when the deferred function runs.
153-
```

lua/plenary/busted.lua

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,9 @@ mod.run = function(file)
218218
print("\n" .. HEADER)
219219
print("Testing: ", file)
220220

221-
local loaded, msg = loadfile(file)
221+
local ok, msg = pcall(dofile, file)
222222

223-
if not loaded then
223+
if not ok then
224224
print(HEADER)
225225
print "FAILED TO LOAD FILE"
226226
print(color_string("red", msg))
@@ -232,37 +232,33 @@ mod.run = function(file)
232232
end
233233
end
234234

235-
coroutine.wrap(function()
236-
loaded()
237-
238-
-- If nothing runs (empty file without top level describe)
239-
if not results.pass then
240-
if is_headless then
241-
return vim.cmd "0cq"
242-
else
243-
return
244-
end
235+
-- If nothing runs (empty file without top level describe)
236+
if not results.pass then
237+
if is_headless then
238+
return vim.cmd "0cq"
239+
else
240+
return
245241
end
242+
end
246243

247-
mod.format_results(results)
244+
mod.format_results(results)
248245

249-
if #results.errs ~= 0 then
250-
print("We had an unexpected error: ", vim.inspect(results.errs), vim.inspect(results))
251-
if is_headless then
252-
return vim.cmd "2cq"
253-
end
254-
elseif #results.fail > 0 then
255-
print "Tests Failed. Exit: 1"
246+
if #results.errs ~= 0 then
247+
print("We had an unexpected error: ", vim.inspect(results.errs), vim.inspect(results))
248+
if is_headless then
249+
return vim.cmd "2cq"
250+
end
251+
elseif #results.fail > 0 then
252+
print "Tests Failed. Exit: 1"
256253

257-
if is_headless then
258-
return vim.cmd "1cq"
259-
end
260-
else
261-
if is_headless then
262-
return vim.cmd "0cq"
263-
end
254+
if is_headless then
255+
return vim.cmd "1cq"
264256
end
265-
end)()
257+
else
258+
if is_headless then
259+
return vim.cmd "0cq"
260+
end
261+
end
266262
end
267263

268264
return mod

tests/plenary/async_testing_spec.lua

Lines changed: 0 additions & 75 deletions
This file was deleted.

0 commit comments

Comments
 (0)