Skip to content

Commit

Permalink
Merge pull request #68 from Frederick888/fix-mod-path
Browse files Browse the repository at this point in the history
Fix mod path when both mod file and mod dir exist
  • Loading branch information
rouge8 authored Jan 3, 2024
2 parents 48c1e14 + 2b0a3f8 commit 3c06f23
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 7 deletions.
5 changes: 4 additions & 1 deletion lua/neotest-rust/dap.lua
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,18 @@ end
-- Determine if mod is in <mod_name>.rs or <mod_name>/mod.rs
local function construct_mod_path(src_path, mod_name)
local match_str = "(.-)[^\\/]-%.?(%w+)%.?[^\\/]*$"
local abs_path, _ = string.match(src_path, match_str)
local abs_path, parent_mod = string.match(src_path, match_str)

local mod_file = abs_path .. mod_name .. ".rs"
local mod_dir = abs_path .. mod_name .. sep .. "mod.rs"
local child_mod = abs_path .. parent_mod .. sep .. mod_name .. ".rs"

if util.file_exists(mod_file) then
return mod_file
elseif util.file_exists(mod_dir) then
return mod_dir
elseif util.file_exists(child_mod) then
return child_mod
end

return nil
Expand Down
7 changes: 7 additions & 0 deletions tests/dap_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ describe("get_test_binary", function()
assert.equal(expected, actual)
end)

async.it("returns the test binary for src/parent/child.rs", function()
local expected = main_actual
local actual = dap.get_test_binary(root, root .. "/src/parent/child.rs")

assert.equal(expected, actual)
end)

async.it("returns the test binary for tests/test_it.rs", function()
assert(test_it_actual)
local expected = root .. "/target/debug/deps/test_it-"
Expand Down
1 change: 1 addition & 0 deletions tests/data/simple-package/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
mod mymod;
mod parent;

fn main() {
println!("Hello, world!");
Expand Down
1 change: 1 addition & 0 deletions tests/data/simple-package/src/parent.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod child;
7 changes: 7 additions & 0 deletions tests/data/simple-package/src/parent/child.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#[cfg(test)]
mod tests {
#[test]
fn math() {
assert_eq!(1 + 1, 2);
}
}
12 changes: 6 additions & 6 deletions tests/init_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,23 @@ describe("discover_positions", function()
id = vim.loop.cwd() .. "/tests/data/simple-package/src/main.rs",
name = "main.rs",
path = vim.loop.cwd() .. "/tests/data/simple-package/src/main.rs",
range = { 0, 0, 25, 0 },
range = { 0, 0, 26, 0 },
type = "file",
},
{
{
id = "tests",
name = "tests",
path = vim.loop.cwd() .. "/tests/data/simple-package/src/main.rs",
range = { 7, 0, 24, 1 },
range = { 8, 0, 25, 1 },
type = "namespace",
},
{
{
id = "tests::basic_math",
name = "basic_math",
path = vim.loop.cwd() .. "/tests/data/simple-package/src/main.rs",
range = { 9, 4, 11, 5 },
range = { 10, 4, 12, 5 },
type = "test",
},
},
Expand All @@ -51,7 +51,7 @@ describe("discover_positions", function()
id = "tests::failed_math",
name = "failed_math",
path = vim.loop.cwd() .. "/tests/data/simple-package/src/main.rs",
range = { 14, 4, 16, 5 },
range = { 15, 4, 17, 5 },
type = "test",
},
},
Expand All @@ -60,15 +60,15 @@ describe("discover_positions", function()
id = "tests::nested",
name = "nested",
path = vim.loop.cwd() .. "/tests/data/simple-package/src/main.rs",
range = { 18, 4, 23, 5 },
range = { 19, 4, 24, 5 },
type = "namespace",
},
{
{
id = "tests::nested::nested_math",
name = "nested_math",
path = vim.loop.cwd() .. "/tests/data/simple-package/src/main.rs",
range = { 20, 8, 22, 9 },
range = { 21, 8, 23, 9 },
type = "test",
},
},
Expand Down

0 comments on commit 3c06f23

Please sign in to comment.