Skip to content

Commit

Permalink
Exclude test case in Cargo's target directory
Browse files Browse the repository at this point in the history
Fixes #59.
  • Loading branch information
rouge8 committed Dec 3, 2023
1 parent 46428d9 commit 48c1e14
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lua/neotest-rust/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ function adapter.is_test_file(file_path)
return vim.endswith(file_path, ".rs") and #adapter.discover_positions(file_path):to_list() ~= 1
end

---Filter directories when searching for test files
---@async
---@param name string Name of directory
---@param rel_path string Path to directory, relative to root
---@param root string Root directory of project
---@return boolean
function adapter.filter_dir(name, rel_path, root)
return root .. Path.path.sep .. rel_path ~= cargo_metadata(root).target_directory
end

local get_package_root = lib.files.match_root_pattern("Cargo.toml")

local function is_unit_test(path)
Expand Down
16 changes: 16 additions & 0 deletions tests/init_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1131,3 +1131,19 @@ describe("results", function()
assert.are.same(expected, results)
end)
end)

describe("filter_dir", function()
it("doesn't exclude the src directory", function()
local adapter = require("neotest-rust")({})
local root = vim.loop.cwd() .. "/tests/data/simple-package"

assert.equals(adapter.filter_dir("src", "src", root), true)
end)

it("excludes the target directory", function()
local adapter = require("neotest-rust")({})
local root = vim.loop.cwd() .. "/tests/data/simple-package"

assert.equals(adapter.filter_dir("target", "target", root), false)
end)
end)

0 comments on commit 48c1e14

Please sign in to comment.