From 2f9f03d75dc245556e2d0d88a561babf8ec3c7f0 Mon Sep 17 00:00:00 2001 From: Jose Veiga Date: Sun, 12 Jun 2022 15:59:02 -0400 Subject: [PATCH 1/2] feat(busted): option to filter test to run by pattern [wip] --- lua/plenary/busted.lua | 23 ++++++++++++++++++++++- lua/plenary/test_harness.lua | 13 ++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/lua/plenary/busted.lua b/lua/plenary/busted.lua index 6d1e91e1..f58621f2 100644 --- a/lua/plenary/busted.lua +++ b/lua/plenary/busted.lua @@ -8,6 +8,7 @@ local function get_trace(element, level, msg) info.traceback = info.traceback:sub(1, index) return info end + level = level or 3 local thisdir = dirname(debug.getinfo(1, "Sl").source, ":h") @@ -170,7 +171,20 @@ local run_each = function(tbl) end end +local matches_filter = function(desc) + if not _PlenaryBustedOpts.filter then + return true + end + + local desc_stack = table.concat(current_description, " ") .. desc + return desc_stack:match(_PlenaryBustedOpts.filter) +end + mod.it = function(desc, func) + if not matches_filter(desc) then + return + end + run_each(current_before_each) local ok, msg, desc_stack = call_inner(desc, func) run_each(current_after_each) @@ -199,12 +213,17 @@ mod.it = function(desc, func) end mod.pending = function(desc, func) + if not matches_filter(desc) then + return + end + local curr_stack = vim.deepcopy(current_description) table.insert(curr_stack, desc) print(PENDING, "||", table.concat(curr_stack, " ")) end _PlenaryBustedOldAssert = _PlenaryBustedOldAssert or assert +_PlenaryBustedOpts = {} -- TODO: check if this should be here? describe = mod.describe it = mod.it @@ -214,7 +233,9 @@ after_each = mod.after_each clear = mod.clear assert = require "luassert" -mod.run = function(file) +mod.run = function(file, opts) + _PlenaryBustedOpts = vim.tbl_deep_extend("force", {}, opts or {}) + print("\n" .. HEADER) print("Testing: ", file) diff --git a/lua/plenary/test_harness.lua b/lua/plenary/test_harness.lua index e404921f..679979af 100644 --- a/lua/plenary/test_harness.lua +++ b/lua/plenary/test_harness.lua @@ -30,6 +30,8 @@ local get_nvim_output = function(job_id) end function harness.test_directory_command(command) + -- TODO: this is broken if we pass mutliple args! + -- figure out if there is a way to call vim commands with lua tables as args. local split_string = vim.split(command, " ") local directory = table.remove(split_string, 1) @@ -78,11 +80,20 @@ function harness.test_directory(directory, opts) local failure = false + local busted_opts = {} + if opts.filter then + busted_opts.filter = opts.filter + end + local jobs = vim.tbl_map(function(p) 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(), + vim.inspect(busted_opts) -- TODO: find better way to do this! + ), } if opts.minimal ~= nil then From 9f033d1469312c51521cf27c64925904bd6400b7 Mon Sep 17 00:00:00 2001 From: Jose Veiga Date: Sun, 12 Jun 2022 16:41:57 -0400 Subject: [PATCH 2/2] refactor(busted): rename _PlenaryBustedOpts to busted_opts --- lua/plenary/busted.lua | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lua/plenary/busted.lua b/lua/plenary/busted.lua index f58621f2..62e4131b 100644 --- a/lua/plenary/busted.lua +++ b/lua/plenary/busted.lua @@ -1,3 +1,5 @@ +local busted_opts + local dirname = function(p) return vim.fn.fnamemodify(p, ":h") end @@ -172,12 +174,12 @@ local run_each = function(tbl) end local matches_filter = function(desc) - if not _PlenaryBustedOpts.filter then + if not busted_opts.filter then return true end local desc_stack = table.concat(current_description, " ") .. desc - return desc_stack:match(_PlenaryBustedOpts.filter) + return desc_stack:match(busted_opts.filter) end mod.it = function(desc, func) @@ -223,7 +225,6 @@ mod.pending = function(desc, func) end _PlenaryBustedOldAssert = _PlenaryBustedOldAssert or assert -_PlenaryBustedOpts = {} -- TODO: check if this should be here? describe = mod.describe it = mod.it @@ -234,7 +235,7 @@ clear = mod.clear assert = require "luassert" mod.run = function(file, opts) - _PlenaryBustedOpts = vim.tbl_deep_extend("force", {}, opts or {}) + busted_opts = vim.F.if_nil(opts, {}, opts) print("\n" .. HEADER) print("Testing: ", file)