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