diff --git a/src/options/dir_action.rs b/src/options/dir_action.rs index d2cacaf..6d84a97 100644 --- a/src/options/dir_action.rs +++ b/src/options/dir_action.rs @@ -63,11 +63,13 @@ mod test { #[test] fn $name() { use options::parser::Arg; - use options::test::assert_parses; + use options::test::parse_for_test; use options::test::Strictnesses::*; static TEST_ARGS: &[&Arg] = &[&flags::RECURSE, &flags::LIST_DIRS, &flags::TREE, &flags::LEVEL ]; - assert_parses($inputs.as_ref(), TEST_ARGS, $stricts, |mf| $type::deduce(mf), $result) + for result in parse_for_test($inputs.as_ref(), TEST_ARGS, $stricts, |mf| $type::deduce(mf)) { + assert_eq!(result, $result); + } } }; } diff --git a/src/options/filter.rs b/src/options/filter.rs index 184b7d8..17a2b47 100644 --- a/src/options/filter.rs +++ b/src/options/filter.rs @@ -150,11 +150,13 @@ mod test { #[test] fn $name() { use options::parser::Arg; - use options::test::assert_parses; + use options::test::parse_for_test; use options::test::Strictnesses::*; static TEST_ARGS: &[&Arg] = &[ &flags::SORT, &flags::ALL, &flags::TREE, &flags::IGNORE_GLOB ]; - assert_parses($inputs.as_ref(), TEST_ARGS, $stricts, |mf| $type::deduce(mf), $result) + for result in parse_for_test($inputs.as_ref(), TEST_ARGS, $stricts, |mf| $type::deduce(mf)) { + assert_eq!(result, $result); + } } }; } diff --git a/src/options/mod.rs b/src/options/mod.rs index 0299cad..7b258d5 100644 --- a/src/options/mod.rs +++ b/src/options/mod.rs @@ -160,7 +160,6 @@ pub mod test { use options::parser::{Arg, MatchedFlags}; use std::ffi::OsString; use fs::filter::{SortField, SortCase}; - use std::fmt::Debug; #[derive(PartialEq, Debug)] @@ -173,24 +172,30 @@ pub mod test { /// This function gets used by the other testing modules. /// It can run with one or both strictness values: if told to run with /// both, then both should resolve to the same result. - pub fn assert_parses(inputs: &[&str], args: &'static [&'static Arg], strictnesses: Strictnesses, get: F, result: T) - where T: PartialEq + Debug, F: Fn(&MatchedFlags) -> T + /// + /// It returns a vector with one or two elements in. + /// These elements can then be tested with assert_eq or what have you. + pub fn parse_for_test(inputs: &[&str], args: &'static [&'static Arg], strictnesses: Strictnesses, get: F) -> Vec + where F: Fn(&MatchedFlags) -> T { use self::Strictnesses::*; use options::parser::{Args, Strictness}; use std::ffi::OsString; let bits = inputs.into_iter().map(|&o| os(o)).collect::>(); + let mut rezzies = Vec::new(); if strictnesses == Last || strictnesses == Both { let results = Args(args).parse(bits.iter(), Strictness::UseLastArguments); - assert_eq!(get(&results.unwrap().flags), result); + rezzies.push(get(&results.unwrap().flags)); } if strictnesses == Complain || strictnesses == Both { let results = Args(args).parse(bits.iter(), Strictness::ComplainAboutRedundantArguments); - assert_eq!(get(&results.unwrap().flags), result); + rezzies.push(get(&results.unwrap().flags)); } + + rezzies } /// Creates an `OSStr` (used in tests) diff --git a/src/options/view.rs b/src/options/view.rs index 5fce5ab..94889ca 100644 --- a/src/options/view.rs +++ b/src/options/view.rs @@ -219,12 +219,13 @@ impl SizeFormat { } +const TIME_STYLES: &[&str] = &["default", "long-iso", "full-iso", "iso"]; + impl TimeFormat { /// Determine how time should be formatted in timestamp columns. fn deduce(matches: &MatchedFlags) -> Result { pub use output::time::{DefaultFormat, ISOFormat}; - const STYLES: &[&str] = &["default", "long-iso", "full-iso", "iso"]; let word = match matches.get(&flags::TIME_STYLE)? { Some(w) => w, @@ -244,7 +245,7 @@ impl TimeFormat { Ok(TimeFormat::FullISO) } else { - Err(Misfire::bad_argument(&flags::TIME_STYLE, word, STYLES)) + Err(Misfire::bad_argument(&flags::TIME_STYLE, word, TIME_STYLES)) } } } @@ -425,14 +426,16 @@ mod test { #[test] fn $name() { use options::parser::Arg; - use options::test::assert_parses; + use options::test::parse_for_test; use options::test::Strictnesses::*; static TEST_ARGS: &[&Arg] = &[ &flags::BINARY, &flags::BYTES, &flags::TIME, &flags::MODIFIED, &flags::CREATED, &flags::ACCESSED, &flags::COLOR, &flags::COLOUR ]; - assert_parses($inputs.as_ref(), TEST_ARGS, $stricts, |mf| $type::deduce(mf), $result) + for result in parse_for_test($inputs.as_ref(), TEST_ARGS, $stricts, |mf| $type::deduce(mf)) { + assert_eq!(result, $result); + } } }; } @@ -453,16 +456,20 @@ mod test { // Default behaviour test!(empty: TimeTypes <- []; Both => Ok(TimeTypes::default())); + + // Modified test!(modified: TimeTypes <- ["--modified"]; Both => Ok(TimeTypes { accessed: false, modified: true, created: false })); test!(m: TimeTypes <- ["-m"]; Both => Ok(TimeTypes { accessed: false, modified: true, created: false })); test!(time_mod: TimeTypes <- ["--time=modified"]; Both => Ok(TimeTypes { accessed: false, modified: true, created: false })); test!(time_m: TimeTypes <- ["-tmod"]; Both => Ok(TimeTypes { accessed: false, modified: true, created: false })); + // Accessed test!(acc: TimeTypes <- ["--accessed"]; Both => Ok(TimeTypes { accessed: true, modified: false, created: false })); test!(a: TimeTypes <- ["-u"]; Both => Ok(TimeTypes { accessed: true, modified: false, created: false })); test!(time_acc: TimeTypes <- ["--time", "accessed"]; Both => Ok(TimeTypes { accessed: true, modified: false, created: false })); test!(time_a: TimeTypes <- ["-t", "acc"]; Both => Ok(TimeTypes { accessed: true, modified: false, created: false })); + // Created test!(cr: TimeTypes <- ["--created"]; Both => Ok(TimeTypes { accessed: false, modified: false, created: true })); test!(c: TimeTypes <- ["-U"]; Both => Ok(TimeTypes { accessed: false, modified: false, created: true })); test!(time_cr: TimeTypes <- ["--time=created"]; Both => Ok(TimeTypes { accessed: false, modified: false, created: true }));