From 6740faa78117068ed4bbf51999c2b0ea7952d1d3 Mon Sep 17 00:00:00 2001 From: Benjamin Sago Date: Sun, 13 Aug 2017 11:14:58 +0100 Subject: [PATCH] env vars should be referenced, not copied MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Just because the type that gets used right now is Copy and Clone doesn’t mean that when we pass mock ones in for tests they’ll be those two as well. So we have to go through and add &s everywhere. --- src/exa.rs | 2 +- src/options/help.rs | 6 +++--- src/options/mod.rs | 12 ++++++------ src/options/version.rs | 2 +- src/options/view.rs | 12 ++++++------ 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/exa.rs b/src/exa.rs index 0641006..5cb5e33 100644 --- a/src/exa.rs +++ b/src/exa.rs @@ -69,7 +69,7 @@ impl Vars for LiveVars { impl<'args, 'w, W: Write + 'w> Exa<'args, 'w, W> { pub fn new(args: I, writer: &'w mut W) -> Result, Misfire> where I: Iterator { - Options::parse(args, LiveVars).map(move |(options, args)| { + Options::parse(args, &LiveVars).map(move |(options, args)| { Exa { options, writer, args } }) } diff --git a/src/options/help.rs b/src/options/help.rs index 69f3810..ed56468 100644 --- a/src/options/help.rs +++ b/src/options/help.rs @@ -130,21 +130,21 @@ mod test { #[test] fn help() { let args = [ os("--help") ]; - let opts = Options::parse(&args, None); + let opts = Options::parse(&args, &None); assert!(opts.is_err()) } #[test] fn help_with_file() { let args = [ os("--help"), os("me") ]; - let opts = Options::parse(&args, None); + let opts = Options::parse(&args, &None); assert!(opts.is_err()) } #[test] fn unhelpful() { let args = []; - let opts = Options::parse(&args, None); + let opts = Options::parse(&args, &None); assert!(opts.is_ok()) // no help when --help isn’t passed } } diff --git a/src/options/mod.rs b/src/options/mod.rs index 1360a63..110c838 100644 --- a/src/options/mod.rs +++ b/src/options/mod.rs @@ -115,7 +115,7 @@ impl Options { /// struct and a list of free filenames, using the environment variables /// for extra options. #[allow(unused_results)] - pub fn parse<'args, I, V>(args: I, vars: V) -> Result<(Options, Vec<&'args OsStr>), Misfire> + pub fn parse<'args, I, V>(args: I, vars: &V) -> Result<(Options, Vec<&'args OsStr>), Misfire> where I: IntoIterator, V: Vars { use options::parser::{Matches, Strictness}; @@ -151,7 +151,7 @@ impl Options { /// Determines the complete set of options based on the given command-line /// arguments, after they’ve been parsed. - fn deduce(matches: &MatchedFlags, vars: V) -> Result { + fn deduce(matches: &MatchedFlags, vars: &V) -> Result { let dir_action = DirAction::deduce(matches)?; let filter = FileFilter::deduce(matches)?; let view = View::deduce(matches, vars)?; @@ -230,28 +230,28 @@ pub mod test { #[test] fn files() { let args = [ os("this file"), os("that file") ]; - let outs = Options::parse(&args, None).unwrap().1; + let outs = Options::parse(&args, &None).unwrap().1; assert_eq!(outs, vec![ &os("this file"), &os("that file") ]) } #[test] fn no_args() { let nothing: Vec = Vec::new(); - let outs = Options::parse(¬hing, None).unwrap().1; + let outs = Options::parse(¬hing, &None).unwrap().1; assert!(outs.is_empty()); // Listing the `.` directory is done in main.rs } #[test] fn long_across() { let args = [ os("--long"), os("--across") ]; - let opts = Options::parse(&args, None); + let opts = Options::parse(&args, &None); assert_eq!(opts.unwrap_err(), Misfire::Useless(&flags::ACROSS, true, &flags::LONG)) } #[test] fn oneline_across() { let args = [ os("--oneline"), os("--across") ]; - let opts = Options::parse(&args, None); + let opts = Options::parse(&args, &None); assert_eq!(opts.unwrap_err(), Misfire::Useless(&flags::ACROSS, true, &flags::ONE_LINE)) } } diff --git a/src/options/version.rs b/src/options/version.rs index 0cd4c54..fc4fa96 100644 --- a/src/options/version.rs +++ b/src/options/version.rs @@ -54,7 +54,7 @@ mod test { #[test] fn help() { let args = [ os("--version") ]; - let opts = Options::parse(&args, None); + let opts = Options::parse(&args, &None); assert!(opts.is_err()) } } diff --git a/src/options/view.rs b/src/options/view.rs index b310524..dd55b8d 100644 --- a/src/options/view.rs +++ b/src/options/view.rs @@ -13,7 +13,7 @@ use info::filetype::FileExtensions; impl View { /// Determine which view to use and all of that view’s arguments. - pub fn deduce(matches: &MatchedFlags, vars: V) -> Result { + pub fn deduce(matches: &MatchedFlags, vars: &V) -> Result { let mode = Mode::deduce(matches, vars)?; let colours = Colours::deduce(matches)?; let style = FileStyle::deduce(matches)?; @@ -25,7 +25,7 @@ impl View { impl Mode { /// Determine the mode from the command-line arguments. - pub fn deduce(matches: &MatchedFlags, vars: V) -> Result { + pub fn deduce(matches: &MatchedFlags, vars: &V) -> Result { use options::misfire::Misfire::*; let long = || { @@ -97,7 +97,7 @@ impl Mode { if matches.has(&flags::GRID)? { let other_options_mode = other_options_scan()?; if let Mode::Grid(grid) = other_options_mode { - let row_threshold = Some(5); + let row_threshold = RowThreshold::deduce(vars)?; return Ok(Mode::GridDetails(grid_details::Options { grid, details, row_threshold })); } else { @@ -153,7 +153,7 @@ impl TerminalWidth { /// Determine a requested terminal width from the command-line arguments. /// /// Returns an error if a requested width doesn’t parse to an integer. - fn deduce(vars: V) -> Result { + fn deduce(vars: &V) -> Result { if let Some(columns) = vars.get("COLUMNS").and_then(|s| s.into_string().ok()) { match columns.parse() { Ok(width) => Ok(TerminalWidth::Set(width)), @@ -482,7 +482,7 @@ mod test { /// Like above, but with $vars. #[test] fn $name() { - for result in parse_for_test($inputs.as_ref(), TEST_ARGS, $stricts, |mf| $type::deduce(mf, $vars)) { + for result in parse_for_test($inputs.as_ref(), TEST_ARGS, $stricts, |mf| $type::deduce(mf, &$vars)) { assert_eq!(result.unwrap_err(), $result); } } @@ -492,7 +492,7 @@ mod test { /// Like further above, but with $vars. #[test] fn $name() { - for result in parse_for_test($inputs.as_ref(), TEST_ARGS, $stricts, |mf| $type::deduce(mf, $vars)) { + for result in parse_for_test($inputs.as_ref(), TEST_ARGS, $stricts, |mf| $type::deduce(mf, &$vars)) { println!("Testing {:?}", result); match result { $pat => assert!(true),