completely rewrote test suite for top level src files and all builtin files
This commit is contained in:
@@ -35,3 +35,53 @@ pub fn shift(node: Node) -> ShResult<()> {
|
||||
state::set_status(0);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::state;
|
||||
use crate::testutil::{TestGuard, test_input};
|
||||
|
||||
#[test]
|
||||
fn shift_in_function() {
|
||||
let guard = TestGuard::new();
|
||||
test_input("f() { echo $1; shift 1; echo $1; }").unwrap();
|
||||
test_input("f a b").unwrap();
|
||||
let out = guard.read_output();
|
||||
let lines: Vec<&str> = out.lines().collect();
|
||||
assert_eq!(lines[0], "a");
|
||||
assert_eq!(lines[1], "b");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn shift_multiple() {
|
||||
let guard = TestGuard::new();
|
||||
test_input("f() { shift 2; echo $1; }").unwrap();
|
||||
test_input("f a b c").unwrap();
|
||||
let out = guard.read_output();
|
||||
assert_eq!(out.trim(), "c");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn shift_all_params() {
|
||||
let guard = TestGuard::new();
|
||||
test_input("f() { shift 3; echo \"[$1]\"; }").unwrap();
|
||||
test_input("f a b c").unwrap();
|
||||
let out = guard.read_output();
|
||||
assert_eq!(out.trim(), "[]");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn shift_non_numeric_fails() {
|
||||
let _g = TestGuard::new();
|
||||
let result = test_input("shift abc");
|
||||
assert!(result.is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn shift_status_zero() {
|
||||
let _g = TestGuard::new();
|
||||
test_input("f() { shift 1; }").unwrap();
|
||||
test_input("f a b").unwrap();
|
||||
assert_eq!(state::get_status(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user