Skip to content

Commit e159413

Browse files
authored
Merge pull request #578 from TypedDevs/feat/577-align-timing-to-right
Align all displayed timings to the right
2 parents 8140d00 + 04dea4b commit e159413

File tree

7 files changed

+83
-43
lines changed

7 files changed

+83
-43
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22

33
## Unreleased
44

5+
### Changed
6+
- Hook output now displays with right-aligned timing and bullet prefix (`● set_up_before_script 2.03s`)
7+
58
### Added
69
- Better code coverage HTML report
710
- Auto-discover coverage paths from test file names when `BASHUNIT_COVERAGE_PATHS` is not set
811
- `tests/unit/assert_test.sh` automatically tracks `src/assert.sh`
9-
- Removes need for manual `--coverage-paths` configuration in most cases
12+
- Removes the need for manual `--coverage-paths` configuration in most cases
1013
- `--coverage-report-html` now defaults to `coverage/html` when no directory is specified
1114

1215
### Fixed

docs/blog/2025-12-19-release-0-31.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ See exactly how long your setup and teardown scripts take:
7272

7373
::: code-group
7474
```[Output]
75-
Running set_up_before_script... done (2.3s)
76-
✓ Passed: My test 45 ms
77-
Running tear_down_after_script... done (0.5s)
75+
set_up_before_script 2.30s
76+
✓ Passed: My test 45ms
77+
tear_down_after_script 0.5s
7878
```
7979
:::
8080

