1 //! Test runner. 2 3 use core::ops::{Deref, FnOnce}; 4 use libtest_mimic::{Arguments, Failed, Trial}; 5 use linkme::distributed_slice; 6 use log::LevelFilter; 7 use std::env; 8 9 /// Command-line arguments to ignore, because they are not supported by libtest-mimic. 10 const IGNORED_ARGS: [&str; 2] = ["-Zunstable-options", "--report-time"]; 11 12 /// The collection of all non-parameterized tests to run. 13 #[doc(hidden)] 14 #[distributed_slice] 15 pub static RDROIDTEST_TESTS: [fn() -> Trial] = [..]; 16 17 /// The collection of all parameterized tests to run. 18 #[doc(hidden)] 19 #[distributed_slice] 20 pub static RDROIDTEST_PTESTS: [fn() -> Vec<Trial>] = [..]; 21 22 /// Runs all tests. main()23pub fn main() { 24 logger::init(logger::Config::default().with_max_level(LevelFilter::Debug)); 25 let args = Arguments::from_iter(env::args().filter(|arg| !IGNORED_ARGS.contains(&arg.deref()))); 26 27 let tests = RDROIDTEST_TESTS 28 .iter() 29 .map(|test| test()) 30 .chain(RDROIDTEST_PTESTS.iter().flat_map(|test| test())) 31 .collect(); 32 33 libtest_mimic::run(&args, tests).exit(); 34 } 35 36 /// Runs the given test. run(test: impl FnOnce()) -> Result<(), Failed>37pub fn run(test: impl FnOnce()) -> Result<(), Failed> { 38 test(); 39 Ok(()) 40 } 41