2023-03-10 03:53:50 -06:00
|
|
|
#![allow(unused)]
|
|
|
|
#![warn(clippy::missing_assert_message)]
|
|
|
|
|
|
|
|
macro_rules! bar {
|
|
|
|
($( $x:expr ),*) => {
|
|
|
|
foo()
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// Should trigger warning
|
|
|
|
fn asserts_without_message() {
|
|
|
|
assert!(foo());
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: assert without any message
|
2023-03-10 03:53:50 -06:00
|
|
|
assert_eq!(foo(), foo());
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: assert without any message
|
2023-03-10 03:53:50 -06:00
|
|
|
assert_ne!(foo(), foo());
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: assert without any message
|
2023-03-10 03:53:50 -06:00
|
|
|
debug_assert!(foo());
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: assert without any message
|
2023-03-10 03:53:50 -06:00
|
|
|
debug_assert_eq!(foo(), foo());
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: assert without any message
|
2023-03-10 03:53:50 -06:00
|
|
|
debug_assert_ne!(foo(), foo());
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: assert without any message
|
2023-03-10 03:53:50 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// Should trigger warning
|
|
|
|
fn asserts_without_message_but_with_macro_calls() {
|
|
|
|
assert!(bar!(true));
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: assert without any message
|
2023-03-10 03:53:50 -06:00
|
|
|
assert!(bar!(true, false));
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: assert without any message
|
2023-03-10 03:53:50 -06:00
|
|
|
assert_eq!(bar!(true), foo());
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: assert without any message
|
2023-03-10 03:53:50 -06:00
|
|
|
assert_ne!(bar!(true, true), bar!(true));
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: assert without any message
|
2023-03-10 03:53:50 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// Should trigger warning
|
|
|
|
fn asserts_with_trailing_commas() {
|
|
|
|
assert!(foo(),);
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: assert without any message
|
2023-03-10 03:53:50 -06:00
|
|
|
assert_eq!(foo(), foo(),);
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: assert without any message
|
2023-03-10 03:53:50 -06:00
|
|
|
assert_ne!(foo(), foo(),);
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: assert without any message
|
2023-03-10 03:53:50 -06:00
|
|
|
debug_assert!(foo(),);
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: assert without any message
|
2023-03-10 03:53:50 -06:00
|
|
|
debug_assert_eq!(foo(), foo(),);
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: assert without any message
|
2023-03-10 03:53:50 -06:00
|
|
|
debug_assert_ne!(foo(), foo(),);
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: assert without any message
|
2023-03-10 03:53:50 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// Should not trigger warning
|
|
|
|
fn asserts_with_message_and_with_macro_calls() {
|
|
|
|
assert!(bar!(true), "msg");
|
|
|
|
assert!(bar!(true, false), "msg");
|
|
|
|
assert_eq!(bar!(true), foo(), "msg");
|
|
|
|
assert_ne!(bar!(true, true), bar!(true), "msg");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Should not trigger warning
|
|
|
|
fn asserts_with_message() {
|
|
|
|
assert!(foo(), "msg");
|
|
|
|
assert_eq!(foo(), foo(), "msg");
|
|
|
|
assert_ne!(foo(), foo(), "msg");
|
|
|
|
debug_assert!(foo(), "msg");
|
|
|
|
debug_assert_eq!(foo(), foo(), "msg");
|
|
|
|
debug_assert_ne!(foo(), foo(), "msg");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Should not trigger warning
|
|
|
|
#[test]
|
|
|
|
fn asserts_without_message_but_inside_a_test_function() {
|
|
|
|
assert!(foo());
|
|
|
|
assert_eq!(foo(), foo());
|
|
|
|
assert_ne!(foo(), foo());
|
|
|
|
debug_assert!(foo());
|
|
|
|
debug_assert_eq!(foo(), foo());
|
|
|
|
debug_assert_ne!(foo(), foo());
|
|
|
|
}
|
|
|
|
|
2023-07-02 07:35:19 -05:00
|
|
|
fn foo() -> bool {
|
|
|
|
true
|
|
|
|
}
|
|
|
|
|
2023-03-10 03:53:50 -06:00
|
|
|
// Should not trigger warning
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
2023-07-02 07:35:19 -05:00
|
|
|
use super::foo;
|
2023-03-10 03:53:50 -06:00
|
|
|
fn asserts_without_message_but_inside_a_test_module() {
|
|
|
|
assert!(foo());
|
|
|
|
assert_eq!(foo(), foo());
|
|
|
|
assert_ne!(foo(), foo());
|
|
|
|
debug_assert!(foo());
|
|
|
|
debug_assert_eq!(foo(), foo());
|
|
|
|
debug_assert_ne!(foo(), foo());
|
|
|
|
}
|
|
|
|
}
|