Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

:TestFile uses wrong search string for test files inside separate folder of Cargo project #759

Open
SqAtx opened this issue Sep 5, 2023 · 0 comments

Comments

@SqAtx
Copy link

SqAtx commented Sep 5, 2023

Given the following cargo project (also available at https://git.sr.ht/~keving/vim-test-repro/tree):

// src/main.rs
fn main() {
    println!("Hello, world!");
}

fn plus_one(n: i32) -> i32 {
    n + 1
}

#[cfg(test)]
#[path = "./tests/main_test.rs"]
mod main_test;
// src/tests/main_test.rs
use crate::plus_one;

#[test]
fn two_plus_one() {
    assert_eq!(plus_one(2), 3);
}
// src/tests/mod.rs
pub mod main_test

If I run :TestFile anywhere inside main_test.rs, it runs cargo test 'tests::main_test::, with the following result:

    Finished test [unoptimized + debuginfo] target(s) in 0.00s
     Running unittests src/main.rs (target/debug/deps/vim_test_repro-21ec13702a047125)

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 1 filtered out; finished in 0.00s

For comparison, this is the output of cargo test:

$ cargo test
    Finished test [unoptimized + debuginfo] target(s) in 0.00s
     Running unittests src/main.rs (target/debug/deps/vim_test_repro-21ec13702a047125)

running 1 test
test main_test::two_plus_one ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

:TestFile prepends an unnecessary tests::, so cargo test doesn't find the test.

I think #535 is the same problem, but it doesn't mention :TestFile specifically.
#708 is about :TestNearest in the same situation.

I'm trying to fix it, but I thought I'd document the exact problem!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant