Running test from exactly one module


#1

Hi! I am trying to implement “run the tests at the cursor” functionality in the IntelliJ Rust. One interesting problem I found is that it seems impossible to run the tests from exactly one module. Suppose I have

mod foo {
    #[test] 
    fn test_foo() {}

    mod bar {
        #[test] 
        fn test_bar() {}
    }
}

If I run cargo test foo:: then the tests from bar will also be executed. Is there any way to execute only foo's tests?


#2

cargo test foo::test_ will work if your test functions are all named as test_*. cargo test has no finer way to filter tests, so otherwise you probably need to name all tests manually.


#3

This will be fine, but it seems there is no way to do this? That is, I cant cargo test "foo OR bar"


#4

Yes there is no way. A test executable had once shipped with a regular expression library but that feature has been removed due to the removal of in-tree regex library. The current regex library is, while being maintained alongside with Rust itself, not distributed with Rust right now, so the test runner cannot use it.