completely rewrote test suite for top level src files and all builtin files

This commit is contained in:
2026-03-06 23:42:14 -05:00
parent 42b4120055
commit b137c38e92
44 changed files with 5909 additions and 582 deletions

View File

@@ -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);
}
}