Skip to content

Commit 244d35c

Browse files
authored
Merge pull request #551 from TypedDevs/feat/improve-assert-display-result
Improve assert display result
2 parents 393c402 + c984538 commit 244d35c

File tree

5 files changed

+9
-5
lines changed

5 files changed

+9
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
- All `assert_*` functions remain unchanged (public API)
2121

2222
### Fixed
23+
- Improve `assert` command output: show `assert <fn>` instead of internal function name in failure messages
2324
- Custom assertions now display the correct test function name in failure messages
2425
- Data providers now work when `set_up_before_script` changes directory
2526
- Subsequent test files now run when `set_up_before_script` changes directory

docs/standalone.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ The prefix `assert_` is optional.
3737
./bashunit -a not_equals "foo" "foo"
3838
```
3939
```[Output]
40-
✗ Failed: Main::exec not_equals
40+
✗ Failed: assert not_equals
4141
Expected 'foo'
4242
but got 'foo'
4343
```
@@ -88,7 +88,7 @@ This way you can control the FD and redirect the output as you need.
8888
Testing.php:3:Method Testing::bar() has no return type specified.
8989
```
9090
```[/tmp/error.log]
91-
✗ Failed: Main::exec assert
91+
✗ Failed: assert exit_code
9292
Expected '0'
9393
but got '1'
9494
```

src/main.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,9 @@ function bashunit::main::exec_assert() {
496496
assert_fn="assert_same"
497497
fi
498498

499+
# Set a friendly test title for CLI assert command output
500+
bashunit::state::set_test_title "assert ${original_assert_fn#assert_}"
501+
499502
# Run the assertion function and write into stderr
500503
"$assert_fn" "${args[@]}" 1>&2
501504
bashunit_exit_code=$?

tests/acceptance/bashunit_direct_fn_call_test.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ function test_bashunit_assert_exit_code_error_with_inner_func() {
106106
assert_empty "$output"
107107

108108
assert_file_contains "$temp" \
109-
"$(bashunit::console_results::print_failed_test "Main::exec assert" "0" "to be" "1")"
109+
"$(bashunit::console_results::print_failed_test "assert exit_code" "0" "to be" "1")"
110110
}
111111

112112
function test_bashunit_assert_exit_code_str_successful_code() {
@@ -127,7 +127,7 @@ function test_bashunit_assert_exit_code_str_successful_but_exit_code_error() {
127127
assert_same "something to stdout" "$output"
128128

129129
assert_file_contains "$temp" \
130-
"$(bashunit::console_results::print_failed_test "Main::exec assert" "1" "but got " "0")"
130+
"$(bashunit::console_results::print_failed_test "assert exit_code" "1" "but got " "0")"
131131
}
132132

133133
# shellcheck disable=SC2155
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
✗ Failed: Bashunit::main::exec assert
1+
✗ Failed: assert same
22
Expected 'foo'
33
but got  'bar'

0 commit comments

Comments
 (0)