diff options
author | Dan Davison <dandavison7@gmail.com> | 2020-06-10 16:28:52 -0400 |
---|---|---|
committer | Dan Davison <dandavison7@gmail.com> | 2020-06-10 17:25:44 -0400 |
commit | 2b8869cf16dd15469753849fae2fb3c26e82bbcf (patch) | |
tree | 6b242891e982410fcf5504e5891e0611b71abf60 /src/tests/integration_test_utils.rs | |
parent | 39b4d39d7f2b3c07e316ea8640640602d2115d14 (diff) |
Refactor: straighten out command line arguments processing
Diffstat (limited to 'src/tests/integration_test_utils.rs')
-rw-r--r-- | src/tests/integration_test_utils.rs | 38 |
1 files changed, 22 insertions, 16 deletions
diff --git a/src/tests/integration_test_utils.rs b/src/tests/integration_test_utils.rs index e67038c8..5d9be02b 100644 --- a/src/tests/integration_test_utils.rs +++ b/src/tests/integration_test_utils.rs @@ -1,47 +1,53 @@ #[cfg(test)] pub mod integration_test_utils { - use std::ffi::OsString; use std::io::BufReader; use bytelines::ByteLines; use console::strip_ansi_codes; - use structopt::{clap, StructOpt}; + use structopt::StructOpt; use crate::cli; use crate::config; use crate::delta::delta; - pub fn get_command_line_options() -> cli::Opt { - let mut opt = cli::Opt::from_iter(Vec::<OsString>::new()); - opt.syntax_theme = None; // TODO: Why does opt.syntax_theme have the value Some("")? - opt.no_gitconfig = true; - opt + pub fn get_config_from_args<'a>(_args: &[&str]) -> config::Config<'a> { + // FIXME: should not be necessary + let (dummy_minus_file, dummy_plus_file) = ("/dev/null", "/dev/null"); + let mut args = vec![dummy_minus_file, dummy_plus_file]; + + for arg in _args { + args.push(arg); + } + args.push("--no-gitconfig"); + let arg_matches = cli::Opt::clap().get_matches_from(args); + cli::process_command_line_arguments(arg_matches, &mut None) + } + + pub fn get_config<'a>() -> config::Config<'a> { + get_config_from_args(&vec![][0..]) } pub fn get_line_of_code_from_delta<'a>( input: &str, line_number: usize, expected_text: &str, - options: cli::Opt, - ) -> (String, config::Config<'a>) { - let (output, config) = run_delta(&input, options); + config: &config::Config<'a>, + ) -> String { + let output = run_delta(&input, config); let line_of_code = output.lines().nth(line_number).unwrap(); assert!(strip_ansi_codes(line_of_code) == expected_text); - (line_of_code.to_string(), config) + line_of_code.to_string() } - pub fn run_delta<'a>(input: &str, options: cli::Opt) -> (String, config::Config<'a>) { + pub fn run_delta<'a>(input: &str, config: &config::Config<'a>) -> String { let mut writer: Vec<u8> = Vec::new(); - let config = - cli::process_command_line_arguments(options, clap::ArgMatches::new(), &mut None); - delta( ByteLines::new(BufReader::new(input.as_bytes())), &mut writer, &config, ) .unwrap(); - (String::from_utf8(writer).unwrap(), config) + String::from_utf8(writer).unwrap() } } |