Skip to content

Commit

Permalink
feat(busted): add keep-going option
Browse files Browse the repository at this point in the history
  • Loading branch information
rish987 committed Jul 27, 2021
1 parent 8bae2c1 commit 9765aa8
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
29 changes: 28 additions & 1 deletion lua/plenary/busted.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ local current_description = {}
local current_before_each = {}
local current_after_each = {}

local abort = false
local run_opts = {}

local add_description = function(desc)
table.insert(current_description, desc)

Expand Down Expand Up @@ -104,6 +107,7 @@ end
local SUCCESS = color_string("green", "Success")
local FAIL = color_string("red", "Fail")
local PENDING = color_string("yellow", "Pending")
local ABORTED = color_string("yellow", "Aborted")

local HEADER = string.rep("=", 40)

Expand Down Expand Up @@ -174,6 +178,11 @@ local run_each = function(tbl)
end

mod.it = function(desc, func)
if abort then
print(ABORTED, "||", table.concat(current_description, " "), desc)
return
end

run_each(current_before_each)
local ok, msg, desc_stack = call_inner(desc, func)
run_each(current_after_each)
Expand All @@ -193,6 +202,10 @@ mod.it = function(desc, func)

print(FAIL, "||", table.concat(test_result.descriptions, " "))
print(indent(msg, 12))

if not run_opts.keep_going then
abort = true
end
else
to_insert = results.pass
print(SUCCESS, "||", table.concat(test_result.descriptions, " "))
Expand All @@ -218,7 +231,21 @@ after_each = mod.after_each
clear = mod.clear
assert = require("luassert")

mod.run = function(file)
function mod.run_command(command)
local split_string = vim.split(command, " ")
local file = table.remove(split_string, 1)

local opts = {}
if #split_string > 0 then
opts = assert(loadstring('return ' .. table.concat(split_string, " ")))()
end

return mod.run(file, opts)
end

mod.run = function(file, opts)
run_opts = opts or {}

print("\n" .. HEADER)
print("Testing: ", file)

Expand Down
4 changes: 3 additions & 1 deletion lua/plenary/test_harness.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ end
function harness.test_directory(directory, opts)
print("Starting...")
opts = vim.tbl_deep_extend('force', {winopts = {winblend = 3}}, opts or {})
local run_opts = vim.tbl_deep_extend('force', {keep_going = false}, opts.run_opts or {})
local run_opts_string = vim.inspect(run_opts):gsub("\n", " ")

local res = {}
if not headless then
Expand Down Expand Up @@ -72,7 +74,7 @@ function harness.test_directory(directory, opts)
local args = {
'--headless',
'-c',
string.format('lua require("plenary.busted").run("%s")', p:absolute())
string.format('lua require("plenary.busted").run("%s", %s)', p:absolute(), run_opts_string)
}

if opts.minimal ~= nil then
Expand Down
2 changes: 1 addition & 1 deletion plugin/plenary.vim
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

" Create command for running busted
command! -nargs=1 -complete=file PlenaryBustedFile
\ lua require('plenary.busted').run(vim.fn.expand("<args>"))
\ lua require('plenary.busted').run_command(vim.fn.expand("<args>"))

command! -nargs=+ -complete=file PlenaryBustedDirectory
\ lua require('plenary.test_harness').test_directory_command(vim.fn.expand("<args>"))
Expand Down

0 comments on commit 9765aa8

Please sign in to comment.