Skip to content

Commit

Permalink
Construction mod path fails for names with _
Browse files Browse the repository at this point in the history
  • Loading branch information
jsiefer committed Feb 28, 2024
1 parent e7e1142 commit aa4f08e
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 6 deletions.
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 aa4f08e

Please sign in to comment.