summary refs log tree commit diff
path: root/tests/coverage/auto-derived.auto.coverage
blob: 242abbf803183b2072c0c04d5350b335205eaf9c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
   LL|       |#![feature(coverage_attribute)]
   LL|       |//@ edition: 2024
   LL|       |//@ revisions: base auto on
   LL|       |
   LL|       |// Tests for how `#[automatically_derived]` affects coverage instrumentation.
   LL|       |//
   LL|       |// The actual behaviour is an implementation detail, so this test mostly exists
   LL|       |// to show when that behaviour has been accidentally or deliberately changed.
   LL|       |//
   LL|       |// Revision guide:
   LL|       |// - base: Test baseline instrumentation behaviour without `#[automatically_derived]`
   LL|       |// - auto: Test how `#[automatically_derived]` affects instrumentation
   LL|       |// - on:   Test interaction between auto-derived and `#[coverage(on)]`
   LL|       |
   LL|       |struct MyStruct;
   LL|       |
   LL|       |trait MyTrait {
   LL|       |    fn my_assoc_fn();
   LL|       |}
   LL|       |
   LL|       |#[cfg_attr(auto, automatically_derived)]
   LL|       |#[cfg_attr(on, automatically_derived)]
   LL|       |#[cfg_attr(on, coverage(on))]
   LL|       |impl MyTrait for MyStruct {
   LL|       |    fn my_assoc_fn() {
   LL|       |        fn inner_fn() {
   LL|       |            say("in inner fn");
   LL|       |        }
   LL|       |
   LL|       |        #[coverage(on)]
   LL|      1|        fn inner_fn_on() {
   LL|      1|            say("in inner fn (on)");
   LL|      1|        }
   LL|       |
   LL|       |        let closure = || {
   LL|       |            say("in closure");
   LL|       |        };
   LL|       |
   LL|       |        closure();
   LL|       |        inner_fn();
   LL|       |        inner_fn_on();
   LL|       |    }
   LL|       |}
   LL|       |
   LL|       |#[coverage(off)]
   LL|       |#[inline(never)]
   LL|       |fn say(s: &str) {
   LL|       |    println!("{s}");
   LL|       |}
   LL|       |
   LL|      1|fn main() {
   LL|      1|    MyStruct::my_assoc_fn();
   LL|      1|}