From 9765aa8eae386377693259019d24ea94b7ef79d7 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 --- 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 57b36e6bc..da6b55da4 100644 --- a/lua/plenary/busted.lua +++ b/lua/plenary/busted.lua @@ -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) @@ -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) @@ -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) @@ -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, " ")) @@ -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) diff --git a/lua/plenary/test_harness.lua b/lua/plenary/test_harness.lua index 87aeeb411..412959f4b 100644 --- a/lua/plenary/test_harness.lua +++ b/lua/plenary/test_harness.lua @@ -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 @@ -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 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(""))