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(neotest): basic support for suite = true #204

Merged
merged 1 commit into from
Feb 1, 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
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added

- Neotest: Basic support for `require('neotest').run.run { suite = true }`.
This will run the current crate's test suite, if detected.
Note that positions are still only discovered for buffers with an attached
LSP client.

## [4.4.0] - 2024-02-01

### Added
Expand Down
21 changes: 16 additions & 5 deletions lua/rustaceanvim/neotest/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,14 @@ NeotestAdapter.discover_positions = function(file_path)
-- We need a runnable for the 'file' position, so we pick the first 'namespace' one
-- Typically, a file only has one test module
---@type RARunnable
local file_runnable = nil
local crate_runnable = nil
local max_end_row = 0
for _, runnable in pairs(runnables) do
local pos = trans.runnable_to_position(file_path, runnable)
if pos then
max_end_row = math.max(max_end_row, pos.range[3])
if pos.type == 'dir' then
file_runnable = runnable
crate_runnable = runnable
else
table.insert(positions, pos)
end
Expand Down Expand Up @@ -145,9 +145,18 @@ NeotestAdapter.discover_positions = function(file_path)
type = 'file',
path = file_path,
range = { 0, 0, max_end_row, 0 },
runnable = namespace_count > 1 and file_runnable or namespace_runnable,
runnable = namespace_count > 1 and crate_runnable or namespace_runnable,
}
table.insert(sorted_positions, 1, file_pos)
local crate_pos = {
id = 'rustaceanvim:' .. crate_runnable.args.workspaceRoot,
name = 'suite',
type = 'dir',
path = crate_runnable.args.workspaceRoot,
range = { 0, 0, 0, 0 },
runnable = crate_runnable,
}
table.insert(sorted_positions, 1, crate_pos)
---@diagnostic disable-next-line: missing-parameter
return lib.positions.parse_tree(sorted_positions)
end
Expand All @@ -165,7 +174,7 @@ end
---@return neotest.RunSpec|nil
---@private
function NeotestAdapter.build_spec(run_args)
local supported_types = { 'test', 'namespace', 'file' }
local supported_types = { 'test', 'namespace', 'file', 'dir' }
local tree = run_args and run_args.tree
if not tree then
return
Expand Down Expand Up @@ -254,7 +263,6 @@ function NeotestAdapter.results(spec, strategy_result)
---@type table<string,neotest.Error[]>
local errors_by_test_id = {}
output_content = output_content:gsub('\r\n', '\n')
-- TODO: Move this to a shared location
local diagostics = require('rustaceanvim.test').parse_diagnostics(context.file, output_content)
for _, diagnostic in pairs(diagostics) do
---@type neotest.Error
Expand All @@ -265,6 +273,9 @@ function NeotestAdapter.results(spec, strategy_result)
errors_by_test_id[diagnostic.test_id] = errors_by_test_id[diagnostic.test_id] or {}
table.insert(errors_by_test_id[diagnostic.test_id], err)
end
if not vim.tbl_contains({ 'file', 'test', 'namespace' }, context.type) then
return results
end
results[ctx_pos_id] = {
status = 'failed',
output = strategy_result.output,
Expand Down
Loading