docs/test-files.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,12 @@ function tear_down() {
8585
The `set_up_before_script` auxiliary function is called, if it is present in the test file, only once before all tests functions in the test file begin.
8686
This is useful for global setup that applies to all test functions in the script, such as loading shared resources.
8787
88-
During test execution, bashunit displays the hook execution with its duration:
88+
During test execution, bashunit displays the hook execution with its duration, right-aligned to match test output:
8989
9090
```
9191
Running tests/example_test.sh
92-
Running set_up_before_script... done (2.03s)
93-
✓ Passed: test_example
92+
● set_up_before_script 2.03s
93+
✓ Passed: test_example 12ms
9494
```
9595
9696
This visibility helps identify slow setup operations that may impact test run time.
@@ -114,8 +114,8 @@ It provides a hook for any cleanup that should occur after all tests have run, s
114114
Like `set_up_before_script`, the execution is displayed with its duration:
115115
116116
```
117-
✓ Passed: test_example
118-
Running tear_down_after_script... done (1.05s)
117+
✓ Passed: test_example 12ms
118+
● tear_down_after_script 1.05s
119119
120120
Tests: 1 passed, 1 total
121121
```

src/console_results.sh

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -160,24 +160,6 @@ function bashunit::console_results::format_duration() {
160160
fi
161161
}
162162

163-
function bashunit::console_results::print_hook_running() {
164-
local hook_name="$1"
165-
166-
if bashunit::env::is_simple_output_enabled; then
167-
return
168-
fi
169-
170-
if bashunit::env::is_failures_only_enabled; then
171-
return
172-
fi
173-
174-
if bashunit::parallel::is_enabled; then
175-
return
176-
fi
177-
178-
printf " ${_BASHUNIT_COLOR_FAINT}Running %s...${_BASHUNIT_COLOR_DEFAULT}" "$hook_name"
179-
}
180-
181163
function bashunit::console_results::print_hook_completed() {
182164
local hook_name="$1"
183165
local duration_ms="$2"
@@ -194,12 +176,14 @@ function bashunit::console_results::print_hook_completed() {
194176
return
195177
fi
196178

179+
local line
180+
line=$(printf "%s● %s%s" \
181+
"$_BASHUNIT_COLOR_PASSED" "$hook_name" "$_BASHUNIT_COLOR_DEFAULT")
182+
197183
local time_display
198184
time_display=$(bashunit::console_results::format_duration "$duration_ms")
199185

200-
printf " %sdone%s %s(%s)%s\n" \
201-
"$_BASHUNIT_COLOR_PASSED" "$_BASHUNIT_COLOR_DEFAULT" \
202-
"$_BASHUNIT_COLOR_FAINT" "$time_display" "$_BASHUNIT_COLOR_DEFAULT"
186+
printf "%s\n" "$(bashunit::str::rpad "$line" "$time_display")"
203187
}
204188

205189
function bashunit::console_results::print_successful_test() {

src/runner.sh

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -893,9 +893,6 @@ function bashunit::runner::run_set_up_before_script() {
893893
return 0
894894
fi
895895

896-
# Print "Running..." message
897-
bashunit::console_results::print_hook_running "set_up_before_script"
898-
899896
local start_time
900897
start_time=$(bashunit::clock::now)
901898

@@ -1014,9 +1011,6 @@ function bashunit::runner::run_tear_down_after_script() {
10141011
return 0
10151012
fi
10161013

1017-
# Print "Running..." message
1018-
bashunit::console_results::print_hook_running "tear_down_after_script"
1019-
10201014
local start_time
10211015
start_time=$(bashunit::clock::now)
10221016

tests/acceptance/bashunit_lifecycle_output_test.sh

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,8 @@ EOF
124124
# Explicitly disable simple/parallel modes to ensure normal output
125125
output=$(BASHUNIT_SIMPLE_OUTPUT=false BASHUNIT_PARALLEL_RUN=false ./bashunit "$test_file" 2>&1)
126126

127-
assert_contains "Running set_up_before_script..." "$output"
128-
assert_contains "done" "$output"
129-
assert_contains "Running tear_down_after_script..." "$output"
127+
assert_contains "● set_up_before_script" "$output"
128+
assert_contains "● tear_down_after_script" "$output"
130129
}
131130

132131
function test_hook_visibility_suppressed_in_failures_only_mode() {
@@ -150,8 +149,8 @@ EOF
150149
local output
151150
output=$(./bashunit --failures-only "$test_file" 2>&1)
152151

153-
assert_not_contains "Running set_up_before_script" "$output"
154-
assert_not_contains "Running tear_down_after_script" "$output"
152+
assert_not_contains " set_up_before_script" "$output"
153+
assert_not_contains " tear_down_after_script" "$output"
155154
}
156155

157156
function test_hook_visibility_suppressed_in_simple_mode() {
@@ -193,6 +192,6 @@ EOF
193192
local output
194193
output=$(BASHUNIT_SIMPLE_OUTPUT=false BASHUNIT_PARALLEL_RUN=false ./bashunit "$test_file" 2>&1)
195194

196-
assert_not_contains "Running set_up_before_script" "$output"
197-
assert_not_contains "Running tear_down_after_script" "$output"
195+
assert_not_contains " set_up_before_script" "$output"
196+
assert_not_contains " tear_down_after_script" "$output"
198197
}

tests/unit/console_results_test.sh

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,3 +659,63 @@ function test_print_successful_test_output_in_minutes_exact() {
659659

660660
export BASHUNIT_SIMPLE_OUTPUT=$original_simple_output
661661
}
662+
663+
function test_print_hook_completed_output_milliseconds() {
664+
local original_simple_output=$BASHUNIT_SIMPLE_OUTPUT
665+
local original_parallel_run=$BASHUNIT_PARALLEL_RUN
666+
export BASHUNIT_SIMPLE_OUTPUT=false
667+
export BASHUNIT_PARALLEL_RUN=false
668+
export TERMINAL_WIDTH=80
669+
670+
local output
671+
output=$(bashunit::console_results::print_hook_completed "set_up_before_script" "12")
672+
673+
assert_matches "● set_up_before_script.*12ms" "$output"
674+
675+
export BASHUNIT_SIMPLE_OUTPUT=$original_simple_output
676+
export BASHUNIT_PARALLEL_RUN=$original_parallel_run
677+
}
678+
679+
function test_print_hook_completed_output_seconds() {
680+
local original_simple_output=$BASHUNIT_SIMPLE_OUTPUT
681+
local original_parallel_run=$BASHUNIT_PARALLEL_RUN
682+
export BASHUNIT_SIMPLE_OUTPUT=false
683+
export BASHUNIT_PARALLEL_RUN=false
684+
export TERMINAL_WIDTH=80
685+
686+
local output
687+
output=$(bashunit::console_results::print_hook_completed "set_up_before_script" "2340")
688+
689+
assert_matches "● set_up_before_script.*2.34s" "$output"
690+
691+
export BASHUNIT_SIMPLE_OUTPUT=$original_simple_output
692+
export BASHUNIT_PARALLEL_RUN=$original_parallel_run
693+
}
694+
695+
function test_print_hook_completed_output_minutes() {
696+
local original_simple_output=$BASHUNIT_SIMPLE_OUTPUT
697+
local original_parallel_run=$BASHUNIT_PARALLEL_RUN
698+
export BASHUNIT_SIMPLE_OUTPUT=false
699+
export BASHUNIT_PARALLEL_RUN=false
700+
export TERMINAL_WIDTH=80
701+
702+
local output
703+
output=$(bashunit::console_results::print_hook_completed "tear_down_after_script" "125000")
704+
705+
assert_matches "● tear_down_after_script.*2m 5s" "$output"
706+
707+
export BASHUNIT_SIMPLE_OUTPUT=$original_simple_output
708+
export BASHUNIT_PARALLEL_RUN=$original_parallel_run
709+
}
710+
711+
function test_print_hook_completed_suppressed_in_simple_mode() {
712+
local original_simple_output=$BASHUNIT_SIMPLE_OUTPUT
713+
export BASHUNIT_SIMPLE_OUTPUT=true
714+
715+
local output
716+
output=$(bashunit::console_results::print_hook_completed "set_up_before_script" "12")
717+
718+
assert_empty "$output"
719+
720+
export BASHUNIT_SIMPLE_OUTPUT=$original_simple_output
721+
}

0 commit comments

Comments
 (0)