Elie Kheirallah | e2bd850 | 2023-03-20 21:19:27 +0000 | [diff] [blame] | 1 | use common::{args, check}; |
| 2 | use libtest_mimic::{Trial, Conclusion}; |
| 3 | use pretty_assertions::assert_eq; |
| 4 | |
| 5 | use crate::common::do_run; |
| 6 | |
| 7 | #[macro_use] |
| 8 | mod common; |
| 9 | |
| 10 | |
| 11 | fn tests() -> Vec<Trial> { |
| 12 | vec![ |
| 13 | Trial::test("foo", || Ok(())), |
| 14 | Trial::test("bar", || Ok(())), |
| 15 | Trial::test("barro", || Ok(())), |
| 16 | ] |
| 17 | } |
| 18 | |
| 19 | #[test] |
| 20 | fn normal() { |
| 21 | check(args([]), tests, 3, |
| 22 | Conclusion { |
| 23 | num_filtered_out: 0, |
| 24 | num_passed: 3, |
| 25 | num_failed: 0, |
| 26 | num_ignored: 0, |
| 27 | num_measured: 0, |
| 28 | }, |
| 29 | " |
| 30 | test foo ... ok |
| 31 | test bar ... ok |
| 32 | test barro ... ok |
| 33 | " |
| 34 | ); |
| 35 | } |
| 36 | |
| 37 | #[test] |
| 38 | fn filter_one() { |
| 39 | check(args(["foo"]), tests, 1, |
| 40 | Conclusion { |
| 41 | num_filtered_out: 2, |
| 42 | num_passed: 1, |
| 43 | num_failed: 0, |
| 44 | num_ignored: 0, |
| 45 | num_measured: 0, |
| 46 | }, |
| 47 | "test foo ... ok", |
| 48 | ); |
| 49 | } |
| 50 | |
| 51 | #[test] |
| 52 | fn filter_two() { |
| 53 | check(args(["bar"]), tests, 2, |
| 54 | Conclusion { |
| 55 | num_filtered_out: 1, |
| 56 | num_passed: 2, |
| 57 | num_failed: 0, |
| 58 | num_ignored: 0, |
| 59 | num_measured: 0, |
| 60 | }, |
| 61 | " |
| 62 | test bar ... ok |
| 63 | test barro ... ok |
| 64 | ", |
| 65 | ); |
| 66 | } |
| 67 | |
| 68 | |
| 69 | #[test] |
| 70 | fn filter_exact() { |
| 71 | check(args(["bar", "--exact"]), tests, 1, |
| 72 | Conclusion { |
| 73 | num_filtered_out: 2, |
| 74 | num_passed: 1, |
| 75 | num_failed: 0, |
| 76 | num_ignored: 0, |
| 77 | num_measured: 0, |
| 78 | }, |
| 79 | "test bar ... ok", |
| 80 | ); |
| 81 | } |
| 82 | |
| 83 | #[test] |
| 84 | fn filter_two_and_skip() { |
| 85 | check(args(["--skip", "barro", "bar"]), tests, 1, |
| 86 | Conclusion { |
| 87 | num_filtered_out: 2, |
| 88 | num_passed: 1, |
| 89 | num_failed: 0, |
| 90 | num_ignored: 0, |
| 91 | num_measured: 0, |
| 92 | }, |
| 93 | "test bar ... ok", |
| 94 | ); |
| 95 | } |
| 96 | |
| 97 | #[test] |
| 98 | fn skip_nothing() { |
| 99 | check(args(["--skip", "peter"]), tests, 3, |
| 100 | Conclusion { |
| 101 | num_filtered_out: 0, |
| 102 | num_passed: 3, |
| 103 | num_failed: 0, |
| 104 | num_ignored: 0, |
| 105 | num_measured: 0, |
| 106 | }, |
| 107 | " |
| 108 | test foo ... ok |
| 109 | test bar ... ok |
| 110 | test barro ... ok |
| 111 | " |
| 112 | ); |
| 113 | } |
| 114 | |
| 115 | #[test] |
| 116 | fn skip_two() { |
| 117 | check(args(["--skip", "bar"]), tests, 1, |
| 118 | Conclusion { |
| 119 | num_filtered_out: 2, |
| 120 | num_passed: 1, |
| 121 | num_failed: 0, |
| 122 | num_ignored: 0, |
| 123 | num_measured: 0, |
| 124 | }, |
| 125 | "test foo ... ok" |
| 126 | ); |
| 127 | } |
| 128 | |
| 129 | #[test] |
| 130 | fn skip_exact() { |
| 131 | check(args(["--exact", "--skip", "bar"]), tests, 2, |
| 132 | Conclusion { |
| 133 | num_filtered_out: 1, |
| 134 | num_passed: 2, |
| 135 | num_failed: 0, |
| 136 | num_ignored: 0, |
| 137 | num_measured: 0, |
| 138 | }, |
| 139 | " |
| 140 | test foo ... ok |
| 141 | test barro ... ok |
| 142 | " |
| 143 | ); |
| 144 | } |
| 145 | |
| 146 | #[test] |
| 147 | fn terse_output() { |
| 148 | let (c, out) = do_run(args(["--format", "terse"]), tests()); |
| 149 | assert_eq!(c, Conclusion { |
| 150 | num_filtered_out: 0, |
| 151 | num_passed: 3, |
| 152 | num_failed: 0, |
| 153 | num_ignored: 0, |
| 154 | num_measured: 0, |
| 155 | }); |
| 156 | assert_log!(out, " |
| 157 | running 3 tests |
| 158 | ... |
| 159 | test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; \ |
| 160 | finished in 0.00s |
| 161 | "); |
| 162 | } |