Skip to content

Commit 2f9f03d

Browse files
committed
feat(busted): option to filter test to run by pattern [wip]
1 parent 968a4b9 commit 2f9f03d

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

lua/plenary/busted.lua

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ local function get_trace(element, level, msg)
88
info.traceback = info.traceback:sub(1, index)
99
return info
1010
end
11+
1112
level = level or 3
1213

1314
local thisdir = dirname(debug.getinfo(1, "Sl").source, ":h")
@@ -170,7 +171,20 @@ local run_each = function(tbl)
170171
end
171172
end
172173

174+
local matches_filter = function(desc)
175+
if not _PlenaryBustedOpts.filter then
176+
return true
177+
end
178+
179+
local desc_stack = table.concat(current_description, " ") .. desc
180+
return desc_stack:match(_PlenaryBustedOpts.filter)
181+
end
182+
173183
mod.it = function(desc, func)
184+
if not matches_filter(desc) then
185+
return
186+
end
187+
174188
run_each(current_before_each)
175189
local ok, msg, desc_stack = call_inner(desc, func)
176190
run_each(current_after_each)
@@ -199,12 +213,17 @@ mod.it = function(desc, func)
199213
end
200214

201215
mod.pending = function(desc, func)
216+
if not matches_filter(desc) then
217+
return
218+
end
219+
202220
local curr_stack = vim.deepcopy(current_description)
203221
table.insert(curr_stack, desc)
204222
print(PENDING, "||", table.concat(curr_stack, " "))
205223
end
206224

207225
_PlenaryBustedOldAssert = _PlenaryBustedOldAssert or assert
226+
_PlenaryBustedOpts = {} -- TODO: check if this should be here?
208227

209228
describe = mod.describe
210229
it = mod.it
@@ -214,7 +233,9 @@ after_each = mod.after_each
214233
clear = mod.clear
215234
assert = require "luassert"
216235

217-
mod.run = function(file)
236+
mod.run = function(file, opts)
237+
_PlenaryBustedOpts = vim.tbl_deep_extend("force", {}, opts or {})
238+
218239
print("\n" .. HEADER)
219240
print("Testing: ", file)
220241

lua/plenary/test_harness.lua

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ local get_nvim_output = function(job_id)
3030
end
3131

3232
function harness.test_directory_command(command)
33+
-- TODO: this is broken if we pass mutliple args!
34+
-- figure out if there is a way to call vim commands with lua tables as args.
3335
local split_string = vim.split(command, " ")
3436
local directory = table.remove(split_string, 1)
3537

@@ -78,11 +80,20 @@ function harness.test_directory(directory, opts)
7880

7981
local failure = false
8082

83+
local busted_opts = {}
84+
if opts.filter then
85+
busted_opts.filter = opts.filter
86+
end
87+
8188
local jobs = vim.tbl_map(function(p)
8289
local args = {
8390
"--headless",
8491
"-c",
85-
string.format('lua require("plenary.busted").run("%s")', p:absolute()),
92+
string.format(
93+
'lua require("plenary.busted").run("%s", %s)',
94+
p:absolute(),
95+
vim.inspect(busted_opts) -- TODO: find better way to do this!
96+
),
8697
}
8798

8899
if opts.minimal ~= nil then

0 commit comments

Comments
 (0)