Skip to content

Commit aa446a0

Browse files
authored
fix(assert): reject empty bool assertions (#640)
1 parent 15aa158 commit aa446a0

3 files changed

Lines changed: 23 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
- `clock::now` handles `EPOCHREALTIME` values that use a comma decimal separator
2222
- Invalid `.env.example` coverage threshold entry; CI now copies `.env.example` to `.env` so config parse errors are caught
2323
- Coverage no longer counts case patterns with trailing comments (e.g. `*thing) # note`) or loop terminators with redirections/pipes (e.g. `done < file`, `done <<<"$var"`, `done | sort`) as executable lines (#634)
24+
- `assert_true` and `assert_false` now report empty strings as assertion failures instead of trying to execute them
2425

2526
## [0.34.1](https://github.com/TypedDevs/bashunit/compare/0.34.0...0.34.1) - 2026-03-20
2627

src/assert.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ function assert_true() {
4343

4444
# Check for expected literal values first
4545
case "$actual" in
46+
"")
47+
bashunit::handle_bool_assertion_failure "true or 0" "$actual"
48+
return
49+
;;
4650
"true" | "0")
4751
bashunit::state::add_assertions_passed
4852
return
@@ -71,6 +75,10 @@ function assert_false() {
7175

7276
# Check for expected literal values first
7377
case "$actual" in
78+
"")
79+
bashunit::handle_bool_assertion_failure "false or 1" "$actual"
80+
return
81+
;;
7482
"false" | "1")
7583
bashunit::state::add_assertions_passed
7684
return

tests/unit/assert_basic_test.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ function test_unsuccessful_assert_true() {
3232
"$(assert_true false)"
3333
}
3434

35+
function test_unsuccessful_assert_true_with_empty_value() {
36+
assert_same "$(bashunit::console_results::print_failed_test "Unsuccessful assert true with empty value" \
37+
"true or 0" \
38+
"but got " "")" \
39+
"$(assert_true "")"
40+
}
41+
3542
function test_successful_assert_true_on_function() {
3643
assert_empty "$(assert_true ls)"
3744
}
@@ -62,6 +69,13 @@ function test_unsuccessful_assert_false() {
6269
"$(assert_false true)"
6370
}
6471

72+
function test_unsuccessful_assert_false_with_empty_value() {
73+
assert_same "$(bashunit::console_results::print_failed_test "Unsuccessful assert false with empty value" \
74+
"false or 1" \
75+
"but got " "")" \
76+
"$(assert_false "")"
77+
}
78+
6579
function test_successful_assert_false_on_function() {
6680
assert_empty "$(assert_false "eval return 1")"
6781
}

0 commit comments

Comments
 (0)