Skip to content

Commit baef9bf

Browse files
committed
Merge branch 'main' into feat/468-bash-support-3.0
Conflicts: CHANGELOG.md src/runner.sh src/test_doubles.sh
2 parents ab46d80 + 58a30d2 commit baef9bf

18 files changed

+185
-23
lines changed

CHANGELOG.md

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,25 @@
22

33
## Unreleased
44

5-
- Add Project-wide `copilot-instructions.md`
6-
- Add `AGENTS.md` for external developer tools integration
7-
- Add two-way synchronization policy between `AGENTS.md` and `copilot-instructions.md` with automatic validation in task templates and PR checklist
8-
- Add tasks storage policy clarifying `.tasks/` (versioned) vs `.task/` (private scratch, git-ignored)
5+
- Add `assert_unsuccessful_code` assertion to check for non-zero exit codes
6+
- Fix bench tests missing test_file var
7+
- Fix compatibility with older python versions for clock::now
8+
- Support Bash 3.0 (Previously 3.2)
9+
10+
## [0.25.0](https://github.com/TypedDevs/bashunit/compare/0.23.0...0.24.0) - 2025-10-05
11+
12+
- Add AI developer tools integration and guidelines
13+
- Add Project-wide `copilot-instructions.md`
14+
- Add `AGENTS.md` for external developer tools integration
15+
- Add tasks storage policy clarifying `.tasks/` (versioned) vs `.task/` (git-ignored)
916
- Include `set_test_title` helper in the single-file library
1017
- Fix lifecycle hooks capture-and-report flow errors
11-
- set_up
12-
- tear_down
13-
- set_up_before_script
14-
- tear_down_after_script
15-
- Support Bash 3.0 (Previously 3.2)
18+
- `set_up`, `tear_down`, `set_up_before_script`, `tear_down_after_script`
19+
- Fix false negative from `assert_have_been_called_with` with pipes
20+
- Fix preservation of trailing whitespace in final argument to `data_set`
21+
- Fix unbound variable error in `parse_data_provider_args` with `set -u`
22+
- Fix wrong assertion_failed name of test on failure
23+
- Fix test name interpolation on failure
1624

1725
## [0.24.0](https://github.com/TypedDevs/bashunit/compare/0.23.0...0.24.0) - 2025-09-14
1826

