Skip to content

Commit 87bffd9

Browse files
Add neovim compatibility functions (#28)
1 parent edebc6b commit 87bffd9

File tree

4 files changed

+23
-7
lines changed

4 files changed

+23
-7
lines changed

lua/neotest-busted/compat.lua

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
local compat = {}
2+
3+
if vim.fn.has("nvim-0.10") == 1 then
4+
compat.tbl_islist = vim.islist
5+
compat.loop = vim.uv
6+
else
7+
compat.tbl_islist = vim.tbl_islist
8+
compat.loop = vim.loop
9+
end
10+
11+
return compat

lua/neotest-busted/config.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
local config = {}
22

3+
local compat = require("neotest-busted.compat")
4+
35
---@type neotest-busted.Config
46
local default_config = {
57
busted_command = nil,
@@ -27,7 +29,7 @@ local function is_optional_string_list(value)
2729
return true
2830
end
2931

30-
if not vim.tbl_islist(value) then
32+
if not compat.tbl_islist(value) then
3133
return false, "must be a list-like table"
3234
end
3335

lua/neotest-busted/init.lua

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
local Cache = require("neotest-busted.cache")
2+
local compat = require("neotest-busted.compat")
23
local config = require("neotest-busted.config")
34
local logging = require("neotest-busted.logging")
45
local util = require("neotest-busted.util")
@@ -181,11 +182,11 @@ function BustedNeotestAdapter.create_test_command(paths, options)
181182

182183
-- TODO: Should paths be quoted? Try seeing if a path with a space works
183184
-- Append custom paths from config
184-
if vim.tbl_islist(config.busted_paths) then
185+
if compat.tbl_islist(config.busted_paths) then
185186
vim.list_extend(lua_paths, config.busted_paths)
186187
end
187188

188-
if vim.tbl_islist(config.busted_cpaths) then
189+
if compat.tbl_islist(config.busted_cpaths) then
189190
vim.list_extend(lua_cpaths, config.busted_cpaths)
190191
end
191192

@@ -234,15 +235,15 @@ function BustedNeotestAdapter.create_test_command(paths, options)
234235

235236
vim.list_extend(arguments, busted_command)
236237

237-
if vim.tbl_islist(config.busted_args) then
238+
if compat.tbl_islist(config.busted_args) then
238239
for _, busted_arg in ipairs(config.busted_args) do
239240
local arg = _options.quote_strings and quote_string(busted_arg) or busted_arg
240241

241242
table.insert(arguments, arg)
242243
end
243244
end
244245

245-
if vim.tbl_islist(_options.busted_arguments) then
246+
if compat.tbl_islist(_options.busted_arguments) then
246247
for _, busted_arg in ipairs(_options.busted_arguments) do
247248
local arg = _options.quote_strings and quote_string(busted_arg) or busted_arg
248249

@@ -269,7 +270,8 @@ function BustedNeotestAdapter.create_test_command(paths, options)
269270
end
270271

271272
return {
272-
nvim_command = vim.loop.exepath(),
273+
---@diagnostic disable-next-line: undefined-field
274+
nvim_command = compat.loop.exepath(),
273275
arguments = arguments,
274276
paths = lua_paths,
275277
cpaths = lua_cpaths,
@@ -527,7 +529,7 @@ function BustedNeotestAdapter.build_spec(args)
527529
local command = vim.list_extend({ test_command.nvim_command }, test_command.arguments)
528530

529531
-- Extra arguments for busted
530-
if vim.tbl_islist(args.extra_args) then
532+
if compat.tbl_islist(args.extra_args) then
531533
vim.list_extend(command, args.extra_args)
532534
end
533535

tests/util_spec.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ describe("util", function()
2727
"lua/neotest-busted/async.lua",
2828
"lua/neotest-busted/busted-util.lua",
2929
"lua/neotest-busted/cache.lua",
30+
"lua/neotest-busted/compat.lua",
3031
"lua/neotest-busted/config.lua",
3132
"lua/neotest-busted/health.lua",
3233
"lua/neotest-busted/init.lua",

0 commit comments

Comments
 (0)