From d43df823d5b7d7a06cc0378e805656fb1032f786 Mon Sep 17 00:00:00 2001 From: Rishikesh Vaishnav Date: Mon, 26 Jul 2021 19:47:44 -0700 Subject: [PATCH] feat(busted): add keep-going option (#196) --- lua/plenary/busted.lua | 29 ++++++++++++++++++++++++++++- lua/plenary/test_harness.lua | 4 +++- plugin/plenary.vim | 2 +- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/lua/plenary/busted.lua b/lua/plenary/busted.lua index 946e2aa45..8d17a81ef 100644 --- a/lua/plenary/busted.lua +++ b/lua/plenary/busted.lua @@ -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) @@ -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) @@ -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) @@ -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, " ")) @@ -213,7 +226,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) diff --git a/lua/plenary/test_harness.lua b/lua/plenary/test_harness.lua index 23e3dbde5..58caf3ffc 100644 --- a/lua/plenary/test_harness.lua +++ b/lua/plenary/test_harness.lua @@ -42,6 +42,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 @@ -74,7 +76,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 diff --git a/plugin/plenary.vim b/plugin/plenary.vim index d0ac14b0b..ea17e75eb 100644 --- a/plugin/plenary.vim +++ b/plugin/plenary.vim @@ -1,7 +1,7 @@ " Create command for running busted command! -nargs=1 -complete=file PlenaryBustedFile - \ lua require('plenary.busted').run(vim.fn.expand("")) + \ lua require('plenary.busted').run_command(vim.fn.expand("")) command! -nargs=+ -complete=file PlenaryBustedDirectory \ lua require('plenary.test_harness').test_directory_command(vim.fn.expand(""))