Skip to content

Commit

Permalink
Merge pull request #5 from wcampbell0x2a/update-panic-msg-more
Browse files Browse the repository at this point in the history
Update to modern rust
  • Loading branch information
wcampbell0x2a committed Sep 11, 2023
2 parents 20259ac + 87cb7b4 commit dc1ab9f
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ macro_rules! assert_eq_hex {
// borrow is initialized even before the values are compared, leading to a
// noticeable slow down.
panic!(r#"assertion `left == right` failed
left: {:#x?},
left: {:#x?}
right: {:#x?}"#, &*left_val, &*right_val)
}
}
Expand All @@ -38,10 +38,9 @@ macro_rules! assert_eq_hex {
// The reborrows below are intentional. Without them, the stack slot for the
// borrow is initialized even before the values are compared, leading to a
// noticeable slow down.
panic!(r#"assertion `left == right` failed
left: {:#x?},
right: {:#x?}: {}"#, &*left_val, &*right_val,
format_args!($($arg)+))
panic!(r#"assertion `left == right` failed: {}
left: {:#x?}
right: {:#x?}"#, format_args!($($arg)+) &*left_val, &*right_val)
}
}
}
Expand All @@ -62,7 +61,7 @@ macro_rules! assert_ne_hex {
// borrow is initialized even before the values are compared, leading to a
// noticeable slow down.
panic!(r#"assertion `left != right` failed
left: {:#x?},
left: {:#x?}
right: {:#x?}"#, &*left_val, &*right_val)
}
}
Expand All @@ -75,10 +74,9 @@ macro_rules! assert_ne_hex {
// The reborrows below are intentional. Without them, the stack slot for the
// borrow is initialized even before the values are compared, leading to a
// noticeable slow down.
panic!(r#"assertion `left != right` failed
left: {:#x?},
right: {:#x?}: {}"#, &*left_val, &*right_val,
format_args!($($arg)+))
panic!(r#"assertion `left != right` failed: {}
left: {:#x?}
right: {:#x?}"#, format_args!($($arg)+), &*left_val, &*right_val)
}
}
}
Expand All @@ -91,23 +89,23 @@ mod tests {

#[test]
#[should_panic(expected = r#"assertion `left == right` failed
left: 0x50,
left: 0x50
right: 0x46"#)]
fn test_eq_0() {
assert_eq_hex!(0x50, 0x46);
}

#[test]
#[should_panic(expected = r#"assertion `left == right` failed
left: 0xff,
left: 0xff
right: 0x46"#)]
fn test_eq_1() {
assert_eq_hex!(0xff, 0x46);
}

#[test]
#[should_panic(expected = r#"assertion `left == right` failed
left: 0xff,
left: 0xff
right: 0x46"#)]
fn test_eq_2() {
assert_eq_hex!(0xff, 0x46);
Expand All @@ -119,7 +117,7 @@ mod tests {
0x0,
0x1,
0x2,
],
]
right: [
0x46,
0x50,
Expand All @@ -131,17 +129,25 @@ mod tests {

#[test]
#[should_panic(expected = r#"assertion `left != right` failed
left: 0x50,
left: 0x50
right: 0x50"#)]
fn test_ne_0() {
assert_ne_hex!(0x50, 0x50);
}

#[test]
#[should_panic(expected = r#"assertion `left != right` failed
left: 0xff,
left: 0xff
right: 0xff"#)]
fn test_ne_1() {
assert_ne_hex!(0xff, 0xff);
}

#[test]
#[should_panic(expected = r#"assertion `left != right` failed: yikes
left: 0xff
right: 0xff"#)]
fn test_ne_more() {
assert_ne_hex!(0xff, 0xff, "yikes");
}
}

0 comments on commit dc1ab9f

Please sign in to comment.