vim-test / vim-test

Run your tests at the speed of thought

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

SqAtx opened this issue · comments

commented

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!