Skip to content
This repository has been archived by the owner on Dec 18, 2024. It is now read-only.

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

Closed
Phoenix500526 opened this issue May 31, 2023 · 6 comments
Closed

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

Phoenix500526 opened this issue May 31, 2023 · 6 comments

Comments

@Phoenix500526
Copy link

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
Copy link
Owner

taiki-e commented Jun 1, 2023

As said in taiki-e/cargo-llvm-cov#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
Copy link
Owner

taiki-e commented Jun 1, 2024

This problem may have been resolved by tokio-macros 2.3.0, which includes tokio-rs/tokio#6497.

@gmli
Copy link

gmli commented Oct 9, 2024

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.

@bitcapybara
Copy link

bitcapybara commented Dec 2, 2024

any update?

@taiki-e
Copy link
Owner

taiki-e commented Dec 4, 2024

No update on this issue, but the #[coverage] attribute itself has been improved and I believe most of the use cases for this crate will be replaced by it: taiki-e/cargo-llvm-cov#123 (comment)

@taiki-e
Copy link
Owner

taiki-e commented Dec 18, 2024

#[coverage(off)] attribute has been stabilized in rust-lang/rust#130766 (will be included in Rust 1.85).

I will deprecate coverage-helper in favor of the pattern that is now documented in cargo-llvm-cov: taiki-e/cargo-llvm-cov#123 (comment)

If you want to ignore all #[test]-related code, you can use module-level #[coverage(off)] attribute:

#[cfg(test)]
#[cfg_attr(coverage, coverage(off))]
mod tests {
    // ...
}

cargo-llvm-cov excludes code contained in the directory named tests from the report by default, so you can also use it instead of #[coverage(off)] attribute.

@taiki-e taiki-e closed this as not planned Won't fix, can't repro, duplicate, stale Dec 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants