oxedyne/fe2o3/fe2o3_core/src/test.rs
1006 bytes, 4 runs
created by r1870400018:122, which is this file's identity for as long as the history lasts, whatever it is later renamed to
download · who wrote it · its history
| 1 | //! Some utilities for testing and performance measurement. |
| 2 | |
| 3 | use crate::prelude::*; |
| 4 | |
| 5 | pub fn test_it< |
| 6 | F: Fn() -> Outcome<()> + 'static + Sync + Send |
| 7 | >( |
| 8 | filter: &str, |
| 9 | tags: &[&str], |
| 10 | closure: F, |
| 11 | ) |
| 12 | -> Outcome<()> |
| 13 | { |
| 14 | if tags.len() == 0 { |
| 15 | return Err(err!( |
| 16 | "The test must have at least one tag, being the title."; |
| 17 | Invalid, Input, Missing, Bug)); |
| 18 | } |
| 19 | for tag in tags { |
| 20 | if (*tag).starts_with(filter) { |
| 21 | test!("'{}' test commencing...", tags[0]); |
| 22 | res!(closure()); |
| 23 | test!("'{}' test completed.", tags[0]); |
| 24 | break; |
| 25 | } |
| 26 | } |
| 27 | Ok(()) |
| 28 | } |
| 29 | |
| 30 | #[cfg(test)] |
| 31 | mod tests { |
| 32 | use super::*; |
| 33 | |
| 34 | #[test] |
| 35 | fn test_000() -> Outcome<()> { |
| 36 | let result = test_it("hello", &["MyTest 000", "hello"], || { |
| 37 | let n = 42; |
| 38 | test!("n = {}", n); |
| 39 | req!(n, 43); |
| 40 | Ok(()) |
| 41 | }); |
| 42 | test!("result = {:?}", result); |
| 43 | log_finish_wait!(); |
| 44 | Ok(()) |
| 45 | } |
| 46 | } |