Skip to content

Commit

Permalink
Merge pull request #74 from jsiefer/main
Browse files Browse the repository at this point in the history
Construction mod path fails for names with underscores
  • Loading branch information
rouge8 committed Feb 28, 2024
2 parents 392b54e + aa4f08e commit 9e9df68
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lua/neotest-rust/dap.lua
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ 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 match_str = "(.-)[^\\/]-%.?([%w_]+)%.?[^\\/]*$"
local abs_path, parent_mod = string.match(src_path, match_str)

local mod_file = abs_path .. mod_name .. ".rs"
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,5 +1,6 @@
mod mymod;
mod parent;
mod other_mod;

fn main() {
println!("Hello, world!");
Expand Down
1 change: 1 addition & 0 deletions tests/data/simple-package/src/other_mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mod foo;
7 changes: 7 additions & 0 deletions tests/data/simple-package/src/other_mod/foo.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);
}
}
43 changes: 37 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, 26, 0 },
range = { 0, 0, 27, 0 },
type = "file",
},
{
{
id = "tests",
name = "tests",
path = vim.loop.cwd() .. "/tests/data/simple-package/src/main.rs",
range = { 8, 0, 25, 1 },
range = { 9, 0, 26, 1 },
type = "namespace",
},
{
{
id = "tests::basic_math",
name = "basic_math",
path = vim.loop.cwd() .. "/tests/data/simple-package/src/main.rs",
range = { 10, 4, 12, 5 },
range = { 11, 4, 13, 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 = { 15, 4, 17, 5 },
range = { 16, 4, 18, 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 = { 19, 4, 24, 5 },
range = { 20, 4, 25, 5 },
type = "namespace",
},
{
{
id = "tests::nested::nested_math",
name = "nested_math",
path = vim.loop.cwd() .. "/tests/data/simple-package/src/main.rs",
range = { 21, 8, 23, 9 },
range = { 22, 8, 24, 9 },
type = "test",
},
},
Expand Down Expand Up @@ -465,6 +465,20 @@ describe("build_spec", function()
assert.equal(spec.cwd, vim.loop.cwd() .. "/tests/data/simple-package")
end)

it("can run tests in other_mod/foo.rs", function()
local tree = Tree:new({
type = "file",
path = vim.loop.cwd() .. "/tests/data/simple-package/src/other_mod/foo.rs",
id = vim.loop.cwd() .. "/tests/data/simple-package/src/other_mod/foo.rs",
}, {}, function(data)
return data
end, {})

local spec = plugin.build_spec({ tree = tree })
assert.equal(spec.context.test_filter, "-E " .. vim.fn.shellescape("test(/^other_mod::foo::/)"))
assert.equal(spec.cwd, vim.loop.cwd() .. "/tests/data/simple-package")
end)

it("can run a single integration test", function()
local tree = Tree:new({
type = "test",
Expand Down Expand Up @@ -791,6 +805,23 @@ describe("build_spec", function()
assert.equal(spec.cwd, vim.loop.cwd() .. "/tests/data/simple-package")
end)

async.it("can debug tests in other_mod/foo.rs", function()
local tree = Tree:new({
type = "file",
path = vim.loop.cwd() .. "/tests/data/simple-package/src/other_mod/foo.rs",
id = vim.loop.cwd() .. "/tests/data/simple-package/src/other_mod/foo.rs",
}, {}, function(data)
return data
end, {})

local spec = plugin.build_spec({ tree = tree, strategy = "dap" })
assert.are.same(spec.strategy.args, {
"--nocapture",
"other_mod::foo",
})
assert.equal(spec.cwd, vim.loop.cwd() .. "/tests/data/simple-package")
end)

async.it("can debug a single integration test", function()
local tree = Tree:new({
type = "test",
Expand Down

0 comments on commit 9e9df68

Please sign in to comment.