fork/rust
git clone https://git.julia.blue/fork/rust
3bcad65fbf6
master
1 LL| |// Enables `coverage(off)` on the entire crate 2 LL| |#![feature(coverage_attribute)] 3 LL| | 4 LL| |#[coverage(off)] 5 LL| |fn do_not_add_coverage_1() { 6 LL| | println!("called but not covered"); 7 LL| |} 8 LL| | 9 LL| |fn do_not_add_coverage_2() { 10 LL| | #![coverage(off)] 11 LL| | println!("called but not covered"); 12 LL| |} 13 LL| | 14 LL| |#[coverage(off)] 15 LL| |#[allow(dead_code)] 16 LL| |fn do_not_add_coverage_not_called() { 17 LL| | println!("not called and not covered"); 18 LL| |} 19 LL| | 20 LL| 1|fn add_coverage_1() { 21 LL| 1| println!("called and covered"); 22 LL| 1|} 23 LL| | 24 LL| 1|fn add_coverage_2() { 25 LL| 1| println!("called and covered"); 26 LL| 1|} 27 LL| | 28 LL| |#[allow(dead_code)] 29 LL| 0|fn add_coverage_not_called() { 30 LL| 0| println!("not called but covered"); 31 LL| 0|} 32 LL| | 33 LL| |// FIXME: These test-cases illustrate confusing results of nested functions. 34 LL| |// See https://github.com/rust-lang/rust/issues/93319 35 LL| |mod nested_fns { 36 LL| | #[coverage(off)] 37 LL| | pub fn outer_not_covered(is_true: bool) { 38 LL| 1| fn inner(is_true: bool) { 39 LL| 1| if is_true { 40 LL| 1| println!("called and covered"); 41 LL| 1| } else { 42 LL| 0| println!("absolutely not covered"); 43 LL| 0| } 44 LL| 1| } 45 LL| | println!("called but not covered"); 46 LL| | inner(is_true); 47 LL| | } 48 LL| | 49 LL| 1| pub fn outer(is_true: bool) { 50 LL| 1| println!("called and covered"); 51 LL| 1| inner_not_covered(is_true); 52 LL| 1| 53 LL| 1| #[coverage(off)] 54 LL| 1| fn inner_not_covered(is_true: bool) { 55 LL| 1| if is_true { 56 LL| 1| println!("called but not covered"); 57 LL| 1| } else { 58 LL| 1| println!("absolutely not covered"); 59 LL| 1| } 60 LL| 1| } 61 LL| 1| } 62 LL| | 63 LL| 1| pub fn outer_both_covered(is_true: bool) { 64 LL| 1| println!("called and covered"); 65 LL| 1| inner(is_true); 66 LL| 1| 67 LL| 1| fn inner(is_true: bool) { 68 LL| 1| if is_true { 69 LL| 1| println!("called and covered"); 70 LL| 1| } else { 71 LL| 0| println!("absolutely not covered"); 72 LL| 0| } 73 LL| 1| } 74 LL| 1| } 75 LL| |} 76 LL| | 77 LL| 1|fn main() { 78 LL| 1| let is_true = std::env::args().len() == 1; 79 LL| 1| 80 LL| 1| do_not_add_coverage_1(); 81 LL| 1| do_not_add_coverage_2(); 82 LL| 1| add_coverage_1(); 83 LL| 1| add_coverage_2(); 84 LL| 1| 85 LL| 1| nested_fns::outer_not_covered(is_true); 86 LL| 1| nested_fns::outer(is_true); 87 LL| 1| nested_fns::outer_both_covered(is_true); 88 LL| 1|} 89