1 //! Test use of `rdroidtest` attribute macro.
2
3 use rdroidtest::{ignore_if, rdroidtest};
4
5 mod raw;
6
7 #[rdroidtest]
one_plus_one()8 fn one_plus_one() {
9 let result = 1 + 1;
10 assert_eq!(result, 2);
11 }
12
13 #[rdroidtest]
14 #[ignore_if(feeling_happy())]
grumble()15 fn grumble() {
16 let result = 1 + 1;
17 assert_eq!(result, 2);
18 }
19
20 #[rdroidtest]
21 #[ignore_if(!feeling_happy())]
clap_hands()22 fn clap_hands() {
23 let result = 1 + 1;
24 assert_eq!(result, 3);
25 }
26
feeling_happy() -> bool27 fn feeling_happy() -> bool {
28 false
29 }
30
31 #[rdroidtest(my_instances())]
is_less_than_five(param: u32)32 fn is_less_than_five(param: u32) {
33 assert!(param < 5);
34 }
35
36 #[rdroidtest(my_instances())]
37 #[ignore_if(feeling_odd)]
is_even(param: u32)38 fn is_even(param: u32) {
39 assert_eq!(param % 2, 0);
40 }
41
42 #[rdroidtest(my_instances())]
43 #[ignore_if(|p| !feeling_odd(p))]
is_odd(param: u32)44 fn is_odd(param: u32) {
45 assert_eq!(param % 2, 1);
46 }
47
feeling_odd(param: &u32) -> bool48 fn feeling_odd(param: &u32) -> bool {
49 *param % 2 == 1
50 }
51
my_instances() -> Vec<(String, u32)>52 fn my_instances() -> Vec<(String, u32)> {
53 vec![("one".to_string(), 1), ("two".to_string(), 2), ("three".to_string(), 3)]
54 }
55
56 #[rdroidtest(wrapped_instances())]
57 #[ignore_if(|p| !feeling_odder(p))]
is_odder(param: Param)58 fn is_odder(param: Param) {
59 assert_eq!(param.0 % 2, 1);
60 }
61
feeling_odder(param: &Param) -> bool62 fn feeling_odder(param: &Param) -> bool {
63 param.0 % 2 == 1
64 }
65
66 struct Param(u32);
67
wrapped_instances() -> Vec<(String, Param)>68 fn wrapped_instances() -> Vec<(String, Param)> {
69 vec![
70 ("one".to_string(), Param(1)),
71 ("two".to_string(), Param(2)),
72 ("three".to_string(), Param(3)),
73 ]
74 }
75
76 #[rdroidtest(more_instances())]
77 #[ignore_if(|p| p != "one")]
is_the_one(param: String)78 fn is_the_one(param: String) {
79 assert_eq!(param, "one");
80 }
81
more_instances() -> Vec<(String, String)>82 fn more_instances() -> Vec<(String, String)> {
83 vec![("one".to_string(), "one".to_string()), ("two".to_string(), "two".to_string())]
84 }
85
86 #[rdroidtest]
87 #[ignore]
ignore_me()88 fn ignore_me() {
89 panic!("shouldn't run!");
90 }
91
92 #[rdroidtest]
93 #[ignore_if(false)]
94 #[ignore]
ignore_me_too()95 fn ignore_me_too() {
96 panic!("shouldn't run either -- attribute trumps ignore_if!");
97 }
98
99 #[rdroidtest]
100 #[ignore]
101 #[ignore_if(false)]
ignore_me_as_well()102 fn ignore_me_as_well() {
103 panic!("shouldn't run either -- attribute trumps ignore_if, regardless of order!");
104 }
105
106 #[rdroidtest(my_instances())]
107 #[ignore]
ignore_all(param: u32)108 fn ignore_all(param: u32) {
109 panic!("parameterized test ({param}) shouldn't run");
110 }
111
112 rdroidtest::test_main!();
113