blob: 4ec3d791617d3db23ca648c2e804af0218f7356e [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 Walbran13d5ebc2022-11-29 18:20:08 +00006use std::env;
7
8/// Command-line arguments to ignore, because they are not supported by libtest-mimic.
9const IGNORED_ARGS: [&str; 2] = ["-Zunstable-options", "--report-time"];
10
Andrew Walbran7e69ba52023-05-10 14:47:49 +000011/// The collection of all tests to run.
12#[doc(hidden)]
13#[distributed_slice]
14pub static IGNORABLETEST_TESTS: [fn() -> Trial] = [..];
15
Andrew Walbran13d5ebc2022-11-29 18:20:08 +000016/// Runs all tests.
Andrew Walbran7e69ba52023-05-10 14:47:49 +000017pub fn main() {
Andrew Walbran13d5ebc2022-11-29 18:20:08 +000018 let args = Arguments::from_iter(env::args().filter(|arg| !IGNORED_ARGS.contains(&arg.deref())));
Andrew Walbran7e69ba52023-05-10 14:47:49 +000019 let tests = IGNORABLETEST_TESTS.iter().map(|test| test()).collect();
Andrew Walbran13d5ebc2022-11-29 18:20:08 +000020 libtest_mimic::run(&args, tests).exit();
21}
22
23/// Runs the given test.
24pub fn run(test: impl FnOnce()) -> Result<(), Failed> {
25 test();
26 Ok(())
27}