summaryrefslogtreecommitdiffstats
path: root/tests/run-coverage/assert.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:57:31 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:57:31 +0000
commitdc0db358abe19481e475e10c32149b53370f1a1c (patch)
treeab8ce99c4b255ce46f99ef402c27916055b899ee /tests/run-coverage/assert.rs
parentReleasing progress-linux version 1.71.1+dfsg1-2~progress7.99u1. (diff)
downloadrustc-dc0db358abe19481e475e10c32149b53370f1a1c.tar.xz
rustc-dc0db358abe19481e475e10c32149b53370f1a1c.zip
Merging upstream version 1.72.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/run-coverage/assert.rs')
-rw-r--r--tests/run-coverage/assert.rs32
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/run-coverage/assert.rs b/tests/run-coverage/assert.rs
new file mode 100644
index 000000000..d32a37e07
--- /dev/null
+++ b/tests/run-coverage/assert.rs
@@ -0,0 +1,32 @@
+#![allow(unused_assignments)]
+// failure-status: 101
+
+fn might_fail_assert(one_plus_one: u32) {
+ println!("does 1 + 1 = {}?", one_plus_one);
+ assert_eq!(1 + 1, one_plus_one, "the argument was wrong");
+}
+
+fn main() -> Result<(),u8> {
+ let mut countdown = 10;
+ while countdown > 0 {
+ if countdown == 1 {
+ might_fail_assert(3);
+ } else if countdown < 5 {
+ might_fail_assert(2);
+ }
+ countdown -= 1;
+ }
+ Ok(())
+}
+
+// Notes:
+// 1. Compare this program and its coverage results to those of the very similar test
+// `panic_unwind.rs`, and similar tests `abort.rs` and `try_error_result.rs`.
+// 2. This test confirms the coverage generated when a program passes or fails an `assert!()` or
+// related `assert_*!()` macro.
+// 3. Notably, the `assert` macros *do not* generate `TerminatorKind::Assert`. The macros produce
+// conditional expressions, `TerminatorKind::SwitchInt` branches, and a possible call to
+// `begin_panic_fmt()` (that begins a panic unwind, if the assertion test fails).
+// 4. `TerminatoKind::Assert` is, however, also present in the MIR generated for this test
+// (and in many other coverage tests). The `Assert` terminator is typically generated by the
+// Rust compiler to check for runtime failures, such as numeric overflows.