Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/bashkit/src/builtins/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,5 +248,5 @@ async fn evaluate_binary(left: &str, op: &str, right: &str, fs: &Arc<dyn FileSys
}

fn parse_int(s: &str) -> i64 {
s.parse().unwrap_or(0)
s.trim().parse().unwrap_or(0)
}
24 changes: 24 additions & 0 deletions crates/bashkit/tests/issue_276_test.rs
Original file line number Diff line number Diff line change
@@ -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");
}
Loading