Skip to content

Commit b996cd3

Browse files
authored
Merge pull request #525 from TypedDevs/feat/524-show-skipped-incomplete
Add --show-skipped and --show-incomplete options
2 parents 68eb45a + e286a07 commit b996cd3

7 files changed

Lines changed: 164 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- Add inline filter syntax to run specific tests from a file
77
- `path::function_name` - filter tests by function name
88
- `path:line_number` - run the test containing the specified line
9+
- Add `--show-skipped` and `--show-incomplete` options to display skipped/incomplete tests at the end
910

1011
### Changed
1112
- **BREAKING:** Introduce subcommand-based CLI architecture
@@ -66,8 +67,8 @@
6667

6768
- Improve `assert_have_been_called_with` with strict argument matching
6869
- Make Windows install clearer in the docs by adding an option for Linux/Mac and another one for Windows.
69-
- Add support for empty values and values containing spaces, tabs or newlines in data providers via new `data_set` function
70-
- Document workaround for global function name collisions when sourcing scripts in tests by copying the original function
70+
- Add data_set function for empty values and values with spaces/tabs/newlines
71+
- Document workaround for function name collisions when sourcing scripts
7172
- Fix `temp_dir` and `temp_file` data not being cleaned up when created in `set_up_before_script`
7273
- Fix `/tmp/bashunit/parallel` not being cleaned after test run
7374

docs/command-line.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ bashunit test tests/ --parallel --simple
5555
| `-s, --simple` | Simple output (dots) |
5656
| `--detailed` | Detailed output (default) |
5757
| `-S, --stop-on-failure` | Stop on first failure |
58+
| `--show-skipped` | Show skipped tests summary at end |
59+
| `--show-incomplete` | Show incomplete tests summary at end |
5860
| `-vvv, --verbose` | Show execution details |
5961
| `--debug [file]` | Enable shell debug mode |
6062
| `--no-output` | Suppress all output |

src/console_results.sh

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,3 +301,47 @@ function console_results::print_failing_tests_and_reset() {
301301
echo ""
302302
fi
303303
}
304+
305+
function console_results::print_skipped_tests_and_reset() {
306+
if [[ -s "$SKIPPED_OUTPUT_PATH" ]] && env::is_show_skipped_enabled; then
307+
local total_skipped
308+
total_skipped=$(state::get_tests_skipped)
309+
310+
if env::is_simple_output_enabled; then
311+
printf "\n"
312+
fi
313+
314+
if [[ "$total_skipped" -eq 1 ]]; then
315+
echo -e "${_COLOR_BOLD}There was 1 skipped test:${_COLOR_DEFAULT}\n"
316+
else
317+
echo -e "${_COLOR_BOLD}There were $total_skipped skipped tests:${_COLOR_DEFAULT}\n"
318+
fi
319+
320+
tr -d '\r' < "$SKIPPED_OUTPUT_PATH" | sed '/^[[:space:]]*$/d' | sed 's/^/|/'
321+
rm "$SKIPPED_OUTPUT_PATH"
322+
323+
echo ""
324+
fi
325+
}
326+
327+
function console_results::print_incomplete_tests_and_reset() {
328+
if [[ -s "$INCOMPLETE_OUTPUT_PATH" ]] && env::is_show_incomplete_enabled; then
329+
local total_incomplete
330+
total_incomplete=$(state::get_tests_incomplete)
331+
332+
if env::is_simple_output_enabled; then
333+
printf "\n"
334+
fi
335+
336+
if [[ "$total_incomplete" -eq 1 ]]; then
337+
echo -e "${_COLOR_BOLD}There was 1 incomplete test:${_COLOR_DEFAULT}\n"
338+
else
339+
echo -e "${_COLOR_BOLD}There were $total_incomplete incomplete tests:${_COLOR_DEFAULT}\n"
340+
fi
341+
342+
tr -d '\r' < "$INCOMPLETE_OUTPUT_PATH" | sed '/^[[:space:]]*$/d' | sed 's/^/|/'
343+
rm "$INCOMPLETE_OUTPUT_PATH"
344+
345+
echo ""
346+
fi
347+
}

src/env.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ _DEFAULT_VERBOSE="false"
3030
_DEFAULT_BENCH_MODE="false"
3131
_DEFAULT_NO_OUTPUT="false"
3232
_DEFAULT_INTERNAL_LOG="false"
33+
_DEFAULT_SHOW_SKIPPED="false"
34+
_DEFAULT_SHOW_INCOMPLETE="false"
3335

