2023-08-15 21:42:33 -05:00
|
|
|
LL| |#![allow(unused_assignments)]
|
|
|
|
LL| |// failure-status: 101
|
|
|
|
LL| |
|
|
|
|
LL| 4|fn might_fail_assert(one_plus_one: u32) {
|
|
|
|
LL| 4| println!("does 1 + 1 = {}?", one_plus_one);
|
|
|
|
LL| 4| assert_eq!(1 + 1, one_plus_one, "the argument was wrong");
|
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
|
|
|
^1
|
2023-08-15 21:42:33 -05:00
|
|
|
LL| 3|}
|
|
|
|
LL| |
|
2023-08-16 20:43:10 -05:00
|
|
|
LL| 1|fn main() -> Result<(), u8> {
|
2023-08-15 21:42:33 -05:00
|
|
|
LL| 1| let mut countdown = 10;
|
|
|
|
LL| 11| while countdown > 0 {
|
|
|
|
LL| 11| if countdown == 1 {
|
|
|
|
LL| 1| might_fail_assert(3);
|
|
|
|
LL| 10| } else if countdown < 5 {
|
|
|
|
LL| 3| might_fail_assert(2);
|
|
|
|
LL| 6| }
|
|
|
|
LL| 10| countdown -= 1;
|
|
|
|
LL| | }
|
|
|
|
LL| 0| Ok(())
|
|
|
|
LL| 0|}
|
|
|
|
LL| |
|
|
|
|
LL| |// Notes:
|
|
|
|
LL| |// 1. Compare this program and its coverage results to those of the very similar test
|
|
|
|
LL| |// `panic_unwind.rs`, and similar tests `abort.rs` and `try_error_result.rs`.
|
|
|
|
LL| |// 2. This test confirms the coverage generated when a program passes or fails an `assert!()` or
|
|
|
|
LL| |// related `assert_*!()` macro.
|
|
|
|
LL| |// 3. Notably, the `assert` macros *do not* generate `TerminatorKind::Assert`. The macros produce
|
|
|
|
LL| |// conditional expressions, `TerminatorKind::SwitchInt` branches, and a possible call to
|
|
|
|
LL| |// `begin_panic_fmt()` (that begins a panic unwind, if the assertion test fails).
|
|
|
|
LL| |// 4. `TerminatoKind::Assert` is, however, also present in the MIR generated for this test
|
|
|
|
LL| |// (and in many other coverage tests). The `Assert` terminator is typically generated by the
|
|
|
|
LL| |// Rust compiler to check for runtime failures, such as numeric overflows.
|
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
|
|
|
|