bashunit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function _check_bash_version() {
2828
_check_bash_version
2929

3030
# shellcheck disable=SC2034
31-
declare -r BASHUNIT_VERSION="0.24.0"
31+
declare -r BASHUNIT_VERSION="0.25.0"
3232

3333
# shellcheck disable=SC2155
3434
declare -r BASHUNIT_ROOT_DIR="$(dirname "${BASH_SOURCE[0]}")"

docs/assertions.md

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ Reports an error if the exit code of `callable` is not equal to `expected`.
333333

334334
If `callable` is not provided, it takes the last executed command or function instead.
335335

336-
[assert_successful_code](#assert-successful-code), [assert_general_error](#assert-general-error) and [assert_command_not_found](#assert-command-not-found)
336+
[assert_successful_code](#assert-successful-code), [assert_unsuccessful_code](#assert-unsuccessful-code), [assert_general_error](#assert-general-error) and [assert_command_not_found](#assert-command-not-found)
337337
are more semantic versions of this assertion, for which you don't need to specify an exit code.
338338
339339
::: code-group
@@ -453,6 +453,45 @@ function test_failure() {
453453
```
454454
:::
455455
456+
## assert_unsuccessful_code
457+
> `assert_unsuccessful_code ["callable"]`
458+
459+
Reports an error if the exit code of `callable` is not unsuccessful (non-zero).
460+
461+
If `callable` is not provided, it takes the last executed command or function instead.
462+
463+
[assert_exit_code](#assert-exit-code) is the full version of this assertion where you can specify the expected exit code.
464+
465+
::: code-group
466+
```bash [Example]
467+
function test_success_with_callable() {
468+
function foo() {
469+
return 1
470+
}
471+
472+
assert_unsuccessful_code "$(foo)"
473+
}
474+
475+
function test_success_without_callable() {
476+
function foo() {
477+
return 2
478+
}
479+
480+
foo # function took instead `callable`
481+
482+
assert_unsuccessful_code
483+
}
484+
485+
function test_failure() {
486+
function foo() {
487+
return 0
488+
}
489+
490+
assert_unsuccessful_code "$(foo)"
491+
}
492+
```
493+
:::
494+
456495
## assert_general_error
457496
> `assert_general_error ["callable"]`
458497

install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ BASHUNIT_GIT_REPO="https://github.com/TypedDevs/bashunit"
9696
if is_git_installed; then
9797
LATEST_BASHUNIT_VERSION="$(get_latest_tag "$BASHUNIT_GIT_REPO")"
9898
else
99-
LATEST_BASHUNIT_VERSION="0.24.0"
99+
LATEST_BASHUNIT_VERSION="0.25.0"
100100
fi
101101
TAG="$LATEST_BASHUNIT_VERSION"
102102

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "bashunit-docs",
3-
"version": "0.24.0",
4-
"checksum": "db65b663556ea1290879f09c653f9ff0e32372e41a4cdc1eb339a294a4095a02",
3+
"version": "0.25.0",
4+
"checksum": "baebbebf93a515f516598b14d5c42d02f4c5bc9933a4c1f59eca36122e109f2d",
55
"description": "Docs for bashunit a simple testing library for bash scripts",
66
"main": "index.js",
77
"repository": "git@github.com:TypedDevs/bashunit.git",

src/assert.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,20 @@ function assert_successful_code() {
380380
state::add_assertions_passed
381381
}
382382

383+
function assert_unsuccessful_code() {
384+
local actual_exit_code=${3-"$?"}
385+
386+
if [[ "$actual_exit_code" -eq 0 ]]; then
387+
local label
388+
label="$(helper::normalize_test_function_name "${FUNCNAME[1]}")"
389+
state::add_assertions_failed
390+
console_results::print_failed_test "${label}" "${actual_exit_code}" "to be non-zero" "but was 0"
391+
return
392+
fi
393+
394+
state::add_assertions_passed
395+
}
396+
383397
function assert_general_error() {
384398
local actual_exit_code=${3-"$?"}
385399
local expected_exit_code=1

src/bashunit.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function bashunit::assertion_failed() {
1010
local failure_condition_message=${3:-"but got "}
1111

1212
local label
13-
label="$(helper::normalize_test_function_name "${FUNCNAME[1]}")"
13+
label="$(helper::normalize_test_function_name "${FUNCNAME[2]}")"
1414
state::add_assertions_failed
1515
console_results::print_failed_test "${label}" "${expected}" \
1616
"$failure_condition_message" "${actual}"

src/clock.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ function clock::now() {
7878
python)
7979
python - <<'EOF'
8080
import time, sys
81-
sys.stdout.write(str(int(time.time() * 1_000_000_000)))
81+
sys.stdout.write(str(int(time.time() * 1000000000)))
8282
EOF
8383
;;
8484
node)

src/globals.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,5 +128,5 @@ function data_set() {
128128
printf ' %q' "$arg"
129129
fi
130130
done
131-
printf '\n'
131+
printf ' %q\n' ""
132132
}

src/helpers.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@ function helper::normalize_test_function_name() {
1818
return
1919
fi
2020

21+
if [[ -z "${interpolated_fn_name-}" && "${original_fn_name}" == *"::"* ]]; then
22+
local state_interpolated_fn_name
23+
state_interpolated_fn_name="$(state::get_current_test_interpolated_function_name)"
24+
25+
if [[ -n "$state_interpolated_fn_name" ]]; then
26+
interpolated_fn_name="$state_interpolated_fn_name"
27+
fi
28+
fi
29+
2130
if [[ -n "${interpolated_fn_name-}" ]]; then
2231
original_fn_name="$interpolated_fn_name"
2332
fi

0 commit comments

Comments
 (0)