blob: fdac4069d36a5dff1b1c047e479d13f7de6f003a [file] [log] [blame]
Andrew Walbran13d5ebc2022-11-29 18:20:08 +00001//! Test runner.
2
3use core::ops::{Deref, FnOnce};
4use libtest_mimic::{Arguments, Failed, Trial};
Andrew Walbran7e69ba52023-05-10 14:47:49 +00005use linkme::distributed_slice;
Andrew Walbran24387602023-06-26 16:06:59 +00006use log::Level;
Andrew Walbran13d5ebc2022-11-29 18:20:08 +00007use std::env;
8
9/// Command-line arguments to ignore, because they are not supported by libtest-mimic.
10const IGNORED_ARGS: [&str; 2] = ["-Zunstable-options", "--report-time"];
11
Andrew Walbran7e69ba52023-05-10 14:47:49 +000012/// The collection of all tests to run.
13#[doc(hidden)]
14#[distributed_slice]
15pub static IGNORABLETEST_TESTS: [fn() -> Trial] = [..];
16
Andrew Walbran13d5ebc2022-11-29 18:20:08 +000017/// Runs all tests.
Andrew Walbran7e69ba52023-05-10 14:47:49 +000018pub fn main() {
Andrew Walbran24387602023-06-26 16:06:59 +000019 logger::init(logger::Config::default().with_min_level(Level::Debug));
Andrew Walbran13d5ebc2022-11-29 18:20:08 +000020 let args = Arguments::from_iter(env::args().filter(|arg| !IGNORED_ARGS.contains(&arg.deref())));
Andrew Walbran7e69ba52023-05-10 14:47:49 +000021 let tests = IGNORABLETEST_TESTS.iter().map(|test| test()).collect();
Andrew Walbran13d5ebc2022-11-29 18:20:08 +000022 libtest_mimic::run(&args, tests).exit();
23}
24
25/// Runs the given test.
26pub fn run(test: impl FnOnce()) -> Result<(), Failed> {
27 test();
28 Ok(())
29}