Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 65 additions & 35 deletions tests/coverage/assert.cov-map
Original file line number Diff line number Diff line change
@@ -1,42 +1,72 @@
Function name: assert::main
Raw bytes (76): 0x[01, 01, 06, 05, 01, 05, 17, 01, 09, 05, 13, 17, 0d, 01, 09, 0c, 01, 09, 01, 00, 1c, 01, 01, 09, 00, 16, 01, 00, 19, 00, 1b, 05, 01, 0b, 00, 18, 02, 01, 0c, 00, 1a, 09, 00, 1b, 02, 0a, 06, 02, 13, 00, 20, 0d, 00, 21, 02, 0a, 0e, 02, 09, 00, 0a, 02, 01, 09, 00, 17, 01, 02, 05, 00, 0b, 01, 01, 01, 00, 02]
Function name: assert::assert_a_plain
Raw bytes (54): 0x[01, 01, 00, 0a, 01, 06, 01, 00, 25, 01, 01, 05, 00, 0c, 01, 00, 0d, 00, 10, 01, 00, 11, 00, 18, 05, 01, 05, 00, 0f, 09, 01, 05, 00, 0f, 15, 01, 05, 00, 14, 0d, 00, 15, 00, 18, 11, 00, 1f, 00, 25, 15, 01, 01, 00, 02]
Number of files: 1
- file 0 => $DIR/assert.rs
Number of expressions: 6
- expression 0 operands: lhs = Counter(1), rhs = Counter(0)
- expression 1 operands: lhs = Counter(1), rhs = Expression(5, Add)
- expression 2 operands: lhs = Counter(0), rhs = Counter(2)
- expression 3 operands: lhs = Counter(1), rhs = Expression(4, Add)
- expression 4 operands: lhs = Expression(5, Add), rhs = Counter(3)
- expression 5 operands: lhs = Counter(0), rhs = Counter(2)
Number of file 0 mappings: 12
- Code(Counter(0)) at (prev + 9, 1) to (start + 0, 28)
- Code(Counter(0)) at (prev + 1, 9) to (start + 0, 22)
- Code(Counter(0)) at (prev + 0, 25) to (start + 0, 27)
- Code(Counter(1)) at (prev + 1, 11) to (start + 0, 24)
- Code(Expression(0, Sub)) at (prev + 1, 12) to (start + 0, 26)
= (c1 - c0)
- Code(Counter(2)) at (prev + 0, 27) to (start + 2, 10)
- Code(Expression(1, Sub)) at (prev + 2, 19) to (start + 0, 32)
= (c1 - (c0 + c2))
- Code(Counter(3)) at (prev + 0, 33) to (start + 2, 10)
- Code(Expression(3, Sub)) at (prev + 2, 9) to (start + 0, 10)
= (c1 - ((c0 + c2) + c3))
- Code(Expression(0, Sub)) at (prev + 1, 9) to (start + 0, 23)
= (c1 - c0)
- Code(Counter(0)) at (prev + 2, 5) to (start + 0, 11)
- Code(Counter(0)) at (prev + 1, 1) to (start + 0, 2)
Highest counter ID seen: c3
Number of expressions: 0
Number of file 0 mappings: 10
- Code(Counter(0)) at (prev + 6, 1) to (start + 0, 37)
- Code(Counter(0)) at (prev + 1, 5) to (start + 0, 12)
- Code(Counter(0)) at (prev + 0, 13) to (start + 0, 16)
- Code(Counter(0)) at (prev + 0, 17) to (start + 0, 24)
- Code(Counter(1)) at (prev + 1, 5) to (start + 0, 15)
- Code(Counter(2)) at (prev + 1, 5) to (start + 0, 15)
- Code(Counter(5)) at (prev + 1, 5) to (start + 0, 20)
- Code(Counter(3)) at (prev + 0, 21) to (start + 0, 24)
- Code(Counter(4)) at (prev + 0, 31) to (start + 0, 37)
- Code(Counter(5)) at (prev + 1, 1) to (start + 0, 2)
Highest counter ID seen: c5

