rust/tests/run-make/coverage-reports/expected_show_coverage.closure_macro_async.txt

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

84 lines
3.3 KiB
Plaintext
Raw Normal View History

1| |// compile-flags: --edition=2018
2| |#![feature(no_coverage)]
3| |
4| |macro_rules! bail {
5| | ($msg:literal $(,)?) => {
6| | if $msg.len() > 0 {
7| | println!("no msg");
8| | } else {
9| | println!($msg);
10| | }
11| | return Err(String::from($msg));
12| | };
13| |}
14| |
15| |macro_rules! on_error {
16| | ($value:expr, $error_message:expr) => {
Coverage instruments closure bodies in macros (not the macro body) Fixes: #84884 This solution might be considered a compromise, but I think it is the better choice. The results in the `closure.rs` test correctly resolve all test cases broken as described in #84884. One test pattern (in both `closure_macro.rs` and `closure_macro_async.rs`) was also affected, and removes coverage statistics for the lines inside the closure, because the closure includes a macro. (The coverage remains at the callsite of the macro, so we lose some detail, but there isn't a perfect choice with macros. Often macro implementations are split across the macro and the callsite, and there doesn't appear to be a single "right choice" for which body should be covered. For the current implementation, we can't do both. The callsite is most likely to be the preferred site for coverage. I applied this fix to all `MacroKinds`, not just `Bang`. I'm trying to resolve an issue of lost coverage in a `MacroKind::Attr`-based, function-scoped macro. Instead of only searching for a body_span that is "not a function-like macro" (that is, MacroKind::Bang), I'm expanding this to all `MacroKind`s. Maybe I should expand this to `ExpnKind::Desugaring` and `ExpnKind::AstPass` (or subsets, depending on their sub-kinds) as well, but I'm not sure that's a good idea. I'd like to add a test of the `Attr` macro on functions, but I need time to figure out how to constract a good, simple example without external crate dependencies. For the moment, all tests still work as expected (no change), this new commit shouldn't have a negative affect, and more importantly, I believe it will have a positive effect. I will try to confirm this.
2021-05-04 01:21:24 -05:00
17| | $value.or_else(|e| { // FIXME(85000): no coverage in closure macros
18| | let message = format!($error_message, e);
19| | if message.len() > 0 {
20| | println!("{}", message);
21| | Ok(String::from("ok"))
22| | } else {
Coverage instruments closure bodies in macros (not the macro body) Fixes: #84884 This solution might be considered a compromise, but I think it is the better choice. The results in the `closure.rs` test correctly resolve all test cases broken as described in #84884. One test pattern (in both `closure_macro.rs` and `closure_macro_async.rs`) was also affected, and removes coverage statistics for the lines inside the closure, because the closure includes a macro. (The coverage remains at the callsite of the macro, so we lose some detail, but there isn't a perfect choice with macros. Often macro implementations are split across the macro and the callsite, and there doesn't appear to be a single "right choice" for which body should be covered. For the current implementation, we can't do both. The callsite is most likely to be the preferred site for coverage. I applied this fix to all `MacroKinds`, not just `Bang`. I'm trying to resolve an issue of lost coverage in a `MacroKind::Attr`-based, function-scoped macro. Instead of only searching for a body_span that is "not a function-like macro" (that is, MacroKind::Bang), I'm expanding this to all `MacroKind`s. Maybe I should expand this to `ExpnKind::Desugaring` and `ExpnKind::AstPass` (or subsets, depending on their sub-kinds) as well, but I'm not sure that's a good idea. I'd like to add a test of the `Attr` macro on functions, but I need time to figure out how to constract a good, simple example without external crate dependencies. For the moment, all tests still work as expected (no change), this new commit shouldn't have a negative affect, and more importantly, I believe it will have a positive effect. I will try to confirm this.
2021-05-04 01:21:24 -05:00
23| | bail!("error");
24| | }
Coverage instruments closure bodies in macros (not the macro body) Fixes: #84884 This solution might be considered a compromise, but I think it is the better choice. The results in the `closure.rs` test correctly resolve all test cases broken as described in #84884. One test pattern (in both `closure_macro.rs` and `closure_macro_async.rs`) was also affected, and removes coverage statistics for the lines inside the closure, because the closure includes a macro. (The coverage remains at the callsite of the macro, so we lose some detail, but there isn't a perfect choice with macros. Often macro implementations are split across the macro and the callsite, and there doesn't appear to be a single "right choice" for which body should be covered. For the current implementation, we can't do both. The callsite is most likely to be the preferred site for coverage. I applied this fix to all `MacroKinds`, not just `Bang`. I'm trying to resolve an issue of lost coverage in a `MacroKind::Attr`-based, function-scoped macro. Instead of only searching for a body_span that is "not a function-like macro" (that is, MacroKind::Bang), I'm expanding this to all `MacroKind`s. Maybe I should expand this to `ExpnKind::Desugaring` and `ExpnKind::AstPass` (or subsets, depending on their sub-kinds) as well, but I'm not sure that's a good idea. I'd like to add a test of the `Attr` macro on functions, but I need time to figure out how to constract a good, simple example without external crate dependencies. For the moment, all tests still work as expected (no change), this new commit shouldn't have a negative affect, and more importantly, I believe it will have a positive effect. I will try to confirm this.
2021-05-04 01:21:24 -05:00
25| | })
26| | };
27| |}
28| |
29| 1|fn load_configuration_files() -> Result<String, String> {
30| 1| Ok(String::from("config"))
31| 1|}
32| |
33| 1|pub async fn test() -> Result<(), String> {
34| 1| println!("Starting service");
35| 1| let config = on_error!(load_configuration_files(), "Error loading configs: {}")?;
^0
36| |
37| 1| let startup_delay_duration = String::from("arg");
38| 1| let _ = (config, startup_delay_duration);
39| 1| Ok(())
40| 1|}
41| |
42| |#[no_coverage]
43| |fn main() {
44| | executor::block_on(test());
45| |}
46| |
47| |mod executor {
48| | use core::{
49| | future::Future,
50| | pin::Pin,
51| | task::{Context, Poll, RawWaker, RawWakerVTable, Waker},
52| | };
53| |
54| | #[no_coverage]
55| | pub fn block_on<F: Future>(mut future: F) -> F::Output {
56| | let mut future = unsafe { Pin::new_unchecked(&mut future) };
57| | use std::hint::unreachable_unchecked;
58| | static VTABLE: RawWakerVTable = RawWakerVTable::new(
59| |
60| | #[no_coverage]
61| | |_| unsafe { unreachable_unchecked() }, // clone
62| |
63| | #[no_coverage]
64| | |_| unsafe { unreachable_unchecked() }, // wake
65| |
66| | #[no_coverage]
67| | |_| unsafe { unreachable_unchecked() }, // wake_by_ref
68| |
69| | #[no_coverage]
70| | |_| (),
71| | );
72| | let waker = unsafe { Waker::from_raw(RawWaker::new(core::ptr::null(), &VTABLE)) };
73| | let mut context = Context::from_waker(&waker);
74| |
75| | loop {
76| | if let Poll::Ready(val) = future.as_mut().poll(&mut context) {
77| | break val;
78| | }
79| | }
80| | }
81| |}