2019-10-20 00:54:01 -07:00
|
|
|
/// This is just a huge hack to make a test runner (with no test cases)
|
|
|
|
/// look as if it's running a bunch of (async) test cases.
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! async_tests {
|
|
|
|
( $runner:ident { $( $name:ident : async $eval:block, )* } ) => {
|
2021-05-20 14:08:01 -07:00
|
|
|
#[allow(dead_code)]
|
2019-10-20 00:54:01 -07:00
|
|
|
fn $runner(_: &[()]) {
|
2019-11-02 20:55:07 -07:00
|
|
|
env_logger::init();
|
2019-10-20 00:54:01 -07:00
|
|
|
|
|
|
|
std::process::exit({
|
2021-01-05 14:17:23 -08:00
|
|
|
let rt = tokio::runtime::Runtime::new()
|
2019-10-30 22:52:00 -07:00
|
|
|
.expect("Failed to create runtime.");
|
2019-10-20 00:54:01 -07:00
|
|
|
|
|
|
|
let (_, errs) = rt.block_on(async {
|
|
|
|
println!();
|
|
|
|
println!("running tests");
|
|
|
|
println!();
|
2021-06-04 20:43:08 -07:00
|
|
|
|
|
|
|
#[allow(unused_mut)]
|
2019-10-20 00:54:01 -07:00
|
|
|
let mut oks: u32 = 0;
|
2021-06-04 20:43:08 -07:00
|
|
|
#[allow(unused_mut)]
|
2019-10-20 00:54:01 -07:00
|
|
|
let mut errs: u32 = 0;
|
|
|
|
$(
|
|
|
|
let $name = async {
|
2019-11-02 20:55:07 -07:00
|
|
|
let result: std::result::Result<(), String> = async {
|
2019-10-20 00:54:01 -07:00
|
|
|
$eval
|
|
|
|
}.await;
|
2019-11-02 20:55:07 -07:00
|
|
|
result
|
2019-10-20 00:54:01 -07:00
|
|
|
};
|
2019-12-30 21:35:23 -08:00
|
|
|
let $name = tokio::spawn($name);
|
2019-10-20 00:54:01 -07:00
|
|
|
)*
|
|
|
|
$(
|
2020-03-31 11:46:26 -07:00
|
|
|
let $name = $name.await.expect("Failed to spawn.");
|
2019-11-02 20:55:07 -07:00
|
|
|
)*
|
|
|
|
$(
|
|
|
|
print!("test {} ... ", stringify!($name));
|
|
|
|
match $name {
|
|
|
|
Ok(_) => {
|
|
|
|
println!("{}", "ok".green());
|
|
|
|
oks += 1;
|
|
|
|
}
|
|
|
|
Err(msg) => {
|
|
|
|
println!("{}", "error".bright_red());
|
|
|
|
println!("{}", msg);
|
|
|
|
errs += 1;
|
|
|
|
}
|
|
|
|
}
|
2019-10-20 00:54:01 -07:00
|
|
|
)*
|
|
|
|
println!();
|
|
|
|
print!("test result: {}. ", if errs > 0 { "error".bright_red() } else { "ok".green() });
|
|
|
|
println!("{} passed; {} failed; 0 ignored; 0 measured; 0 filtered out", oks, errs);
|
|
|
|
println!();
|
|
|
|
(oks, errs)
|
|
|
|
});
|
|
|
|
// Just returns #errs as exit code.
|
|
|
|
errs as i32
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! rassert {
|
|
|
|
( $x:expr ) => {
|
|
|
|
{
|
|
|
|
if $x { Ok(()) } else { Err(stringify!($x)) }?
|
|
|
|
}
|
|
|
|
};
|
2019-10-20 19:28:29 -07:00
|
|
|
( $x:expr, $format:expr $(, $arg:expr)* ) => {
|
|
|
|
{
|
|
|
|
if $x { Ok(()) } else { Err( format!($format, $( $arg )* ) ) }?
|
|
|
|
}
|
|
|
|
};
|
2019-10-20 00:54:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! rassert_eq {
|
|
|
|
( $a:expr, $b:expr ) => { rassert!($a == $b) };
|
2019-10-30 13:24:07 -07:00
|
|
|
( $a:expr, $b:expr, $format:expr $(, $arg:expr)* ) => {
|
2019-10-30 22:52:00 -07:00
|
|
|
rassert!($a == $b, $format $(, $arg )* )
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! rassert_ne {
|
|
|
|
( $a:expr, $b:expr ) => { rassert!($a != $b) };
|
|
|
|
( $a:expr, $b:expr, $format:expr $(, $arg:expr)* ) => {
|
|
|
|
rassert!($a != $b, $format $(, $arg )* )
|
2019-10-30 13:24:07 -07:00
|
|
|
};
|
2019-10-20 00:54:01 -07:00
|
|
|
}
|