From: Ian Jackson Date: Mon, 17 May 2021 16:33:42 +0000 (+0100) Subject: apitest: Move portmanteau machinery from wdriver X-Git-Tag: otter-0.6.0~186 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=fd490833bd41fd4461c7b21e196e3c243ef0220c;p=otter.git apitest: Move portmanteau machinery from wdriver Signed-off-by: Ian Jackson --- diff --git a/apitest/apitest.rs b/apitest/apitest.rs index 7fa9474b..a9463421 100644 --- a/apitest/apitest.rs +++ b/apitest/apitest.rs @@ -1024,3 +1024,50 @@ pub fn setup_core(module_paths: &[&str], early_args: EarlyArgPredicate) -> wanted_tests, }) } + +pub struct PortmanteauMember { + pub path: &'static str, + pub f: fn() -> Result<(), Explode>, +} +inventory::collect!(PortmanteauMember); + +#[macro_export] +macro_rules! portmanteau_has { + ($path:literal, $mod:ident) => { + #[path = $path] mod $mod; + inventory::submit!(PortmanteauMember { path: $path, f: $mod::main }); + } +} + +#[throws(AE)] +pub fn portmanteau_main(prefix: &str){ + let arg = 'arg: loop { + for (ai, s) in env::args().enumerate() { + let plausible = |s: &str| s.starts_with(&format!("{}-",prefix)); + + break 'arg if ai == 0 { + let s = s.rsplitn(2,'/').next().unwrap(); + if ! plausible(s) { continue } + s + } else { + let s = s.strip_prefix("--test=") + .expect("found non-long-option looking for --test={wdt,at}-*"); + if ! plausible(s) { + panic!("found non --no-bwrap --{}-* option looking for --{}-*", + prefix,prefix); + } + s + }.to_owned(); + } + panic!("ran out of options looking for --test={}-*", prefix); + }; + + let f = inventory::iter::.into_iter() + .find_map(|pm| { + let n = pm.path.strip_suffix(".rs").unwrap(); + if n == arg { Some(pm.f) } else { None } + }) + .expect("unrecognosed {wdt,at}-* portanteau member"); + + f()?; +} diff --git a/wdriver/wdriver.rs b/wdriver/wdriver.rs index f4fb2601..8e9ad7ee 100644 --- a/wdriver/wdriver.rs +++ b/wdriver/wdriver.rs @@ -891,52 +891,10 @@ pub fn as_usual Result<(), Explode>>( // ==================== portmanteau binary ==================== -pub struct PortmanteauMember { - path: &'static str, - f: fn() -> Result<(), Explode>, -} -inventory::collect!(PortmanteauMember); - -macro_rules! portmanteau_has { - ($path:literal, $mod:ident) => { - #[path = $path] mod $mod; - inventory::submit!(PortmanteauMember { path: $path, f: $mod::main }); - } -} - -#[throws(AE)] -fn main(){ - let arg = 'arg: loop { - for (ai, s) in env::args().enumerate() { - let plausible = |s: &str| s.starts_with("wdt-"); - - break 'arg if ai == 0 { - let s = s.rsplitn(2,'/').next().unwrap(); - if ! plausible(s) { continue } - s - } else { - let s = s.strip_prefix("--test=") - .expect("found non-long-option looking for --test=wdt-*"); - if ! plausible(s) { - panic!("found non --no-bwrap --wdt-* option looking for --wdt-*"); - } - s - }.to_owned(); - } - panic!("ran out of options looking for --test=wdt-*"); - }; - - let f = inventory::iter::.into_iter() - .find_map(|pm| { - let n = pm.path.strip_suffix(".rs").unwrap(); - if n == arg { Some(pm.f) } else { None } - }) - .expect("unrecognosed wdt-* portanteau member"); - - f()?; -} - portmanteau_has!("wdt-altergame.rs", wdt_altergame); portmanteau_has!("wdt-hand.rs", wdt_hand); portmanteau_has!("wdt-simple.rs", wdt_simple); portmanteau_has!("wdt-bundles.rs", wdt_bundles); + +#[throws(AE)] +fn main() { portmanteau_main("wdt")? }