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