Function name: assert::assert_b_message
Raw bytes (54): 0x[01, 01, 00, 0a, 01, 0d, 01, 00, 27, 01, 01, 05, 00, 0c, 01, 00, 0d, 00, 10, 01, 00, 11, 00, 18, 05, 01, 05, 00, 0f, 09, 01, 05, 00, 0f, 15, 01, 05, 00, 14, 0d, 00, 15, 00, 18, 11, 00, 1f, 00, 25, 15, 01, 01, 00, 02]
Number of files: 1
- file 0 => $DIR/assert.rs
Number of expressions: 0
Number of file 0 mappings: 10
- Code(Counter(0)) at (prev + 13, 1) to (start + 0, 39)
- Code(Counter(0)) at (prev + 1, 5) to (start + 0, 12)
- Code(Counter(0)) at (prev + 0, 13) to (start + 0, 16)
- Code(Counter(0)) at (prev + 0, 17) to (start + 0, 24)
- Code(Counter(1)) at (prev + 1, 5) to (start + 0, 15)
- Code(Counter(2)) at (prev + 1, 5) to (start + 0, 15)
- Code(Counter(5)) at (prev + 1, 5) to (start + 0, 20)
- Code(Counter(3)) at (prev + 0, 21) to (start + 0, 24)
- Code(Counter(4)) at (prev + 0, 31) to (start + 0, 37)
- Code(Counter(5)) at (prev + 1, 1) to (start + 0, 2)
Highest counter ID seen: c5

Function name: assert::assert_c_format_inline
Raw bytes (54): 0x[01, 01, 00, 0a, 01, 14, 01, 00, 38, 01, 01, 05, 00, 0c, 01, 00, 0d, 00, 10, 01, 00, 11, 00, 18, 05, 01, 05, 00, 0f, 09, 01, 05, 00, 0f, 15, 01, 05, 00, 14, 0d, 00, 15, 00, 18, 11, 00, 1f, 00, 25, 15, 01, 01, 00, 02]
Number of files: 1
- file 0 => $DIR/assert.rs
Number of expressions: 0
Number of file 0 mappings: 10
- Code(Counter(0)) at (prev + 20, 1) to (start + 0, 56)
- Code(Counter(0)) at (prev + 1, 5) to (start + 0, 12)
- Code(Counter(0)) at (prev + 0, 13) to (start + 0, 16)
- Code(Counter(0)) at (prev + 0, 17) to (start + 0, 24)
- Code(Counter(1)) at (prev + 1, 5) to (start + 0, 15)
- Code(Counter(2)) at (prev + 1, 5) to (start + 0, 15)
- Code(Counter(5)) at (prev + 1, 5) to (start + 0, 20)
- Code(Counter(3)) at (prev + 0, 21) to (start + 0, 24)
- Code(Counter(4)) at (prev + 0, 31) to (start + 0, 37)
- Code(Counter(5)) at (prev + 1, 1) to (start + 0, 2)
Highest counter ID seen: c5

Function name: assert::might_fail_assert
Raw bytes (24): 0x[01, 01, 00, 04, 01, 04, 01, 00, 28, 01, 01, 05, 00, 0d, 01, 01, 05, 00, 0f, 05, 01, 01, 00, 02]
Function name: assert::assert_d_format_arg
Raw bytes (54): 0x[01, 01, 00, 0a, 01, 1b, 01, 00, 35, 01, 01, 05, 00, 0c, 01, 00, 0d, 00, 10, 01, 00, 11, 00, 18, 05, 01, 05, 00, 0f, 09, 01, 05, 00, 0f, 15, 01, 05, 00, 14, 0d, 00, 15, 00, 18, 11, 00, 1f, 00, 25, 15, 01, 01, 00, 02]
Number of files: 1
- file 0 => $DIR/assert.rs
Number of expressions: 0
Number of file 0 mappings: 4
- Code(Counter(0)) at (prev + 4, 1) to (start + 0, 40)
- Code(Counter(0)) at (prev + 1, 5) to (start + 0, 13)
- Code(Counter(0)) at (prev + 1, 5) to (start + 0, 15)
- Code(Counter(1)) at (prev + 1, 1) to (start + 0, 2)
Highest counter ID seen: c1
Number of file 0 mappings: 10
- Code(Counter(0)) at (prev + 27, 1) to (start + 0, 53)
- Code(Counter(0)) at (prev + 1, 5) to (start + 0, 12)
- Code(Counter(0)) at (prev + 0, 13) to (start + 0, 16)
- Code(Counter(0)) at (prev + 0, 17) to (start + 0, 24)
- Code(Counter(1)) at (prev + 1, 5) to (start + 0, 15)
- Code(Counter(2)) at (prev + 1, 5) to (start + 0, 15)
- Code(Counter(5)) at (prev + 1, 5) to (start + 0, 20)
- Code(Counter(3)) at (prev + 0, 21) to (start + 0, 24)
- Code(Counter(4)) at (prev + 0, 31) to (start + 0, 37)
- Code(Counter(5)) at (prev + 1, 1) to (start + 0, 2)
Highest counter ID seen: c5

