fork/rust
git clone https://git.julia.blue/fork/rust
3bcad65fbf6
master
1 LL| |#![allow(unused_assignments)] 2 LL| |// failure-status: 101 3 LL| | 4 LL| 4|fn might_fail_assert(one_plus_one: u32) { 5 LL| 4| println!("does 1 + 1 = {}?", one_plus_one); 6 LL| 4| assert_eq!(1 + 1, one_plus_one, "the argument was wrong"); 7 ^1 8 LL| 3|} 9 LL| | 10 LL| 1|fn main() -> Result<(), u8> { 11 LL| 1| let mut countdown = 10; 12 LL| 11| while countdown > 0 { 13 LL| 11| if countdown == 1 { 14 LL| 1| might_fail_assert(3); 15 LL| 10| } else if countdown < 5 { 16 LL| 3| might_fail_assert(2); 17 LL| 6| } 18 LL| 10| countdown -= 1; 19 LL| | } 20 LL| 0| Ok(()) 21 LL| 0|} 22 LL| | 23 LL| |// Notes: 24 LL| |// 1. Compare this program and its coverage results to those of the very similar test 25 LL| |// `panic_unwind.rs`, and similar tests `abort.rs` and `try_error_result.rs`. 26 LL| |// 2. This test confirms the coverage generated when a program passes or fails an `assert!()` or 27 LL| |// related `assert_*!()` macro. 28 LL| |// 3. Notably, the `assert` macros *do not* generate `TerminatorKind::Assert`. The macros produce 29 LL| |// conditional expressions, `TerminatorKind::SwitchInt` branches, and a possible call to 30 LL| |// `begin_panic_fmt()` (that begins a panic unwind, if the assertion test fails). 31 LL| |// 4. `TerminatoKind::Assert` is, however, also present in the MIR generated for this test 32 LL| |// (and in many other coverage tests). The `Assert` terminator is typically generated by the 33 LL| |// Rust compiler to check for runtime failures, such as numeric overflows. 34