1 #![allow(unused)]
2 #![warn(clippy::missing_assert_message)]
3
4 macro_rules! bar {
5 ($( $x:expr ),*) => {
6 foo()
7 };
8 }
9
10 // Should trigger warning
asserts_without_message()11 fn asserts_without_message() {
12 assert!(foo());
13 assert_eq!(foo(), foo());
14 assert_ne!(foo(), foo());
15 debug_assert!(foo());
16 debug_assert_eq!(foo(), foo());
17 debug_assert_ne!(foo(), foo());
18 }
19
20 // Should trigger warning
asserts_without_message_but_with_macro_calls()21 fn asserts_without_message_but_with_macro_calls() {
22 assert!(bar!(true));
23 assert!(bar!(true, false));
24 assert_eq!(bar!(true), foo());
25 assert_ne!(bar!(true, true), bar!(true));
26 }
27
28 // Should trigger warning
asserts_with_trailing_commas()29 fn asserts_with_trailing_commas() {
30 assert!(foo(),);
31 assert_eq!(foo(), foo(),);
32 assert_ne!(foo(), foo(),);
33 debug_assert!(foo(),);
34 debug_assert_eq!(foo(), foo(),);
35 debug_assert_ne!(foo(), foo(),);
36 }
37
38 // Should not trigger warning
asserts_with_message_and_with_macro_calls()39 fn asserts_with_message_and_with_macro_calls() {
40 assert!(bar!(true), "msg");
41 assert!(bar!(true, false), "msg");
42 assert_eq!(bar!(true), foo(), "msg");
43 assert_ne!(bar!(true, true), bar!(true), "msg");
44 }
45
46 // Should not trigger warning
asserts_with_message()47 fn asserts_with_message() {
48 assert!(foo(), "msg");
49 assert_eq!(foo(), foo(), "msg");
50 assert_ne!(foo(), foo(), "msg");
51 debug_assert!(foo(), "msg");
52 debug_assert_eq!(foo(), foo(), "msg");
53 debug_assert_ne!(foo(), foo(), "msg");
54 }
55
56 // Should not trigger warning
57 #[test]
asserts_without_message_but_inside_a_test_function()58 fn asserts_without_message_but_inside_a_test_function() {
59 assert!(foo());
60 assert_eq!(foo(), foo());
61 assert_ne!(foo(), foo());
62 debug_assert!(foo());
63 debug_assert_eq!(foo(), foo());
64 debug_assert_ne!(foo(), foo());
65 }
66
foo() -> bool67 fn foo() -> bool {
68 true
69 }
70
71 // Should not trigger warning
72 #[cfg(test)]
73 mod tests {
74 use super::foo;
asserts_without_message_but_inside_a_test_module()75 fn asserts_without_message_but_inside_a_test_module() {
76 assert!(foo());
77 assert_eq!(foo(), foo());
78 assert_ne!(foo(), foo());
79 debug_assert!(foo());
80 debug_assert_eq!(foo(), foo());
81 debug_assert_ne!(foo(), foo());
82 }
83 }
84