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"); +}