diff --git a/lua/neotest-rust/dap.lua b/lua/neotest-rust/dap.lua index 174dce9..9f771d9 100644 --- a/lua/neotest-rust/dap.lua +++ b/lua/neotest-rust/dap.lua @@ -82,7 +82,7 @@ end -- Determine if mod is in .rs or /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" diff --git a/tests/data/simple-package/src/main.rs b/tests/data/simple-package/src/main.rs index bb0a2f4..693614a 100644 --- a/tests/data/simple-package/src/main.rs +++ b/tests/data/simple-package/src/main.rs @@ -1,5 +1,6 @@ mod mymod; mod parent; +mod other_mod; fn main() { println!("Hello, world!"); diff --git a/tests/data/simple-package/src/other_mod.rs b/tests/data/simple-package/src/other_mod.rs new file mode 100644 index 0000000..f4ad3bf --- /dev/null +++ b/tests/data/simple-package/src/other_mod.rs @@ -0,0 +1 @@ +mod foo; diff --git a/tests/data/simple-package/src/other_mod/foo.rs b/tests/data/simple-package/src/other_mod/foo.rs new file mode 100644 index 0000000..c1e9866 --- /dev/null +++ b/tests/data/simple-package/src/other_mod/foo.rs @@ -0,0 +1,7 @@ +#[cfg(test)] +mod tests { + #[test] + fn math() { + assert_eq!(1 + 1, 2); + } +} diff --git a/tests/init_spec.lua b/tests/init_spec.lua index 6e63051..e1c8c42 100644 --- a/tests/init_spec.lua +++ b/tests/init_spec.lua @@ -26,7 +26,7 @@ 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", }, { @@ -34,7 +34,7 @@ describe("discover_positions", function() 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", }, { @@ -42,7 +42,7 @@ describe("discover_positions", function() 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", }, }, @@ -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", }, }, @@ -60,7 +60,7 @@ 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", }, { @@ -68,7 +68,7 @@ describe("discover_positions", function() 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", }, }, @@ -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", @@ -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",