Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep-going option for busted-style tests #197

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
33 changes: 32 additions & 1 deletion lua/plenary/busted.lua
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,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 @@ -99,6 +102,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 @@ -170,6 +174,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 @@ -189,6 +198,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 @@ -213,7 +226,25 @@ after_each = mod.after_each
clear = mod.clear
assert = require "luassert"

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

local opts = {}
if #split_string > 0 then
if json then
opts = vim.fn.json_decode(table.concat(split_string, " "))
else
opts = assert(loadstring("return " .. table.concat(split_string, " ")))()
end
end

return mod.run(file, opts)
end

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

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

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

local res = {}
if not headless then
Expand Down Expand Up @@ -68,10 +70,11 @@ function harness.test_directory(directory, opts)
local failure = false

local jobs = vim.tbl_map(function(p)
local command_string = p:absolute() .. " " .. run_opts_string
local args = {
"--headless",
"-c",
string.format('lua require("plenary.busted").run("%s")', p:absolute()),
string.format('lua require("plenary.busted").run_command([=[%s]=], true)', command_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