Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(runsettings): Adds support for runsettings files #125

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,19 @@ require("neotest").setup({
})
```

## Using `.runsettings` files

The plugin provides commands to select and clear the runsettings files (if any are available in the Neovim working director tree).

To select the runsettings file in a Neovim session run:
`:NeotestSelectRunsettingsFile`

- This will apply the runsettings to all tests run via the neotest-adapter

To clear the runsettings file in the same session run:
`:NeotestClearRunsettings`


## Additional `dotnet test` arguments

As well as the `dotnet_additional_args` option in the adapter setup above, you may also provide additional CLI arguments as a table to each `neotest` command.
Expand Down
43 changes: 43 additions & 0 deletions lua/neotest-dotnet/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,49 @@ setmetatable(DotnetNeotestAdapter, {
if type(opts.discovery_root) == "string" then
discovery_root = opts.discovery_root
end

local function find_runsettings_files()
local files = {}
for _, runsettingsFile in
ipairs(vim.fn.glob(vim.fn.getcwd() .. "**/*.runsettings", false, true))
do
table.insert(files, runsettingsFile)
end

for _, runsettingsFile in
ipairs(vim.fn.glob(vim.fn.getcwd() .. "**/.runsettings", false, true))
do
table.insert(files, runsettingsFile)
end

return files
end

local function select_runsettings_file()
local files = find_runsettings_files()
if #files == 0 then
print("No .runsettings files found")
vim.g.neotest_dotnet_runsettings_path = nil
return
end

vim.ui.select(files, {
prompt = "Select runsettings file:",
format_item = function(item)
return vim.fn.fnamemodify(item, ":p:.")
end,
}, function(choice)
if choice then
vim.g.neotest_dotnet_runsettings_path = choice
print("Selected runsettings file: " .. choice)
end
end)
end

vim.api.nvim_create_user_command("NeotestSelectRunsettingsFile", select_runsettings_file, {})
vim.api.nvim_create_user_command("NeotestClearRunsettings", function()
vim.g.neotest_dotnet_runsettings_path = nil
end, {})
return DotnetNeotestAdapter
end,
})
Expand Down
5 changes: 5 additions & 0 deletions lua/neotest-dotnet/utils/build-spec-utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ function BuildSpecUtils.create_single_spec(position, proj_root, filter_arg, dotn
end
end

if vim.g.neotest_dotnet_runsettings_path then
table.insert(command, "--settings")
table.insert(command, vim.g.neotest_dotnet_runsettings_path)
end

local command_string = table.concat(command, " ")

logger.debug("neotest-dotnet: Running tests using command: " .. command_string)
Expand Down
Loading