@@ -9,34 +9,51 @@ function test_successful_assert_duration_within_fast_command() {
99 assert_empty " $( assert_duration " echo hello" 5000) "
1010}
1111
12+ # Failure paths mock bashunit::duration::measure_ms: they exercise the
13+ # threshold comparison and failure message, not the timing itself, so a real
14+ # `sleep 1` per test only slowed the suite down (#826).
1215function test_unsuccessful_assert_duration_exceeds_threshold() {
16+ bashunit::mock bashunit::duration::measure_ms <<< " 2000"
17+
1318 assert_same \
1419 " $( bashunit::console_results::print_failed_test \
1520 " Unsuccessful assert duration exceeds threshold" \
16- " 1000" " to complete within (ms)" " sleep 1 " ) " \
17- " $( assert_duration " sleep 1 " 1000) "
21+ " 1000" " to complete within (ms)" " fake_slow_command " ) " \
22+ " $( assert_duration " fake_slow_command " 1000) "
1823}
1924
2025function test_successful_assert_duration_less_than() {
2126 assert_empty " $( assert_duration_less_than " sleep 0" 5000) "
2227}
2328
2429function test_unsuccessful_assert_duration_less_than() {
30+ bashunit::mock bashunit::duration::measure_ms <<< " 2000"
31+
2532 assert_same \
2633 " $( bashunit::console_results::print_failed_test \
2734 " Unsuccessful assert duration less than" \
28- " 100" " to complete within (ms)" " sleep 1 " ) " \
29- " $( assert_duration_less_than " sleep 1 " 100) "
35+ " 100" " to complete within (ms)" " fake_slow_command " ) " \
36+ " $( assert_duration_less_than " fake_slow_command " 100) "
3037}
3138
39+ # Keep one success path on a real (short) sleep so measure_ms integration
40+ # stays covered end-to-end. The last-resort date-seconds clock has 1s
41+ # resolution and would measure a sub-second sleep as 0ms, so skip there.
3242function test_successful_assert_duration_greater_than() {
33- assert_empty " $( assert_duration_greater_than " sleep 1" 500) "
43+ bashunit::clock::now_to_slot > /dev/null 2>&1 || true
44+ if [ " ${_BASHUNIT_CLOCK_NOW_IMPL:- } " = " date-seconds" ]; then
45+ bashunit::skip " clock has 1s resolution" && return
46+ fi
47+
48+ assert_empty " $( assert_duration_greater_than " sleep 0.2" 100) "
3449}
3550
3651function test_unsuccessful_assert_duration_greater_than() {
52+ bashunit::mock bashunit::duration::measure_ms <<< " 3"
53+
3754 assert_same \
3855 " $( bashunit::console_results::print_failed_test \
3956 " Unsuccessful assert duration greater than" \
40- " 5000" " to take at least (ms)" " echo hello " ) " \
41- " $( assert_duration_greater_than " echo hello " 5000) "
57+ " 5000" " to take at least (ms)" " fake_fast_command " ) " \
58+ " $( assert_duration_greater_than " fake_fast_command " 5000) "
4259}
0 commit comments