Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 0 additions & 16 deletions TESTS_README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,19 +135,3 @@ To test this in your `~/.config/nvim` configuration, try the suggested file stru
lua/example/module.lua
lua/spec/example/module_spec.lua
```

# Asynchronous testing

Tests run in a coroutine, which can be yielded and resumed. This can be used to
test code that uses asynchronous Neovim functionalities. For example, this can
be done inside a test:

```lua
local co = coroutine.running()
vim.defer_fn(function()
coroutine.resume(co)
end, 1000)
--The test will reach here immediately.
coroutine.yield()
--The test will only reach here after one second, when the deferred function runs.
```
52 changes: 24 additions & 28 deletions lua/plenary/busted.lua
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,9 @@ mod.run = function(file)
print("\n" .. HEADER)
print("Testing: ", file)

local loaded, msg = loadfile(file)
local ok, msg = pcall(dofile, file)

if not loaded then
if not ok then
print(HEADER)
print "FAILED TO LOAD FILE"
print(color_string("red", msg))
Expand All @@ -232,37 +232,33 @@ mod.run = function(file)
end
end

coroutine.wrap(function()
loaded()

-- If nothing runs (empty file without top level describe)
if not results.pass then
if is_headless then
return vim.cmd "0cq"
else
return
end
-- If nothing runs (empty file without top level describe)
if not results.pass then
if is_headless then
return vim.cmd "0cq"
else
return
end
end

mod.format_results(results)
mod.format_results(results)

if #results.errs ~= 0 then
print("We had an unexpected error: ", vim.inspect(results.errs), vim.inspect(results))
if is_headless then
return vim.cmd "2cq"
end
elseif #results.fail > 0 then
print "Tests Failed. Exit: 1"
if #results.errs ~= 0 then
print("We had an unexpected error: ", vim.inspect(results.errs), vim.inspect(results))
if is_headless then
return vim.cmd "2cq"
end
elseif #results.fail > 0 then
print "Tests Failed. Exit: 1"

if is_headless then
return vim.cmd "1cq"
end
else
if is_headless then
return vim.cmd "0cq"
end
if is_headless then
return vim.cmd "1cq"
end
end)()
else
if is_headless then
return vim.cmd "0cq"
end
end
end

return mod
75 changes: 0 additions & 75 deletions tests/plenary/async_testing_spec.lua

This file was deleted.