3436
: "${BASHUNIT_PARALLEL_RUN:=${PARALLEL_RUN:=$_DEFAULT_PARALLEL_RUN}}"
3537
: "${BASHUNIT_SHOW_HEADER:=${SHOW_HEADER:=$_DEFAULT_SHOW_HEADER}}"
@@ -41,6 +43,8 @@ _DEFAULT_INTERNAL_LOG="false"
4143
: "${BASHUNIT_BENCH_MODE:=${BENCH_MODE:=$_DEFAULT_BENCH_MODE}}"
4244
: "${BASHUNIT_NO_OUTPUT:=${NO_OUTPUT:=$_DEFAULT_NO_OUTPUT}}"
4345
: "${BASHUNIT_INTERNAL_LOG:=${INTERNAL_LOG:=$_DEFAULT_INTERNAL_LOG}}"
46+
: "${BASHUNIT_SHOW_SKIPPED:=${SHOW_SKIPPED:=$_DEFAULT_SHOW_SKIPPED}}"
47+
: "${BASHUNIT_SHOW_INCOMPLETE:=${SHOW_INCOMPLETE:=$_DEFAULT_SHOW_INCOMPLETE}}"
4448

4549
function env::is_parallel_run_enabled() {
4650
[[ "$BASHUNIT_PARALLEL_RUN" == "true" ]]
@@ -86,6 +90,14 @@ function env::is_no_output_enabled() {
8690
[[ "$BASHUNIT_NO_OUTPUT" == "true" ]]
8791
}
8892

93+
function env::is_show_skipped_enabled() {
94+
[[ "$BASHUNIT_SHOW_SKIPPED" == "true" ]]
95+
}
96+
97+
function env::is_show_incomplete_enabled() {
98+
[[ "$BASHUNIT_SHOW_INCOMPLETE" == "true" ]]
99+
}
100+
89101
function env::active_internet_connection() {
90102
if [[ "${BASHUNIT_NO_NETWORK:-}" == "true" ]]; then
91103
return 1
@@ -157,6 +169,8 @@ TEMP_DIR_PARALLEL_TEST_SUITE="${TMPDIR:-/tmp}/bashunit/parallel/${_OS:-Unknown}/
157169
TEMP_FILE_PARALLEL_STOP_ON_FAILURE="$TEMP_DIR_PARALLEL_TEST_SUITE/.stop-on-failure"
158170
TERMINAL_WIDTH="$(env::find_terminal_width)"
159171
FAILURES_OUTPUT_PATH=$(mktemp)
172+
SKIPPED_OUTPUT_PATH=$(mktemp)
173+
INCOMPLETE_OUTPUT_PATH=$(mktemp)
160174
CAT="$(command -v cat)"
161175

162176
# Initialize temp directory once at startup for performance

src/main.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ function main::cmd_test() {
6666
console_header::print_test_help
6767
exit 0
6868
;;
69+
--show-skipped)
70+
export BASHUNIT_SHOW_SKIPPED=true
71+
;;
72+
--show-incomplete)
73+
export BASHUNIT_SHOW_INCOMPLETE=true
74+
;;
6975
*)
7076
raw_args+=("$1")
7177
;;
@@ -319,6 +325,8 @@ function main::exec_tests() {
319325
fi
320326

321327
console_results::print_failing_tests_and_reset
328+
console_results::print_incomplete_tests_and_reset
329+
console_results::print_skipped_tests_and_reset
322330
console_results::render_result
323331
exit_code=$?
324332

@@ -378,6 +386,8 @@ function main::cleanup() {
378386
function main::handle_stop_on_failure_sync() {
379387
printf "\n%sStop on failure enabled...%s\n" "${_COLOR_SKIPPED}" "${_COLOR_DEFAULT}"
380388
console_results::print_failing_tests_and_reset
389+
console_results::print_incomplete_tests_and_reset
390+
console_results::print_skipped_tests_and_reset
381391
console_results::render_result
382392
cleanup_script_temp_files
383393
if parallel::is_enabled; then

src/runner.sh

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ function runner::load_test_files() {
6565
parallel::aggregate_test_results "$TEMP_DIR_PARALLEL_TEST_SUITE"
6666
# Kill the spinner once the aggregation finishes
6767
disown "$spinner_pid" && kill "$spinner_pid" &>/dev/null
68-
printf "\r " # Clear the spinner output
68+
printf "\r \r" # Clear the spinner output
6969
for script_id in "${scripts_ids[@]}"; do
7070
export BASHUNIT_CURRENT_SCRIPT_ID="${script_id}"
7171
cleanup_script_temp_files
@@ -111,6 +111,13 @@ function runner::load_bench_files() {
111111
}
112112

113113
function runner::spinner() {
114+
# Only show spinner when output is to a terminal
115+
if [[ ! -t 1 ]]; then
116+
# Not a terminal, just wait silently
117+
while true; do sleep 1; done
118+
return
119+
fi
120+
114121
if env::is_simple_output_enabled; then
115122
printf "\n"
116123
fi
@@ -524,13 +531,15 @@ function runner::run_test() {
524531
if [[ "$current_assertions_incomplete" != "$(state::get_assertions_incomplete)" ]]; then
525532
state::add_tests_incomplete
526533
reports::add_test_incomplete "$test_file" "$label" "$duration" "$total_assertions"
534+
runner::write_incomplete_result_output "$test_file" "$fn_name" "$subshell_output"
527535
internal_log "Test incomplete" "$label"
528536
return
529537
fi
530538

531539
if [[ "$current_assertions_skipped" != "$(state::get_assertions_skipped)" ]]; then
532540
state::add_tests_skipped
533541
reports::add_test_skipped "$test_file" "$label" "$duration" "$total_assertions"
542+
runner::write_skipped_result_output "$test_file" "$fn_name" "$subshell_output"
534543
internal_log "Test skipped" "$label"
535544
return
536545
fi
@@ -681,6 +690,38 @@ function runner::write_failure_result_output() {
681690
echo -e "$test_nr) $test_file:$line_number\n$error_msg" >> "$FAILURES_OUTPUT_PATH"
682691
}
683692

693+
function runner::write_skipped_result_output() {
694+
local test_file=$1
695+
local fn_name=$2
696+
local output_msg=$3
697+
698+
local line_number
699+
line_number=$(helper::get_function_line_number "$fn_name")
700+
701+
local test_nr="*"
702+
if ! parallel::is_enabled; then
703+
test_nr=$(state::get_tests_skipped)
704+
fi
705+
706+
echo -e "$test_nr) $test_file:$line_number\n$output_msg" >> "$SKIPPED_OUTPUT_PATH"
707+
}
708+
709+
function runner::write_incomplete_result_output() {
710+
local test_file=$1
711+
local fn_name=$2
712+
local output_msg=$3
713+
714+
local line_number
715+
line_number=$(helper::get_function_line_number "$fn_name")
716+
717+
local test_nr="*"
718+
if ! parallel::is_enabled; then
719+
test_nr=$(state::get_tests_incomplete)
720+
fi
721+
722+
echo -e "$test_nr) $test_file:$line_number\n$output_msg" >> "$INCOMPLETE_OUTPUT_PATH"
723+
}
724+
684725
function runner::record_file_hook_failure() {
685726
local hook_name="$1"
686727
local test_file="$2"
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
function set_up_before_script() {
5+
TEST_ENV_FILE="tests/acceptance/fixtures/.env.default"
6+
}
7+
8+
function test_skipped_tests_not_displayed_without_flag() {
9+
local output
10+
output=$(./bashunit --no-parallel --simple --env "$TEST_ENV_FILE" \
11+
"tests/acceptance/bashunit_init_test.sh")
12+
13+
assert_not_contains "There was 1 skipped test:" "$output"
14+
}
15+
16+
function test_incomplete_tests_not_displayed_without_flag() {
17+
local output
18+
output=$(./bashunit --no-parallel --simple --env "$TEST_ENV_FILE" \
19+
"tests/acceptance/bashunit_execution_error_test.sh")
20+
21+
assert_not_contains "There was 1 incomplete test:" "$output"
22+
}
23+
24+
function test_skipped_tests_displayed_with_show_skipped_flag() {
25+
local output
26+
output=$(./bashunit --no-parallel --simple --show-skipped --env "$TEST_ENV_FILE" \
27+
"tests/acceptance/bashunit_init_test.sh")
28+
29+
assert_contains "There was 1 skipped test:" "$output"
30+
assert_contains "Bashunit init updates env" "$output"
31+
}
32+
33+
function test_incomplete_tests_displayed_with_show_incomplete_flag() {
34+
local output
35+
output=$(./bashunit --no-parallel --simple --show-incomplete --env "$TEST_ENV_FILE" \
36+
"tests/acceptance/bashunit_execution_error_test.sh")
37+
38+
assert_contains "There was 1 incomplete test:" "$output"
39+
assert_contains "Add snapshots with regex" "$output"
40+
}
41+
42+
function test_both_flags_can_be_used_together() {
43+
local output
44+
output=$(./bashunit --no-parallel --simple --show-skipped --show-incomplete --env "$TEST_ENV_FILE" \
45+
"tests/acceptance/bashunit_fail_test.sh" "tests/acceptance/bashunit_init_test.sh")
46+
47+
assert_contains "incomplete test" "$output"
48+
assert_contains "skipped test" "$output"
49+
}

0 commit comments

Comments
 (0)