65 changes: 37 additions & 28 deletions tests/coverage/assert.coverage
Original file line number Diff line number Diff line change
@@ -1,33 +1,42 @@
LL| |#![allow(unused_assignments)]
LL| |//@ failure-status: 101
LL| |#![feature(coverage_attribute)]
LL| |//@ edition: 2024
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");
LL| 3|}
LL| |use core::assert_matches;
LL| |
LL| 1|fn main() -> Result<(), u8> {
LL| 1| let mut countdown = 10;
LL| 10| while countdown > 0 {
LL| 9| if countdown == 1 {
LL| 1| might_fail_assert(3);
LL| 8| } else if countdown < 5 {
LL| 3| might_fail_assert(2);
LL| 5| }
LL| 9| countdown -= 1;
LL| | }
LL| 1| Ok(())
LL| 1|fn assert_a_plain(opt: Option<&str>) {
LL| 1| assert!(opt.is_some());
LL| 1| assert_eq!(opt, Some("true"));
LL| 1| assert_ne!(opt, None);
LL| 1| assert_matches!(opt, Some("true"));
LL| 1|}
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. `TerminatorKind::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.
LL| 1|fn assert_b_message(opt: Option<&str>) {
LL| 1| assert!(opt.is_some(), "message");
LL| 1| assert_eq!(opt, Some("true"), "message");
LL| 1| assert_ne!(opt, None, "message");
LL| 1| assert_matches!(opt, Some("true"), "message");
LL| 1|}
LL| |
LL| 1|fn assert_c_format_inline(opt: Option<&str>, msg: &str) {
LL| 1| assert!(opt.is_some(), "message: {msg}");
LL| 1| assert_eq!(opt, Some("true"), "message: {msg}");
LL| 1| assert_ne!(opt, None, "message: {msg}");
LL| 1| assert_matches!(opt, Some("true"), "message: {msg}");
LL| 1|}
LL| |
LL| 1|fn assert_d_format_arg(opt: Option<&str>, msg: &str) {
LL| 1| assert!(opt.is_some(), "message: {}", msg);
LL| 1| assert_eq!(opt, Some("true"), "message: {}", msg);
LL| 1| assert_ne!(opt, None, "message: {}", msg);
LL| 1| assert_matches!(opt, Some("true"), "message: {}", msg);
LL| 1|}
LL| |
LL| |#[coverage(off)]
LL| |fn main() {
LL| | let opt = core::hint::black_box(Some("true"));
LL| | assert_a_plain(opt);
LL| | assert_b_message(opt);
LL| | assert_c_format_inline(opt, "message");
LL| | assert_d_format_arg(opt, "message");
LL| |}

63 changes: 36 additions & 27 deletions tests/coverage/assert.rs
Original file line number Diff line number Diff line change
@@ -1,32 +1,41 @@
#![allow(unused_assignments)]
//@ failure-status: 101
#![feature(coverage_attribute)]
//@ edition: 2024

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");
use core::assert_matches;

fn assert_a_plain(opt: Option<&str>) {
assert!(opt.is_some());
assert_eq!(opt, Some("true"));
assert_ne!(opt, None);
assert_matches!(opt, Some("true"));
}

fn assert_b_message(opt: Option<&str>) {
assert!(opt.is_some(), "message");
assert_eq!(opt, Some("true"), "message");
assert_ne!(opt, None, "message");
assert_matches!(opt, Some("true"), "message");
}

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(())
fn assert_c_format_inline(opt: Option<&str>, msg: &str) {
assert!(opt.is_some(), "message: {msg}");
assert_eq!(opt, Some("true"), "message: {msg}");
assert_ne!(opt, None, "message: {msg}");
assert_matches!(opt, Some("true"), "message: {msg}");
}

// 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. `TerminatorKind::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.
fn assert_d_format_arg(opt: Option<&str>, msg: &str) {
assert!(opt.is_some(), "message: {}", msg);
assert_eq!(opt, Some("true"), "message: {}", msg);
assert_ne!(opt, None, "message: {}", msg);
assert_matches!(opt, Some("true"), "message: {}", msg);
}

#[coverage(off)]
fn main() {
let opt = core::hint::black_box(Some("true"));
assert_a_plain(opt);
assert_b_message(opt);
assert_c_format_inline(opt, "message");
assert_d_format_arg(opt, "message");
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
19 changes: 19 additions & 0 deletions tests/coverage/call-method.cov-map
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Function name: call_method::call_method
Raw bytes (59): 0x[01, 01, 00, 0b, 01, 08, 01, 00, 11, 01, 01, 09, 00, 0e, 01, 00, 11, 00, 16, 01, 02, 05, 00, 0a, 01, 02, 09, 00, 0f, 01, 02, 0d, 00, 12, 01, 04, 05, 05, 0a, 01, 00, 05, 00, 0a, 01, 07, 09, 00, 0f, 01, 02, 0d, 00, 12, 01, 03, 01, 00, 02]
Number of files: 1
- file 0 => $DIR/call-method.rs
Number of expressions: 0
Number of file 0 mappings: 11
- Code(Counter(0)) at (prev + 8, 1) to (start + 0, 17)
- Code(Counter(0)) at (prev + 1, 9) to (start + 0, 14)
- Code(Counter(0)) at (prev + 0, 17) to (start + 0, 22)
- Code(Counter(0)) at (prev + 2, 5) to (start + 0, 10)
- Code(Counter(0)) at (prev + 2, 9) to (start + 0, 15)
- Code(Counter(0)) at (prev + 2, 13) to (start + 0, 18)
- Code(Counter(0)) at (prev + 4, 5) to (start + 5, 10)
- Code(Counter(0)) at (prev + 0, 5) to (start + 0, 10)
- Code(Counter(0)) at (prev + 7, 9) to (start + 0, 15)
- Code(Counter(0)) at (prev + 2, 13) to (start + 0, 18)
- Code(Counter(0)) at (prev + 3, 1) to (start + 0, 2)
Highest counter ID seen: c0

46 changes: 46 additions & 0 deletions tests/coverage/call-method.coverage
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
LL| |#![feature(coverage_attribute)]
LL| |//@ edition: 2024
LL| |//@ min-llvm-version: 23
LL| |
LL| |// Basic test for method calls and chained method calls.
LL| |
LL| |#[rustfmt::skip]
LL| 1|fn call_method() {
LL| 1| let thing = Thing;
LL| |
LL| 1| thing
LL| | .
LL| 1| method
LL| | (
LL| 1| "arg"
LL| | )
LL| | ;
LL| |
LL| 1| thing
LL| 1| .
LL| 1| method
LL| 1| (
LL| 1| "arg"
LL| 1| )
LL| | .
LL| 1| method
LL| | (
LL| 1| "arg"
LL| | )
LL| | ;
LL| 1|}
LL| |
LL| |struct Thing;
LL| |
LL| |#[coverage(off)]
LL| |impl Thing {
LL| | fn method(&self, _arg: &str) -> &Self {
LL| | self
LL| | }
LL| |}
LL| |
LL| |#[coverage(off)]
LL| |fn main() {
LL| | call_method();
LL| |}

45 changes: 45 additions & 0 deletions tests/coverage/call-method.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#![feature(coverage_attribute)]
//@ edition: 2024
//@ min-llvm-version: 23

// Basic test for method calls and chained method calls.

#[rustfmt::skip]
fn call_method() {
let thing = Thing;

thing
.
method
(
"arg"
)
;

thing
.
method
(
"arg"
)
.
method
(
"arg"
)
;
}

struct Thing;

#[coverage(off)]
impl Thing {
fn method(&self, _arg: &str) -> &Self {
self
}
}

#[coverage(off)]
fn main() {
call_method();
}
Loading
Loading