diff --git a/CHANGELOG.md b/CHANGELOG.md index dc902a86..16b0ebf9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,11 @@ - Helps debug test failures without manually capturing output - Enabled by default; use `--no-output-on-failure` or `BASHUNIT_SHOW_OUTPUT_ON_FAILURE=false` to disable - New CLI options: `--show-output`, `--no-output-on-failure` +- Add `--no-progress` flag to suppress real-time progress display (Issue #503) + - Hides per-test output, file headers, hook messages, and spinner during execution + - Shows only the final test summary + - Useful for CI/CD pipelines or log-restricted environments + - Can also be set via `BASHUNIT_NO_PROGRESS=true` environment variable ## [0.32.0](https://github.com/TypedDevs/bashunit/compare/0.31.0...0.32.0) - 2026-01-12 diff --git a/docs/command-line.md b/docs/command-line.md index 99c866e5..04a4ecaf 100644 --- a/docs/command-line.md +++ b/docs/command-line.md @@ -69,6 +69,7 @@ bashunit test tests/ --parallel --simple | `--debug [file]` | Enable shell debug mode | | `--no-output` | Suppress all output | | `--failures-only` | Only show failures | +| `--no-progress` | Suppress real-time progress, show only summary | | `--show-output` | Show test output on failure (default) | | `--no-output-on-failure` | Hide test output on failure | | `--strict` | Enable strict shell mode | @@ -260,6 +261,39 @@ bashunit test tests/ --no-output-on-failure ``` ::: +### No Progress + +> `bashunit test --no-progress` + +Suppress real-time progress display during test execution, showing only the final summary. + +When enabled, bashunit hides: +- Per-test output (pass/fail messages or dots) +- File headers ("Running tests/...") +- Hook completion messages +- Spinner during parallel execution + +The final summary with test counts and results is still displayed. + +This is useful for: +- CI/CD pipelines where streaming output causes issues +- Log-restricted environments +- Reducing output noise when only the final result matters + +::: code-group +```bash [Example] +bashunit test tests/ --no-progress +``` +```[Output] +bashunit - 0.32.0 | Tests: 10 +Tests: 10 passed, 10 total +Assertions: 25 passed, 25 total + + All tests passed +Time taken: 1.23s +``` +::: + ### Strict Mode > `bashunit test --strict` diff --git a/docs/configuration.md b/docs/configuration.md index 19b686ab..7cebab4f 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -347,6 +347,23 @@ BASHUNIT_FAILURES_ONLY=true ``` ::: +## No progress + +> `BASHUNIT_NO_PROGRESS=true|false` + +Suppress real-time progress display during test execution. `false` by default. + +When enabled, bashunit hides per-test output, file headers, hook messages, and spinners, +showing only the final summary. Useful for CI/CD pipelines or log-restricted environments. + +Similar as using `--no-progress` option on the [command line](/command-line#no-progress). + +::: code-group +```bash [Example] +BASHUNIT_NO_PROGRESS=true +``` +::: + ## Show output on failure > `BASHUNIT_SHOW_OUTPUT_ON_FAILURE=true|false` diff --git a/src/console_header.sh b/src/console_header.sh index bc5467a3..cc486935 100644 --- a/src/console_header.sh +++ b/src/console_header.sh @@ -117,6 +117,7 @@ Options: --debug [file] Enable shell debug mode --no-output Suppress all output --failures-only Only show failures (suppress passed/skipped/incomplete) + --no-progress Suppress real-time progress, show only final results --show-output Show test output on failure (default: enabled) --no-output-on-failure Hide test output on failure --strict Enable strict shell mode (set -euo pipefail) diff --git a/src/console_results.sh b/src/console_results.sh index c768d477..143ccbfd 100644 --- a/src/console_results.sh +++ b/src/console_results.sh @@ -172,6 +172,10 @@ function bashunit::console_results::print_hook_completed() { return fi + if bashunit::env::is_no_progress_enabled; then + return + fi + if bashunit::parallel::is_enabled; then return fi diff --git a/src/env.sh b/src/env.sh index 08e77864..aed4a663 100644 --- a/src/env.sh +++ b/src/env.sh @@ -63,6 +63,7 @@ _BASHUNIT_DEFAULT_LOGIN_SHELL="false" _BASHUNIT_DEFAULT_FAILURES_ONLY="false" _BASHUNIT_DEFAULT_NO_COLOR="false" _BASHUNIT_DEFAULT_SHOW_OUTPUT_ON_FAILURE="true" +_BASHUNIT_DEFAULT_NO_PROGRESS="false" : "${BASHUNIT_PARALLEL_RUN:=${PARALLEL_RUN:=$_BASHUNIT_DEFAULT_PARALLEL_RUN}}" : "${BASHUNIT_SHOW_HEADER:=${SHOW_HEADER:=$_BASHUNIT_DEFAULT_SHOW_HEADER}}" @@ -82,6 +83,7 @@ _BASHUNIT_DEFAULT_SHOW_OUTPUT_ON_FAILURE="true" : "${BASHUNIT_LOGIN_SHELL:=${LOGIN_SHELL:=$_BASHUNIT_DEFAULT_LOGIN_SHELL}}" : "${BASHUNIT_FAILURES_ONLY:=${FAILURES_ONLY:=$_BASHUNIT_DEFAULT_FAILURES_ONLY}}" : "${BASHUNIT_SHOW_OUTPUT_ON_FAILURE:=${SHOW_OUTPUT_ON_FAILURE:=$_BASHUNIT_DEFAULT_SHOW_OUTPUT_ON_FAILURE}}" +: "${BASHUNIT_NO_PROGRESS:=${NO_PROGRESS:=$_BASHUNIT_DEFAULT_NO_PROGRESS}}" # Support NO_COLOR standard (https://no-color.org) if [[ -n "${NO_COLOR:-}" ]]; then BASHUNIT_NO_COLOR="true" @@ -165,6 +167,10 @@ function bashunit::env::is_show_output_on_failure_enabled() { [[ "$BASHUNIT_SHOW_OUTPUT_ON_FAILURE" == "true" ]] } +function bashunit::env::is_no_progress_enabled() { + [[ "$BASHUNIT_NO_PROGRESS" == "true" ]] +} + function bashunit::env::is_no_color_enabled() { [[ "$BASHUNIT_NO_COLOR" == "true" ]] } diff --git a/src/main.sh b/src/main.sh index 83f6e2d4..fd06a834 100644 --- a/src/main.sh +++ b/src/main.sh @@ -88,6 +88,9 @@ function bashunit::main::cmd_test() { --no-output-on-failure) export BASHUNIT_SHOW_OUTPUT_ON_FAILURE=false ;; + --no-progress) + export BASHUNIT_NO_PROGRESS=true + ;; --strict) export BASHUNIT_STRICT_MODE=true ;; diff --git a/src/runner.sh b/src/runner.sh index 9012724e..3105bfa2 100755 --- a/src/runner.sh +++ b/src/runner.sh @@ -153,6 +153,12 @@ function bashunit::runner::spinner() { return fi + # Don't show spinner in no-progress mode + if bashunit::env::is_no_progress_enabled; then + while true; do sleep 1; done + return + fi + if bashunit::env::is_simple_output_enabled; then printf "\n" fi @@ -369,6 +375,11 @@ function bashunit::runner::render_running_file_header() { return fi + # Suppress file headers in no-progress mode + if bashunit::env::is_no_progress_enabled; then + return + fi + if ! bashunit::env::is_simple_output_enabled; then if bashunit::env::is_verbose_enabled; then printf "\n${_BASHUNIT_COLOR_BOLD}%s${_BASHUNIT_COLOR_DEFAULT}\n" "Running $script" @@ -1011,6 +1022,7 @@ function bashunit::runner::run_tear_down_after_script() { # Add blank line after tests if no tear_down hook if ! bashunit::env::is_simple_output_enabled && \ ! bashunit::env::is_failures_only_enabled && \ + ! bashunit::env::is_no_progress_enabled && \ ! bashunit::parallel::is_enabled; then echo "" fi @@ -1037,6 +1049,7 @@ function bashunit::runner::run_tear_down_after_script() { # Add blank line after tear_down output if ! bashunit::env::is_simple_output_enabled && \ ! bashunit::env::is_failures_only_enabled && \ + ! bashunit::env::is_no_progress_enabled && \ ! bashunit::parallel::is_enabled; then echo "" fi diff --git a/src/state.sh b/src/state.sh index 1131d033..b869e83c 100644 --- a/src/state.sh +++ b/src/state.sh @@ -268,6 +268,10 @@ function bashunit::state::print_line() { bashunit::state::add_test_output "[$type]$line" + if bashunit::env::is_no_progress_enabled; then + return + fi + if ! bashunit::env::is_simple_output_enabled; then printf "%s\n" "$line" return diff --git a/tests/acceptance/bashunit_no_progress_test.sh b/tests/acceptance/bashunit_no_progress_test.sh new file mode 100644 index 00000000..19ef0195 --- /dev/null +++ b/tests/acceptance/bashunit_no_progress_test.sh @@ -0,0 +1,74 @@ +#!/usr/bin/env bash +set -euo pipefail + +function set_up_before_script() { + TEST_ENV_FILE="tests/acceptance/fixtures/.env.default" +} + +function test_no_progress_suppresses_test_output_in_detailed_mode() { + local test_file=./tests/acceptance/fixtures/test_bashunit_when_a_test_passes.sh + local output + + output=$(./bashunit --no-parallel --env "$TEST_ENV_FILE" --no-progress "$test_file" 2>&1) + + # Should NOT contain "Passed" (per-test progress output) + assert_not_contains "Passed" "$output" + # Should still show final summary + assert_contains "Tests:" "$output" + assert_contains "4 passed" "$output" +} + +function test_no_progress_suppresses_test_output_in_simple_mode() { + local test_file=./tests/acceptance/fixtures/test_bashunit_when_a_test_passes.sh + local output + + output=$(./bashunit --no-parallel --simple --env "$TEST_ENV_FILE" --no-progress "$test_file" 2>&1) + + # Should NOT contain dots for passed tests + assert_not_contains "...." "$output" + # Should still show final summary + assert_contains "Tests:" "$output" + assert_contains "4 passed" "$output" +} + +function test_no_progress_suppresses_file_headers() { + local test_file=./tests/acceptance/fixtures/test_bashunit_when_a_test_passes.sh + local output + + output=$(./bashunit --no-parallel --env "$TEST_ENV_FILE" --no-progress "$test_file" 2>&1) + + # Should NOT contain "Running" file headers + assert_not_contains "Running" "$output" +} + +function test_no_progress_shows_correct_counts_in_summary() { + local test_file=./tests/acceptance/fixtures/test_bashunit_when_a_test_passes.sh + local output + + output=$(./bashunit --no-parallel --env "$TEST_ENV_FILE" --no-progress "$test_file" 2>&1) + + # Summary should show passed count even though progress was suppressed + assert_contains "4 passed" "$output" + assert_contains "4 total" "$output" +} + +function test_no_progress_still_shows_failures_in_summary() { + local test_file=./tests/acceptance/fixtures/test_bashunit_when_a_test_fail.sh + local output + + output=$(./bashunit --no-parallel --env "$TEST_ENV_FILE" --no-progress "$test_file" 2>&1) || true + + # Should still show failure summary + assert_contains "There was 1 failure" "$output" + assert_contains "Tests:" "$output" +} + +function test_no_progress_via_env_variable() { + local test_file=./tests/acceptance/fixtures/test_bashunit_when_a_test_passes.sh + local output + + output=$(BASHUNIT_NO_PROGRESS=true ./bashunit --no-parallel --skip-env-file "$test_file" 2>&1) + + assert_not_contains "Passed" "$output" + assert_contains "4 passed" "$output" +}