From fd9ce76e1e1e71cd451f3131ebd7c56968338183 Mon Sep 17 00:00:00 2001 From: Michael Aaron Murphy <mmstickman@gmail.com> Date: Sat, 28 Oct 2017 13:52:39 -0400 Subject: [PATCH] Fix Unit Tests --- src/builtins/exists.rs | 23 +++++++---------------- src/parser/assignments/actions.rs | 19 +++++++++++++------ 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/src/builtins/exists.rs b/src/builtins/exists.rs index 17bcd280..1a16706c 100644 --- a/src/builtins/exists.rs +++ b/src/builtins/exists.rs @@ -7,8 +7,6 @@ use std::fs; use std::io::{self, BufWriter}; use std::os::unix::fs::PermissionsExt; -#[cfg(test)] -use builtins::Builtin; use shell::Shell; #[cfg(test)] use shell::flow_control::{Function, Statement}; @@ -216,8 +214,7 @@ fn function_is_defined(function: &str, shell: &Shell) -> bool { #[test] fn test_evaluate_arguments() { use parser::assignments::{KeyBuf, Primitive}; - let builtins = Builtin::map(); - let mut shell = Shell::new(&builtins); + let mut shell = Shell::new(); let mut sink = BufWriter::new(io::sink()); // assert_eq!(evaluate_arguments(&[], &mut sink, &shell), Ok(false)); @@ -319,8 +316,7 @@ fn test_evaluate_arguments() { #[test] fn test_match_flag_argument() { - let builtins = Builtin::map(); - let shell = Shell::new(&builtins); + let shell = Shell::new(); // we don't really care about the passed values, as long as both sited return the same value assert_eq!(match_flag_argument('a', "ARRAY", &shell), array_var_is_not_empty("ARRAY", &shell)); @@ -335,8 +331,7 @@ fn test_match_flag_argument() { #[test] fn test_match_option_argument() { - let builtins = Builtin::map(); - let shell = Shell::new(&builtins); + let shell = Shell::new(); // we don't really care about the passed values, as long as both sited return the same value assert_eq!(match_option_argument("fn", "FUN", &shell), array_var_is_not_empty("FUN", &shell)); @@ -359,8 +354,7 @@ fn test_path_is_directory() { #[test] fn test_binary_is_in_path() { - let builtins = Builtin::map(); - let mut shell = Shell::new(&builtins); + let mut shell = Shell::new(); // TODO: We should probably also test with more complex PATH-variables: // TODO: multiple/:directories/ @@ -391,8 +385,7 @@ fn test_string_is_nonzero() { #[test] fn test_array_var_is_not_empty() { - let builtins = Builtin::map(); - let mut shell = Shell::new(&builtins); + let mut shell = Shell::new(); shell.variables.set_array("EMPTY_ARRAY", SmallVec::from_vec(Vec::new())); assert_eq!(array_var_is_not_empty("EMPTY_ARRAY", &shell), false); @@ -413,8 +406,7 @@ fn test_array_var_is_not_empty() { #[test] fn test_string_var_is_not_empty() { - let builtins = Builtin::map(); - let mut shell = Shell::new(&builtins); + let mut shell = Shell::new(); shell.variables.set_var("EMPTY", ""); assert_eq!(string_var_is_not_empty("EMPTY", &shell), false); @@ -436,8 +428,7 @@ fn test_string_var_is_not_empty() { #[test] fn test_function_is_defined() { use parser::assignments::{KeyBuf, Primitive}; - let builtins = Builtin::map(); - let mut shell = Shell::new(&builtins); + let mut shell = Shell::new(); // create a simple dummy function let name_str = "test_function"; diff --git a/src/parser/assignments/actions.rs b/src/parser/assignments/actions.rs index 4c0eb75f..3793ab79 100644 --- a/src/parser/assignments/actions.rs +++ b/src/parser/assignments/actions.rs @@ -116,9 +116,15 @@ impl<'a> Action<'a> { mod tests { use super::*; + fn split(input: &str) -> (String, Operator, String) { + let (keys, op, vals) = split_assignment(input); + (keys.unwrap().into(), Operator::parse(op.unwrap()).unwrap(), vals.unwrap().into()) + } + #[test] fn assignment_actions() { - let actions = AssignmentActions::new("abc def = 123 456").unwrap().collect::<Vec<_>>(); + let (keys, op, vals) = split("abc def = 123 456"); + let actions = AssignmentActions::new(&keys, op, &vals).collect::<Vec<_>>(); assert_eq!(actions.len(), 2); assert_eq!( actions[0], @@ -143,7 +149,8 @@ mod tests { ),) ); - let actions = AssignmentActions::new("ab:int *= 3").unwrap().collect::<Vec<_>>(); + let (keys, op, vals) = split("ab:int *= 3"); + let actions = AssignmentActions::new(&keys, op, &vals).collect::<Vec<_>>(); assert_eq!(actions.len(), 1); assert_eq!( actions[0], @@ -157,8 +164,8 @@ mod tests { ),) ); - let actions = AssignmentActions::new("a b[] c:int[] = one [two three] [4 5 6]") - .unwrap() + let (keys, op, vals) = split("a b[] c:int[] = one [two three] [4 5 6]"); + let actions = AssignmentActions::new(&keys, op, &vals) .collect::<Vec<_>>(); assert_eq!(actions.len(), 3); assert_eq!( @@ -195,8 +202,8 @@ mod tests { ),) ); - let actions = AssignmentActions::new("a[] b c[] = [one two] three [four five]") - .unwrap() + let (keys, op, values) = split("a[] b c[] = [one two] three [four five]"); + let actions = AssignmentActions::new(&keys, op, &values) .collect::<Vec<_>>(); assert_eq!(actions.len(), 3); assert_eq!( -- GitLab