mirror of
https://github.com/Llewellynvdm/exa.git
synced 2024-12-30 19:39:09 +00:00
env vars should be referenced, not copied
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.
This commit is contained in:
parent
33e83accd0
commit
6740faa781
@ -69,7 +69,7 @@ impl Vars for LiveVars {
|
|||||||
impl<'args, 'w, W: Write + 'w> Exa<'args, 'w, W> {
|
impl<'args, 'w, W: Write + 'w> Exa<'args, 'w, W> {
|
||||||
pub fn new<I>(args: I, writer: &'w mut W) -> Result<Exa<'args, 'w, W>, Misfire>
|
pub fn new<I>(args: I, writer: &'w mut W) -> Result<Exa<'args, 'w, W>, Misfire>
|
||||||
where I: Iterator<Item=&'args OsString> {
|
where I: Iterator<Item=&'args OsString> {
|
||||||
Options::parse(args, LiveVars).map(move |(options, args)| {
|
Options::parse(args, &LiveVars).map(move |(options, args)| {
|
||||||
Exa { options, writer, args }
|
Exa { options, writer, args }
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -130,21 +130,21 @@ mod test {
|
|||||||
#[test]
|
#[test]
|
||||||
fn help() {
|
fn help() {
|
||||||
let args = [ os("--help") ];
|
let args = [ os("--help") ];
|
||||||
let opts = Options::parse(&args, None);
|
let opts = Options::parse(&args, &None);
|
||||||
assert!(opts.is_err())
|
assert!(opts.is_err())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn help_with_file() {
|
fn help_with_file() {
|
||||||
let args = [ os("--help"), os("me") ];
|
let args = [ os("--help"), os("me") ];
|
||||||
let opts = Options::parse(&args, None);
|
let opts = Options::parse(&args, &None);
|
||||||
assert!(opts.is_err())
|
assert!(opts.is_err())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn unhelpful() {
|
fn unhelpful() {
|
||||||
let args = [];
|
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
|
assert!(opts.is_ok()) // no help when --help isn’t passed
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -115,7 +115,7 @@ impl Options {
|
|||||||
/// struct and a list of free filenames, using the environment variables
|
/// struct and a list of free filenames, using the environment variables
|
||||||
/// for extra options.
|
/// for extra options.
|
||||||
#[allow(unused_results)]
|
#[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<Item=&'args OsString>,
|
where I: IntoIterator<Item=&'args OsString>,
|
||||||
V: Vars {
|
V: Vars {
|
||||||
use options::parser::{Matches, Strictness};
|
use options::parser::{Matches, Strictness};
|
||||||
@ -151,7 +151,7 @@ impl Options {
|
|||||||
|
|
||||||
/// Determines the complete set of options based on the given command-line
|
/// Determines the complete set of options based on the given command-line
|
||||||
/// arguments, after they’ve been parsed.
|
/// arguments, after they’ve been parsed.
|
||||||
fn deduce<V: Vars>(matches: &MatchedFlags, vars: V) -> Result<Options, Misfire> {
|
fn deduce<V: Vars>(matches: &MatchedFlags, vars: &V) -> Result<Options, Misfire> {
|
||||||
let dir_action = DirAction::deduce(matches)?;
|
let dir_action = DirAction::deduce(matches)?;
|
||||||
let filter = FileFilter::deduce(matches)?;
|
let filter = FileFilter::deduce(matches)?;
|
||||||
let view = View::deduce(matches, vars)?;
|
let view = View::deduce(matches, vars)?;
|
||||||
@ -230,28 +230,28 @@ pub mod test {
|
|||||||
#[test]
|
#[test]
|
||||||
fn files() {
|
fn files() {
|
||||||
let args = [ os("this file"), os("that file") ];
|
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") ])
|
assert_eq!(outs, vec![ &os("this file"), &os("that file") ])
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn no_args() {
|
fn no_args() {
|
||||||
let nothing: Vec<OsString> = Vec::new();
|
let nothing: Vec<OsString> = 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
|
assert!(outs.is_empty()); // Listing the `.` directory is done in main.rs
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn long_across() {
|
fn long_across() {
|
||||||
let args = [ os("--long"), os("--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))
|
assert_eq!(opts.unwrap_err(), Misfire::Useless(&flags::ACROSS, true, &flags::LONG))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn oneline_across() {
|
fn oneline_across() {
|
||||||
let args = [ os("--oneline"), os("--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))
|
assert_eq!(opts.unwrap_err(), Misfire::Useless(&flags::ACROSS, true, &flags::ONE_LINE))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,7 @@ mod test {
|
|||||||
#[test]
|
#[test]
|
||||||
fn help() {
|
fn help() {
|
||||||
let args = [ os("--version") ];
|
let args = [ os("--version") ];
|
||||||
let opts = Options::parse(&args, None);
|
let opts = Options::parse(&args, &None);
|
||||||
assert!(opts.is_err())
|
assert!(opts.is_err())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ use info::filetype::FileExtensions;
|
|||||||
impl View {
|
impl View {
|
||||||
|
|
||||||
/// Determine which view to use and all of that view’s arguments.
|
/// Determine which view to use and all of that view’s arguments.
|
||||||
pub fn deduce<V: Vars>(matches: &MatchedFlags, vars: V) -> Result<View, Misfire> {
|
pub fn deduce<V: Vars>(matches: &MatchedFlags, vars: &V) -> Result<View, Misfire> {
|
||||||
let mode = Mode::deduce(matches, vars)?;
|
let mode = Mode::deduce(matches, vars)?;
|
||||||
let colours = Colours::deduce(matches)?;
|
let colours = Colours::deduce(matches)?;
|
||||||
let style = FileStyle::deduce(matches)?;
|
let style = FileStyle::deduce(matches)?;
|
||||||
@ -25,7 +25,7 @@ impl View {
|
|||||||
impl Mode {
|
impl Mode {
|
||||||
|
|
||||||
/// Determine the mode from the command-line arguments.
|
/// Determine the mode from the command-line arguments.
|
||||||
pub fn deduce<V: Vars>(matches: &MatchedFlags, vars: V) -> Result<Mode, Misfire> {
|
pub fn deduce<V: Vars>(matches: &MatchedFlags, vars: &V) -> Result<Mode, Misfire> {
|
||||||
use options::misfire::Misfire::*;
|
use options::misfire::Misfire::*;
|
||||||
|
|
||||||
let long = || {
|
let long = || {
|
||||||
@ -97,7 +97,7 @@ impl Mode {
|
|||||||
if matches.has(&flags::GRID)? {
|
if matches.has(&flags::GRID)? {
|
||||||
let other_options_mode = other_options_scan()?;
|
let other_options_mode = other_options_scan()?;
|
||||||
if let Mode::Grid(grid) = other_options_mode {
|
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 }));
|
return Ok(Mode::GridDetails(grid_details::Options { grid, details, row_threshold }));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -153,7 +153,7 @@ impl TerminalWidth {
|
|||||||
/// Determine a requested terminal width from the command-line arguments.
|
/// Determine a requested terminal width from the command-line arguments.
|
||||||
///
|
///
|
||||||
/// Returns an error if a requested width doesn’t parse to an integer.
|
/// Returns an error if a requested width doesn’t parse to an integer.
|
||||||
fn deduce<V: Vars>(vars: V) -> Result<TerminalWidth, Misfire> {
|
fn deduce<V: Vars>(vars: &V) -> Result<TerminalWidth, Misfire> {
|
||||||
if let Some(columns) = vars.get("COLUMNS").and_then(|s| s.into_string().ok()) {
|
if let Some(columns) = vars.get("COLUMNS").and_then(|s| s.into_string().ok()) {
|
||||||
match columns.parse() {
|
match columns.parse() {
|
||||||
Ok(width) => Ok(TerminalWidth::Set(width)),
|
Ok(width) => Ok(TerminalWidth::Set(width)),
|
||||||
@ -482,7 +482,7 @@ mod test {
|
|||||||
/// Like above, but with $vars.
|
/// Like above, but with $vars.
|
||||||
#[test]
|
#[test]
|
||||||
fn $name() {
|
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);
|
assert_eq!(result.unwrap_err(), $result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -492,7 +492,7 @@ mod test {
|
|||||||
/// Like further above, but with $vars.
|
/// Like further above, but with $vars.
|
||||||
#[test]
|
#[test]
|
||||||
fn $name() {
|
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);
|
println!("Testing {:?}", result);
|
||||||
match result {
|
match result {
|
||||||
$pat => assert!(true),
|
$pat => assert!(true),
|
||||||
|
Loading…
Reference in New Issue
Block a user