@@ -13,7 +13,8 @@ function console_results::render_result() {
1313 fi
1414
1515 if env::is_simple_output_enabled; then
16- printf " \n\n"
16+ progress::blank_line
17+ progress::blank_line
1718 fi
1819
1920 local total_tests=0
@@ -67,36 +68,42 @@ function console_results::render_result() {
6768 printf " %s total\n" " $total_assertions "
6869
6970 if [[ " $( state::get_tests_failed) " -gt 0 ]]; then
70- printf " \n%s%s%s\n" " $_COLOR_RETURN_ERROR " " Some tests failed " " $_COLOR_DEFAULT "
71+ progress::blank_line
72+ printf " %s%s%s\n" " $_COLOR_RETURN_ERROR " " Some tests failed " " $_COLOR_DEFAULT "
7173 console_results::print_execution_time
7274 return 1
7375 fi
7476
7577 if [[ " $( state::get_tests_incomplete) " -gt 0 ]]; then
76- printf " \n%s%s%s\n" " $_COLOR_RETURN_INCOMPLETE " " Some tests incomplete " " $_COLOR_DEFAULT "
78+ progress::blank_line
79+ printf " %s%s%s\n" " $_COLOR_RETURN_INCOMPLETE " " Some tests incomplete " " $_COLOR_DEFAULT "
7780 console_results::print_execution_time
7881 return 0
7982 fi
8083
8184 if [[ " $( state::get_tests_skipped) " -gt 0 ]]; then
82- printf " \n%s%s%s\n" " $_COLOR_RETURN_SKIPPED " " Some tests skipped " " $_COLOR_DEFAULT "
85+ progress::blank_line
86+ printf " %s%s%s\n" " $_COLOR_RETURN_SKIPPED " " Some tests skipped " " $_COLOR_DEFAULT "
8387 console_results::print_execution_time
8488 return 0
8589 fi
8690
8791 if [[ " $( state::get_tests_snapshot) " -gt 0 ]]; then
88- printf " \n%s%s%s\n" " $_COLOR_RETURN_SNAPSHOT " " Some snapshots created " " $_COLOR_DEFAULT "
92+ progress::blank_line
93+ printf " %s%s%s\n" " $_COLOR_RETURN_SNAPSHOT " " Some snapshots created " " $_COLOR_DEFAULT "
8994 console_results::print_execution_time
9095 return 0
9196 fi
9297
9398 if [[ $total_tests -eq 0 ]]; then
94- printf " \n%s%s%s\n" " $_COLOR_RETURN_ERROR " " No tests found " " $_COLOR_DEFAULT "
99+ progress::blank_line
100+ printf " %s%s%s\n" " $_COLOR_RETURN_ERROR " " No tests found " " $_COLOR_DEFAULT "
95101 console_results::print_execution_time
96102 return 1
97103 fi
98104
99- printf " \n%s%s%s\n" " $_COLOR_RETURN_SUCCESS " " All tests passed " " $_COLOR_DEFAULT "
105+ progress::blank_line
106+ printf " %s%s%s\n" " $_COLOR_RETURN_SUCCESS " " All tests passed " " $_COLOR_DEFAULT "
100107 console_results::print_execution_time
101108 return 0
102109}
@@ -143,17 +150,39 @@ function console_results::print_successful_test() {
143150 state::print_line " successful" " $full_line "
144151}
145152
153+ # Print a summary line for a failed test with its duration.
154+ function console_results::print_failed_test_summary() {
155+ local test_name=$1
156+ local duration=${2:- " 0" }
157+
158+ local line
159+ line=$( printf " %s✗ Failed%s: %s" " $_COLOR_FAILED " " $_COLOR_DEFAULT " " $test_name " )
160+
161+ local full_line=$line
162+ if env::is_show_execution_time_enabled; then
163+ full_line=" $( printf " %s\n" " $( str::rpad " $line " " $duration ms" ) " ) "
164+ fi
165+
166+ state::print_line " failed" " $full_line "
167+ }
168+
146169function console_results::print_failure_message() {
147170 local test_name=$1
148171 local failure_message=$2
172+ local duration=${3-}
149173
150174 local line
151175 line=" $( printf " \
152176${_COLOR_FAILED} ✗ Failed${_COLOR_DEFAULT} : %s
153177 ${_COLOR_FAINT} Message:${_COLOR_DEFAULT} ${_COLOR_BOLD} '%s'${_COLOR_DEFAULT} \n" \
154178 " ${test_name} " " ${failure_message} " ) "
155179
156- state::print_line " failure" " $line "
180+ local full_line=$line
181+ if [[ -n " $duration " ]] && env::is_show_execution_time_enabled; then
182+ full_line=" $( printf " %s\n" " $( str::rpad " $line " " $duration ms" ) " ) "
183+ fi
184+
185+ state::print_line " failure" " $full_line "
157186}
158187
159188function console_results::print_failed_test() {
@@ -163,6 +192,7 @@ function console_results::print_failed_test() {
163192 local actual=$4
164193 local extra_key=${5-}
165194 local extra_value=${6-}
195+ local duration=${7-}
166196
167197 local line
168198 line=" $( printf " \
@@ -178,13 +208,19 @@ ${_COLOR_FAILED}✗ Failed${_COLOR_DEFAULT}: %s
178208 " ${extra_key} " " ${extra_value} " ) "
179209 fi
180210
181- state::print_line " failed" " $line "
211+ local full_line=$line
212+ if [[ -n " $duration " ]] && env::is_show_execution_time_enabled; then
213+ full_line=" $( printf " %s\n" " $( str::rpad " $line " " $duration ms" ) " ) "
214+ fi
215+
216+ state::print_line " failed" " $full_line "
182217}
183218
184219
185220function console_results::print_failed_snapshot_test() {
186221 local function_name=$1
187222 local snapshot_file=$2
223+ local duration=${3-}
188224
189225 local line
190226 line=" $( printf " ${_COLOR_FAILED} ✗ Failed${_COLOR_DEFAULT} : %s
@@ -203,12 +239,18 @@ function console_results::print_failed_snapshot_test() {
203239 rm " $actual_file "
204240 fi
205241
206- state::print_line " failed_snapshot" " $line "
242+ local full_line=$line
243+ if [[ -n " $duration " ]] && env::is_show_execution_time_enabled; then
244+ full_line=" $( printf " %s\n" " $( str::rpad " $line " " $duration ms" ) " ) "
245+ fi
246+
247+ state::print_line " failed_snapshot" " $full_line "
207248}
208249
209250function console_results::print_skipped_test() {
210251 local function_name=$1
211252 local reason=${2-}
253+ local duration=${3-}
212254
213255 local line
214256 line=" $( printf " ${_COLOR_SKIPPED} ↷ Skipped${_COLOR_DEFAULT} : %s\n" " ${function_name} " ) "
@@ -217,12 +259,18 @@ function console_results::print_skipped_test() {
217259 line+=" $( printf " ${_COLOR_FAINT} %s${_COLOR_DEFAULT} \n" " ${reason} " ) "
218260 fi
219261
220- state::print_line " skipped" " $line "
262+ local full_line=$line
263+ if [[ -n " $duration " ]] && env::is_show_execution_time_enabled; then
264+ full_line=" $( printf " %s\n" " $( str::rpad " $line " " $duration ms" ) " ) "
265+ fi
266+
267+ state::print_line " skipped" " $full_line "
221268}
222269
223270function console_results::print_incomplete_test() {
224271 local function_name=$1
225272 local pending=${2-}
273+ local duration=${3-}
226274
227275 local line
228276 line=" $( printf " ${_COLOR_INCOMPLETE} ✒ Incomplete${_COLOR_DEFAULT} : %s\n" " ${function_name} " ) "
@@ -231,23 +279,35 @@ function console_results::print_incomplete_test() {
231279 line+=" $( printf " ${_COLOR_FAINT} %s${_COLOR_DEFAULT} \n" " ${pending} " ) "
232280 fi
233281
234- state::print_line " incomplete" " $line "
282+ local full_line=$line
283+ if [[ -n " $duration " ]] && env::is_show_execution_time_enabled; then
284+ full_line=" $( printf " %s\n" " $( str::rpad " $line " " $duration ms" ) " ) "
285+ fi
286+
287+ state::print_line " incomplete" " $full_line "
235288}
236289
237290function console_results::print_snapshot_test() {
238291 local function_name=$1
292+ local duration=${2-}
239293 local test_name
240294 test_name=$( helper::normalize_test_function_name " $function_name " )
241295
242296 local line
243297 line=" $( printf " ${_COLOR_SNAPSHOT} ✎ Snapshot${_COLOR_DEFAULT} : %s\n" " ${test_name} " ) "
244298
245- state::print_line " snapshot" " $line "
299+ local full_line=$line
300+ if [[ -n " $duration " ]] && env::is_show_execution_time_enabled; then
301+ full_line=" $( printf " %s\n" " $( str::rpad " $line " " $duration ms" ) " ) "
302+ fi
303+
304+ state::print_line " snapshot" " $full_line "
246305}
247306
248307function console_results::print_error_test() {
249308 local function_name=$1
250309 local error=" $2 "
310+ local duration=${3-}
251311
252312 local test_name
253313 test_name=$( helper::normalize_test_function_name " $function_name " )
@@ -256,7 +316,12 @@ function console_results::print_error_test() {
256316 line=" $( printf " ${_COLOR_FAILED} ✗ Error${_COLOR_DEFAULT} : %s
257317 ${_COLOR_FAINT} %s${_COLOR_DEFAULT} \n" " ${test_name} " " ${error} " ) "
258318
259- state::print_line " error" " $line "
319+ local full_line=$line
320+ if [[ -n " $duration " ]] && env::is_show_execution_time_enabled; then
321+ full_line=" $( printf " %s\n" " $( str::rpad " $line " " $duration ms" ) " ) "
322+ fi
323+
324+ state::print_line " error" " $full_line "
260325}
261326
262327function console_results::print_failing_tests_and_reset() {
@@ -265,7 +330,8 @@ function console_results::print_failing_tests_and_reset() {
265330 total_failed=$( state::get_tests_failed)
266331
267332 if env::is_simple_output_enabled; then
268- printf " \n\n"
333+ progress::blank_line
334+ progress::blank_line
269335 fi
270336
271337 if [[ " $total_failed " -eq 1 ]]; then
@@ -277,6 +343,6 @@ function console_results::print_failing_tests_and_reset() {
277343 sed ' ${/^$/d;}' " $FAILURES_OUTPUT_PATH " | sed ' s/^/|/'
278344 rm " $FAILURES_OUTPUT_PATH "
279345
280- echo " "
346+ progress::blank_line
281347 fi
282348}
0 commit comments