/// This function reuses and tweaks the code generally used by cargo test.
/// This will work both when called by 'cargo run' and 'cargo test', although
/// test somewhat mangles the output.
/// This currently doesn't check that failing tests are actually failing
This function reuses and tweaks the code generally used by cargo test.
This will work both when called by 'cargo run' and 'cargo test', although
test somewhat mangles the output.
This currently doesn't check that failing tests are actually failing
This function reuses and tweaks the code generally used by cargo test . This will work both when called by ' cargo run ' and ' cargo test ' although test somewhat mangles the output . This currently doesn ' t check that failing tests are actually failing
pub fn runner(tests: Vec<Test>, args: Vec<String>) {
    fn partition_map<A, O, E, F: Fn(A) -> Result<O, E>>(v: Vec<A>, f: F) -> (Vec<O>, Vec<E>) {
        v.into_iter()
            .fold((Vec::new(), Vec::new()), |(mut oks, mut errs), elem| {
                match f(elem) {
                    Ok(v) => oks.push(v),
                    Err(v) => errs.push(v),
                };
                (oks, errs)
            })
    }
    let (should_pass, should_fail) = partition_map(tests, passing);
    println!("Scenario tests:");
    for test in &should_pass {
        println!("\t{0}  Running {1}", "✔".green(), test.desc.name)
    }
    test_main(&args, should_pass, None);
    for test in should_fail {
        match test {
            Test::Passing(_) => panic!("This should be impossible"),
            Test::Failing(test, excuse, name) => {
                let name_and_shame = match name {
                    Some(name) => format!("and it's {}'s job to fix it", name.red()),
                    None => "".to_string(),
                };
                println!(
                    "\t{0} {1} was not run because {2} {3}",
                    "✘".red(),
                    test.desc.name,
                    excuse,
                    name_and_shame,
                )
            }
        }
    }
    println!();
}
pub fn runner ( tests : Vec < Test > , args : Vec < String > ) { fn partition_map < A , O , E , F : Fn ( A ) -> Result < O , E > > ( v : Vec < A > , f : F ) -> ( Vec < O > , Vec < E > ) { v . into_iter ( ) . fold ( ( Vec :: new ( ) , Vec :: new ( ) ) , | ( mut oks , mut errs ) , elem | { match f ( elem ) { Ok ( v ) => oks . push ( v ) , Err ( v ) => errs . push ( v ) , } ; ( oks , errs ) } ) } let ( should_pass , should_fail ) = partition_map ( tests , passing ) ; println ! ( " " ) ; for test in & should_pass { println ! ( " \t " " g een() , st.d sc.n me) } test_main ( & args , should_pass , None ) ; for test in should_fail { match test { Test :: Passing ( _ ) => panic ! ( " " ) , Test :: Failing ( test , excuse , name ) => { let name_and_shame = match name { Some ( name ) => format ! ( " " name red ( ) ) , None => " " . to_string ( ) , } ; println ! ( " \t " " r d() , test desc name excuse name_and_shame ) } } } println ! ( ) ; }
This function reuses and tweaks the code generally used by cargo test.
This function reuses and tweaks the code generally used by cargo test .
tests
Vec<Test>
args
Vec<String>