Coverage tests for remaining TerminatorKinds and async, improve Assert
Tested and validate results for panic unwind, panic abort, assert!()
macro, TerminatorKind::Assert (for example, numeric overflow), and
async/await.
Implemented a previous documented idea to change Assert handling to be
the same as FalseUnwind and Goto, so it doesn't get its own
BasicCoverageBlock anymore. This changed a couple of coverage regions,
but I validated those changes are not any worse than the prior results,
and probably help assure some consistency (even if some people might
disagree with how the code region is consistently computed).
Fixed issue with async/await. AggregateKind::Generator needs to be
handled like AggregateKind::Closure; coverage span for the outer async
function should not "cover" the async body, which is actually executed
in a separate "closure" MIR.
2020-11-16 11:14:28 -06:00
|
|
|
#![allow(unused_assignments)]
|
|
|
|
// expect-exit-status-101
|
|
|
|
|
|
|
|
fn might_panic(should_panic: bool) {
|
|
|
|
if should_panic {
|
|
|
|
println!("panicking...");
|
|
|
|
panic!("panics");
|
|
|
|
} else {
|
|
|
|
println!("Don't Panic");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-01 01:58:08 -06:00
|
|
|
fn main() -> Result<(), u8> {
|
Coverage tests for remaining TerminatorKinds and async, improve Assert
Tested and validate results for panic unwind, panic abort, assert!()
macro, TerminatorKind::Assert (for example, numeric overflow), and
async/await.
Implemented a previous documented idea to change Assert handling to be
the same as FalseUnwind and Goto, so it doesn't get its own
BasicCoverageBlock anymore. This changed a couple of coverage regions,
but I validated those changes are not any worse than the prior results,
and probably help assure some consistency (even if some people might
disagree with how the code region is consistently computed).
Fixed issue with async/await. AggregateKind::Generator needs to be
handled like AggregateKind::Closure; coverage span for the outer async
function should not "cover" the async body, which is actually executed
in a separate "closure" MIR.
2020-11-16 11:14:28 -06:00
|
|
|
let mut countdown = 10;
|
|
|
|
while countdown > 0 {
|
|
|
|
if countdown == 1 {
|
|
|
|
might_panic(true);
|
|
|
|
} else if countdown < 5 {
|
|
|
|
might_panic(false);
|
|
|
|
}
|
|
|
|
countdown -= 1;
|
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
// Notes:
|
|
|
|
// 1. Compare this program and its coverage results to those of the similar tests `abort.rs` and
|
|
|
|
// `try_error_result.rs`.
|
|
|
|
// 2. Since the `panic_unwind.rs` test is allowed to unwind, it is also allowed to execute the
|
|
|
|
// normal program exit cleanup, including writing out the current values of the coverage
|
|
|
|
// counters.
|