Permalink
Browse files

Fix Unit Tests

  • Loading branch information...
mmstick committed Oct 28, 2017
1 parent 1055e45 commit fd9ce76e1e1e71cd451f3131ebd7c56968338183
Showing with 20 additions and 22 deletions.
  1. +7 −16 src/builtins/exists.rs
  2. +13 −6 src/parser/assignments/actions.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";
@@ -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!(

0 comments on commit fd9ce76

Please sign in to comment.