blob: f1adb235f74a3718f07b2bf8b149738201ab1f36 [file] [log] [blame] [edit]
LL| |#![feature(coverage_attribute)]
LL| |//@ edition: 2024
LL| |
LL| |// Test that when a macro expands to another macro, without any significant
LL| |// spans of its own, that this doesn't cause coverage instrumentation to give
LL| |// up and ignore the inner spans.
LL| |
LL| |macro_rules! inner_macro {
LL| | () => {
LL| | if core::hint::black_box(true) {
LL| | say("true");
LL| | } else {
LL| | say("false");
LL| | }
LL| | };
LL| |}
LL| |
LL| |macro_rules! middle_macro {
LL| | () => {
LL| | inner_macro!()
LL| | };
LL| |}
LL| |
LL| |macro_rules! outer_macro {
LL| | () => {
LL| | middle_macro!()
LL| | };
LL| |}
LL| |
LL| |// In each of these three functions, the macro call should be instrumented,
LL| |// and should have an execution count of 1.
LL| |//
LL| |// Each function contains some extra code to ensure that control flow is
LL| |// non-trivial.
LL| |
LL| 1|fn uses_inner_macro() {
LL| 1| if core::hint::black_box(true) {
LL| 1| say("before inner_macro");
LL| 1| inner_macro!();
LL| 1| say("after inner_macro");
LL| 0| }
LL| 1|}
LL| |
LL| 1|fn uses_middle_macro() {
LL| 1| if core::hint::black_box(true) {
LL| 1| say("before middle_macro");
LL| 1| middle_macro!();
LL| 1| say("after middle_macro")
LL| 0| }
LL| 1|}
LL| |
LL| 1|fn uses_outer_macro() {
LL| 1| if core::hint::black_box(true) {
LL| 1| say("before outer_macro");
LL| 1| outer_macro!();
LL| 1| say("after outer_macro");
LL| 0| }
LL| 1|}
LL| |
LL| |#[coverage(off)]
LL| |fn main() {
LL| | uses_inner_macro();
LL| | uses_middle_macro();
LL| | uses_outer_macro();
LL| |}
LL| |
LL| |#[coverage(off)]
LL| |fn say(message: &str) {
LL| | println!("{message}");
LL| |}