diff --git a/lua/plenary/busted.lua b/lua/plenary/busted.lua index 6d1e91e1..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 @@ -8,6 +10,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 +173,20 @@ local run_each = function(tbl) end end +local matches_filter = function(desc) + if not busted_opts.filter then + return true + end + + local desc_stack = table.concat(current_description, " ") .. desc + return desc_stack:match(busted_opts.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,6 +215,10 @@ 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, " ")) @@ -214,7 +234,9 @@ after_each = mod.after_each clear = mod.clear assert = require "luassert" -mod.run = function(file) +mod.run = function(file, opts) + busted_opts = vim.F.if_nil(opts, {}, opts) + 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