Skip to content

Commit

Permalink
Add neovim compatibility functions (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
MisanthropicBit authored Nov 9, 2024
1 parent edebc6b commit 87bffd9
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
11 changes: 11 additions & 0 deletions lua/neotest-busted/compat.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
local compat = {}

if vim.fn.has("nvim-0.10") == 1 then
compat.tbl_islist = vim.islist
compat.loop = vim.uv
else
compat.tbl_islist = vim.tbl_islist
compat.loop = vim.loop
end

return compat
4 changes: 3 additions & 1 deletion lua/neotest-busted/config.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
local config = {}

local compat = require("neotest-busted.compat")

---@type neotest-busted.Config
local default_config = {
busted_command = nil,
Expand Down Expand Up @@ -27,7 +29,7 @@ local function is_optional_string_list(value)
return true
end

if not vim.tbl_islist(value) then
if not compat.tbl_islist(value) then
return false, "must be a list-like table"
end

Expand Down
14 changes: 8 additions & 6 deletions lua/neotest-busted/init.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
local Cache = require("neotest-busted.cache")
local compat = require("neotest-busted.compat")
local config = require("neotest-busted.config")
local logging = require("neotest-busted.logging")
local util = require("neotest-busted.util")
Expand Down Expand Up @@ -181,11 +182,11 @@ function BustedNeotestAdapter.create_test_command(paths, options)

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

if vim.tbl_islist(config.busted_cpaths) then
if compat.tbl_islist(config.busted_cpaths) then
vim.list_extend(lua_cpaths, config.busted_cpaths)
end

Expand Down Expand Up @@ -234,15 +235,15 @@ function BustedNeotestAdapter.create_test_command(paths, options)

vim.list_extend(arguments, busted_command)

if vim.tbl_islist(config.busted_args) then
if compat.tbl_islist(config.busted_args) then
for _, busted_arg in ipairs(config.busted_args) do
local arg = _options.quote_strings and quote_string(busted_arg) or busted_arg

table.insert(arguments, arg)
end
end

if vim.tbl_islist(_options.busted_arguments) then
if compat.tbl_islist(_options.busted_arguments) then
for _, busted_arg in ipairs(_options.busted_arguments) do
local arg = _options.quote_strings and quote_string(busted_arg) or busted_arg

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

return {
nvim_command = vim.loop.exepath(),
---@diagnostic disable-next-line: undefined-field
nvim_command = compat.loop.exepath(),
arguments = arguments,
paths = lua_paths,
cpaths = lua_cpaths,
Expand Down Expand Up @@ -527,7 +529,7 @@ function BustedNeotestAdapter.build_spec(args)
local command = vim.list_extend({ test_command.nvim_command }, test_command.arguments)

-- Extra arguments for busted
if vim.tbl_islist(args.extra_args) then
if compat.tbl_islist(args.extra_args) then
vim.list_extend(command, args.extra_args)
end

Expand Down
1 change: 1 addition & 0 deletions tests/util_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ describe("util", function()
"lua/neotest-busted/async.lua",
"lua/neotest-busted/busted-util.lua",
"lua/neotest-busted/cache.lua",
"lua/neotest-busted/compat.lua",
"lua/neotest-busted/config.lua",
"lua/neotest-busted/health.lua",
"lua/neotest-busted/init.lua",
Expand Down

0 comments on commit 87bffd9

Please sign in to comment.