about summary refs log tree commit diff
path: root/tests/coverage/coverage_attr_closure.coverage
diff options
context:
space:
mode:
authorZalathar <Zalathar@users.noreply.github.com>2024-01-20 18:23:49 +1100
committerZalathar <Zalathar@users.noreply.github.com>2024-02-05 10:07:19 +1100
commit8dd2b37462a2017207d4ecb01d3123881d8ec2f2 (patch)
tree21613594a540920a1a2a1666a9cf2918ecd8513c /tests/coverage/coverage_attr_closure.coverage
parentfe420dc46ecf988eb13c34526feea18fd8daef6b (diff)
downloadrust-8dd2b37462a2017207d4ecb01d3123881d8ec2f2.tar.gz
rust-8dd2b37462a2017207d4ecb01d3123881d8ec2f2.zip
coverage: Add a test for `#[coverage(..)]` on closures
Diffstat (limited to 'tests/coverage/coverage_attr_closure.coverage')
-rw-r--r--tests/coverage/coverage_attr_closure.coverage43
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/coverage/coverage_attr_closure.coverage b/tests/coverage/coverage_attr_closure.coverage
new file mode 100644
index 00000000000..32c75b40d83
--- /dev/null
+++ b/tests/coverage/coverage_attr_closure.coverage
@@ -0,0 +1,43 @@
+   LL|       |#![feature(coverage_attribute, stmt_expr_attributes)]
+   LL|       |#![allow(dead_code)]
+   LL|       |// edition: 2021
+   LL|       |
+   LL|       |static GLOBAL_CLOSURE_ON: fn(&str) = #[coverage(on)]
+   LL|      0||input: &str| {
+   LL|      0|    println!("{input}");
+   LL|      0|};
+   LL|       |static GLOBAL_CLOSURE_OFF: fn(&str) = #[coverage(off)]
+   LL|       ||input: &str| {
+   LL|       |    println!("{input}");
+   LL|       |};
+   LL|       |
+   LL|       |#[coverage(on)]
+   LL|      1|fn contains_closures_on() {
+   LL|      1|    let _local_closure_on = #[coverage(on)]
+   LL|      1|    |input: &str| {
+   LL|      0|        println!("{input}");
+   LL|      1|    };
+   LL|      1|    let _local_closure_off = #[coverage(off)]
+   LL|      1|    |input: &str| {
+   LL|       |        println!("{input}");
+   LL|      1|    };
+   LL|      1|}
+   LL|       |
+   LL|       |#[coverage(off)]
+   LL|       |fn contains_closures_off() {
+   LL|       |    let _local_closure_on = #[coverage(on)]
+   LL|      0|    |input: &str| {
+   LL|      0|        println!("{input}");
+   LL|      0|    };
+   LL|       |    let _local_closure_off = #[coverage(off)]
+   LL|       |    |input: &str| {
+   LL|       |        println!("{input}");
+   LL|       |    };
+   LL|       |}
+   LL|       |
+   LL|       |#[coverage(off)]
+   LL|       |fn main() {
+   LL|       |    contains_closures_on();
+   LL|       |    contains_closures_off();
+   LL|       |}
+