Skip to content

Commit 587752f

Browse files
committed
feat: add --quiet|--failures-only option
1 parent c3e3b70 commit 587752f

9 files changed

+52
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
- Update docs mocks usage
66
- Add support for `.bash` test files
7+
- Add `-q|--quiet|--failures-only` mode
78

89
## [0.22.3](https://github.com/TypedDevs/bashunit/compare/0.22.2...0.22.3) - 2025-07-27
910

bashunit

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ while [[ $# -gt 0 ]]; do
9494
--no-output)
9595
export BASHUNIT_NO_OUTPUT=true
9696
;;
97+
-q|--quiet|--failures-only)
98+
export BASHUNIT_FAILURES_ONLY=true
99+
;;
97100
-vvv|--verbose)
98101
export BASHUNIT_VERBOSE=true
99102
;;

docs/command-line.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,18 @@ Run tests without printing any output. Exit code will be `0` if all tests pass o
352352
```
353353
:::
354354

355+
## Failures only
356+
357+
> `bashunit --failures-only`
358+
359+
Suppress all per-test output. Failures and summary are shown only after all tests finish.
360+
361+
::: code-group
362+
```bash [Example]
363+
./bashunit tests --failures-only
364+
```
365+
:::
366+
355367
## Version
356368

357369
> `bashunit --version`
@@ -442,6 +454,8 @@ Options:
442454
Suppress all console output; rely on exit code.
443455
-s, --simple | --detailed
444456
Choose console output style (default: detailed).
457+
-q, --quiet | --failures-only
458+
Suppress per-test output and show failures at the end.
445459
-S, --stop-on-failure
446460
Stop execution immediately on the first failing test.
447461
--upgrade

docs/configuration.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,20 @@ BASHUNIT_NO_OUTPUT=true
266266
```
267267
:::
268268

269+
## Failures only
270+
271+
> `BASHUNIT_FAILURES_ONLY=true|false`
272+
273+
Suppress all per-test output. Failures and summary are shown only after all tests finish. Defaults to `false`.
274+
275+
Similar as using `--failures-only` option on the [command line](/command-line#failures-only).
276+
277+
::: code-group
278+
```bash [Example]
279+
BASHUNIT_FAILURES_ONLY=true
280+
```
281+
:::
282+
269283
<script setup>
270284
import pkg from '../package.json'
271285
</script>

src/console_header.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ Options:
100100
-s, --simple | --detailed
101101
Choose console output style (default: detailed).
102102
103+
-q, --quiet | --failures-only
104+
Suppress per-test output and show failures at the end.
105+
103106
-S, --stop-on-failure
104107
Stop execution immediately on the first failing test.
105108

src/env.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ _DEFAULT_VERBOSE="false"
3030
_DEFAULT_BENCH_MODE="false"
3131
_DEFAULT_NO_OUTPUT="false"
3232
_DEFAULT_INTERNAL_LOG="false"
33+
_DEFAULT_FAILURES_ONLY="false"
3334

3435
: "${BASHUNIT_PARALLEL_RUN:=${PARALLEL_RUN:=$_DEFAULT_PARALLEL_RUN}}"
3536
: "${BASHUNIT_SHOW_HEADER:=${SHOW_HEADER:=$_DEFAULT_SHOW_HEADER}}"
@@ -41,6 +42,7 @@ _DEFAULT_INTERNAL_LOG="false"
4142
: "${BASHUNIT_BENCH_MODE:=${BENCH_MODE:=$_DEFAULT_BENCH_MODE}}"
4243
: "${BASHUNIT_NO_OUTPUT:=${NO_OUTPUT:=$_DEFAULT_NO_OUTPUT}}"
4344
: "${BASHUNIT_INTERNAL_LOG:=${INTERNAL_LOG:=$_DEFAULT_INTERNAL_LOG}}"
45+
: "${BASHUNIT_FAILURES_ONLY:=${FAILURES_ONLY:=$_DEFAULT_FAILURES_ONLY}}"
4446

4547
function env::is_parallel_run_enabled() {
4648
[[ "$BASHUNIT_PARALLEL_RUN" == "true" ]]
@@ -86,6 +88,10 @@ function env::is_no_output_enabled() {
8688
[[ "$BASHUNIT_NO_OUTPUT" == "true" ]]
8789
}
8890

91+
function env::is_failures_only_enabled() {
92+
[[ "$BASHUNIT_FAILURES_ONLY" == "true" ]]
93+
}
94+
8995
function env::active_internet_connection() {
9096
if [[ "${BASHUNIT_NO_NETWORK:-}" == "true" ]]; then
9197
return 1
@@ -134,6 +140,7 @@ function env::print_verbose() {
134140
"BASHUNIT_STOP_ON_FAILURE"
135141
"BASHUNIT_SHOW_EXECUTION_TIME"
136142
"BASHUNIT_VERBOSE"
143+
"BASHUNIT_FAILURES_ONLY"
137144
)
138145

139146
local max_length=0

src/state.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,10 @@ function state::print_line() {
193193

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

196+
if env::is_failures_only_enabled; then
197+
return
198+
fi
199+
196200
if ! env::is_simple_output_enabled; then
197201
printf "%s\n" "$line"
198202
return

tests/acceptance/snapshots/bashunit_path_test_sh.test_bashunit_without_path_env_nor_argument.snapshot

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ Options:
4343
-s, --simple | --detailed
4444
Choose console output style (default: detailed).
4545

46+
-q, --quiet | --failures-only
47+
Suppress per-test output and show failures at the end.
48+
4649
-S, --stop-on-failure
4750
Stop execution immediately on the first failing test.
4851

tests/acceptance/snapshots/bashunit_test_sh.test_bashunit_should_display_help.snapshot

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ Options:
4242
-s, --simple | --detailed
4343
Choose console output style (default: detailed).
4444

45+
-q, --quiet | --failures-only
46+
Suppress per-test output and show failures at the end.
47+
4548
-S, --stop-on-failure
4649
Stop execution immediately on the first failing test.
4750

0 commit comments

Comments
 (0)