From 9dc8c746e17475038dc64830f0ebf6bc47a3c8e2 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 26 Feb 2026 15:24:36 +0000 Subject: [PATCH] fix(test): trim whitespace in parse_int for integer comparisons Closes #276 --- crates/bashkit/src/builtins/test.rs | 2 +- crates/bashkit/tests/issue_276_test.rs | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 crates/bashkit/tests/issue_276_test.rs diff --git a/crates/bashkit/src/builtins/test.rs b/crates/bashkit/src/builtins/test.rs index 423a119d..5d7d2d2e 100644 --- a/crates/bashkit/src/builtins/test.rs +++ b/crates/bashkit/src/builtins/test.rs @@ -248,5 +248,5 @@ async fn evaluate_binary(left: &str, op: &str, right: &str, fs: &Arc i64 { - s.parse().unwrap_or(0) + s.trim().parse().unwrap_or(0) } diff --git a/crates/bashkit/tests/issue_276_test.rs b/crates/bashkit/tests/issue_276_test.rs new file mode 100644 index 00000000..a828ce24 --- /dev/null +++ b/crates/bashkit/tests/issue_276_test.rs @@ -0,0 +1,24 @@ +//! Regression test for #276: parse_int doesn't trim whitespace + +use bashkit::Bash; + +#[tokio::test] +async fn issue_276_parse_int_trims_whitespace() { + let mut bash = Bash::new(); + // wc pads output with spaces; integer comparison must still work + let r = bash + .exec(r#"[ " 3 " -ge 2 ] && echo yes || echo no"#) + .await + .unwrap(); + assert_eq!(r.stdout.trim(), "yes"); +} + +#[tokio::test] +async fn issue_276_wc_output_in_comparison() { + let mut bash = Bash::new(); + let r = bash + .exec(r#"count=$(echo -e "a\nb\nc" | wc -l); [ "$count" -ge 2 ] && echo has || echo no"#) + .await + .unwrap(); + assert_eq!(r.stdout.trim(), "has"); +}