taiki-e / coverage-helper

Helper for https://github.com/taiki-e/cargo-llvm-cov/issues/123.
Apache License 2.0
10 stars 1 forks source link

The coverage-helper::test doesn't work with tokio::test #2

Open Phoenix500526 opened 1 year ago

Phoenix500526 commented 1 year ago

Hi, @taiki-e.

Currently, the implementation of coverage_helper replaces std::test with coverage_helper::test. However, this approach doesn't work for tokio::test. Given that tokio::test is widely used, shall we support tokio::test in this crate?

IMO, we can provide a tokio module in coverage_helper, like:

mod test{
    use coverage_helper::{tokio, test};
    #[test]
    fn test_foo() {...}

    #[tokio::test]
    async fn test_bar() {...}
}

What do you think? If this approach is feasible, I can do some contributions.

taiki-e commented 1 year ago

As said in https://github.com/taiki-e/cargo-llvm-cov/issues/273, tokio::test refers ::core::prelude::v1::test, so it's not working with coverage_helper.

The most desirable fix is to change libtest so that the test attribute gets no_coverage, and the second most desirable is to make the change on the tokio side.

taiki-e commented 4 months ago

This problem may have been resolved by tokio-macros 2.3.0, which includes https://github.com/tokio-rs/tokio/pull/6497.

gmli commented 2 weeks ago

And so, what are we supposed to write in the tests using #[tokio::test] ?

EDIT : ok I understand, the version 2.3.0 of tokio-macros may have solved it without any change. I’ve updated to tokio 1.40.0 and the problem remains.