Skip to content

Commit eb60a60

Browse files
coverage: Add test to codify existing behavior
Currently `await` is only counted towards coverage if the containing function is suspended and resumed at least once. A future commit will fix this and update the test to reflect the new behavior.
1 parent 9c01301 commit eb60a60

File tree

3 files changed

+54
-2
lines changed

3 files changed

+54
-2
lines changed

tests/coverage/async.cov-map

+36-2
Original file line numberDiff line numberDiff line change
@@ -262,10 +262,44 @@ Number of file 0 mappings: 1
262262
- Code(Zero) at (prev + 87, 25) to (start + 0, 34)
263263

264264
Function name: async::main
265-
Raw bytes (9): 0x[01, 01, 00, 01, 01, 59, 01, 08, 02]
265+
Raw bytes (9): 0x[01, 01, 00, 01, 01, 61, 01, 09, 02]
266266
Number of files: 1
267267
- file 0 => global file 1
268268
Number of expressions: 0
269269
Number of file 0 mappings: 1
270-
- Code(Counter(0)) at (prev + 89, 1) to (start + 8, 2)
270+
- Code(Counter(0)) at (prev + 97, 1) to (start + 9, 2)
271+
272+
Function name: async::n
273+
Raw bytes (9): 0x[01, 01, 00, 01, 01, 59, 01, 00, 14]
274+
Number of files: 1
275+
- file 0 => global file 1
276+
Number of expressions: 0
277+
Number of file 0 mappings: 1
278+
- Code(Counter(0)) at (prev + 89, 1) to (start + 0, 20)
279+
280+
Function name: async::n::{closure#0}
281+
Raw bytes (9): 0x[01, 01, 00, 01, 01, 59, 14, 00, 19]
282+
Number of files: 1
283+
- file 0 => global file 1
284+
Number of expressions: 0
285+
Number of file 0 mappings: 1
286+
- Code(Counter(0)) at (prev + 89, 20) to (start + 0, 25)
287+
288+
Function name: async::o
289+
Raw bytes (9): 0x[01, 01, 00, 01, 01, 5b, 01, 00, 14]
290+
Number of files: 1
291+
- file 0 => global file 1
292+
Number of expressions: 0
293+
Number of file 0 mappings: 1
294+
- Code(Counter(0)) at (prev + 91, 1) to (start + 0, 20)
295+
296+
Function name: async::o::{closure#0}
297+
Raw bytes (19): 0x[01, 01, 00, 03, 01, 5b, 14, 02, 08, 05, 03, 0a, 00, 0f, 09, 01, 01, 00, 02]
298+
Number of files: 1
299+
- file 0 => global file 1
300+
Number of expressions: 0
301+
Number of file 0 mappings: 3
302+
- Code(Counter(0)) at (prev + 91, 20) to (start + 2, 8)
303+
- Code(Counter(1)) at (prev + 3, 10) to (start + 0, 15)
304+
- Code(Counter(2)) at (prev + 1, 1) to (start + 0, 2)
271305

tests/coverage/async.coverage

+9
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,14 @@
9191
LL| 1|async fn m(x: u8) -> u8 { x - 1 }
9292
^0
9393
LL| |
94+
LL| 1|async fn n() -> u8 { 1 }
95+
LL| |
96+
LL| 1|async fn o() -> u8 {
97+
LL| 1| // FIXME(#98712): await is only covered if the function yields
98+
LL| 1| n()
99+
LL| 0| .await
100+
LL| 1|}
101+
LL| |
94102
LL| 1|fn main() {
95103
LL| 1| let _ = g(10);
96104
LL| 1| let _ = h(9);
@@ -99,6 +107,7 @@
99107
LL| 1| l(6);
100108
LL| 1| let _ = m(5);
101109
LL| 1| executor::block_on(future.as_mut());
110+
LL| 1| executor::block_on(Box::pin(o()).as_mut());
102111
LL| 1|}
103112
LL| |
104113
LL| |mod executor {

tests/coverage/async.rs

+9
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,14 @@ fn l(x: u8) {
8686

8787
async fn m(x: u8) -> u8 { x - 1 }
8888

89+
async fn n() -> u8 { 1 }
90+
91+
async fn o() -> u8 {
92+
// FIXME(#98712): await is only covered if the function yields
93+
n()
94+
.await
95+
}
96+
8997
fn main() {
9098
let _ = g(10);
9199
let _ = h(9);
@@ -94,6 +102,7 @@ fn main() {
94102
l(6);
95103
let _ = m(5);
96104
executor::block_on(future.as_mut());
105+
executor::block_on(Box::pin(o()).as_mut());
97106
}
98107

99108
mod executor {

0 commit comments

Comments
 (0)