Skip to content
Draft
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- Update docs mocks usage
- Add support for `.bash` test files
- Add `-q|--quiet|--failures-only` mode
- Add runtime check for Bash >= 3.2

## [0.22.3](https://github.com/TypedDevs/bashunit/compare/0.22.2...0.22.3) - 2025-07-27
Expand Down
3 changes: 3 additions & 0 deletions bashunit
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ while [[ $# -gt 0 ]]; do
--no-output)
export BASHUNIT_NO_OUTPUT=true
;;
-q|--quiet|--failures-only)
export BASHUNIT_FAILURES_ONLY=true
;;
-vvv|--verbose)
export BASHUNIT_VERBOSE=true
;;
Expand Down
14 changes: 14 additions & 0 deletions docs/command-line.md
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,18 @@ Run tests without printing any output. Exit code will be `0` if all tests pass o
```
:::

## Failures only

> `bashunit --failures-only`

Suppress all per-test output. Failures and summary are shown only after all tests finish.

::: code-group
```bash [Example]
./bashunit tests --failures-only
```
:::

## Version

> `bashunit --version`
Expand Down Expand Up @@ -442,6 +454,8 @@ Options:
Suppress all console output; rely on exit code.
-s, --simple | --detailed
Choose console output style (default: detailed).
-q, --quiet | --failures-only
Suppress per-test output and show failures at the end.
-S, --stop-on-failure
Stop execution immediately on the first failing test.
--upgrade
Expand Down
14 changes: 14 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,20 @@ BASHUNIT_NO_OUTPUT=true
```
:::

## Failures only

> `BASHUNIT_FAILURES_ONLY=true|false`

Suppress all per-test output. Failures and summary are shown only after all tests finish. Defaults to `false`.

Similar as using `--failures-only` option on the [command line](/command-line#failures-only).

::: code-group
```bash [Example]
BASHUNIT_FAILURES_ONLY=true
```
:::

<script setup>
import pkg from '../package.json'
</script>
3 changes: 3 additions & 0 deletions src/console_header.sh
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ Options:
-s, --simple | --detailed
Choose console output style (default: detailed).

-q, --quiet | --failures-only
Suppress per-test output and show failures at the end.

-S, --stop-on-failure
Stop execution immediately on the first failing test.

Expand Down
7 changes: 7 additions & 0 deletions src/env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ _DEFAULT_VERBOSE="false"
_DEFAULT_BENCH_MODE="false"
_DEFAULT_NO_OUTPUT="false"
_DEFAULT_INTERNAL_LOG="false"
_DEFAULT_FAILURES_ONLY="false"

: "${BASHUNIT_PARALLEL_RUN:=${PARALLEL_RUN:=$_DEFAULT_PARALLEL_RUN}}"
: "${BASHUNIT_SHOW_HEADER:=${SHOW_HEADER:=$_DEFAULT_SHOW_HEADER}}"
Expand All @@ -41,6 +42,7 @@ _DEFAULT_INTERNAL_LOG="false"
: "${BASHUNIT_BENCH_MODE:=${BENCH_MODE:=$_DEFAULT_BENCH_MODE}}"
: "${BASHUNIT_NO_OUTPUT:=${NO_OUTPUT:=$_DEFAULT_NO_OUTPUT}}"
: "${BASHUNIT_INTERNAL_LOG:=${INTERNAL_LOG:=$_DEFAULT_INTERNAL_LOG}}"
: "${BASHUNIT_FAILURES_ONLY:=${FAILURES_ONLY:=$_DEFAULT_FAILURES_ONLY}}"

function env::is_parallel_run_enabled() {
[[ "$BASHUNIT_PARALLEL_RUN" == "true" ]]
Expand Down Expand Up @@ -86,6 +88,10 @@ function env::is_no_output_enabled() {
[[ "$BASHUNIT_NO_OUTPUT" == "true" ]]
}

function env::is_failures_only_enabled() {
[[ "$BASHUNIT_FAILURES_ONLY" == "true" ]]
}

function env::active_internet_connection() {
if [[ "${BASHUNIT_NO_NETWORK:-}" == "true" ]]; then
return 1
Expand Down Expand Up @@ -134,6 +140,7 @@ function env::print_verbose() {
"BASHUNIT_STOP_ON_FAILURE"
"BASHUNIT_SHOW_EXECUTION_TIME"
"BASHUNIT_VERBOSE"
"BASHUNIT_FAILURES_ONLY"
)

local max_length=0
Expand Down
12 changes: 8 additions & 4 deletions src/runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ function runner::call_test_functions() {
unset fn_name
done

if ! env::is_simple_output_enabled; then
if ! env::is_simple_output_enabled && ! env::is_failures_only_enabled; then
echo ""
fi
}
Expand Down Expand Up @@ -155,7 +155,7 @@ function runner::call_bench_functions() {
unset fn_name
done

if ! env::is_simple_output_enabled; then
if ! env::is_simple_output_enabled && ! env::is_failures_only_enabled; then
echo ""
fi
}
Expand All @@ -165,7 +165,7 @@ function runner::render_running_file_header() {

internal_log "Running file" "$script"

if parallel::is_enabled; then
if parallel::is_enabled || env::is_failures_only_enabled; then
return
fi

Expand Down Expand Up @@ -227,8 +227,12 @@ function runner::run_test() {

# 2>&1: Redirects the std-error (FD 2) to the std-output (FD 1).
# points to the original std-output.
local failures_only_backup="$BASHUNIT_FAILURES_ONLY"
export BASHUNIT_FAILURES_ONLY=false
"$fn_name" "$@" 2>&1

local exit_code=$?
export BASHUNIT_FAILURES_ONLY="$failures_only_backup"
exit "$exit_code"
)

# Closes FD 3, which was used temporarily to hold the original stdout.
Expand Down
4 changes: 4 additions & 0 deletions src/state.sh
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ function state::print_line() {

state::add_test_output "[$type]$line"

if env::is_failures_only_enabled; then
return
fi

if ! env::is_simple_output_enabled; then
printf "%s\n" "$line"
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ Options:
-s, --simple | --detailed
Choose console output style (default: detailed).

-q, --quiet | --failures-only
Suppress per-test output and show failures at the end.

-S, --stop-on-failure
Stop execution immediately on the first failing test.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ Options:
-s, --simple | --detailed
Choose console output style (default: detailed).

-q, --quiet | --failures-only
Suppress per-test output and show failures at the end.

-S, --stop-on-failure
Stop execution immediately on the first failing test.

Expand Down
Loading