File tree Expand file tree Collapse file tree 4 files changed +15
-18
lines changed Expand file tree Collapse file tree 4 files changed +15
-18
lines changed Original file line number Diff line number Diff line change @@ -39,6 +39,7 @@ _BENCH_MODE=false
39
39
# Determine bench mode early so path arguments use correct pattern
40
40
for arg in " $@ " ; do
41
41
if [[ $arg == " -b" || $arg == " --bench" ]]; then
42
+ export BASHUNIT_BENCH_MODE=true
42
43
_BENCH_MODE=true
43
44
break
44
45
fi
Original file line number Diff line number Diff line change @@ -69,8 +69,10 @@ function benchmark::run_function() {
69
69
local dur_ms=$( math::calculate " $dur_ns / 1000000" )
70
70
durations+=(" $dur_ms " )
71
71
72
- local line=" bench $fn_name [$i /$its ] ${dur_ms} ms"
73
- state::print_line " successful" " $line "
72
+ if env::is_bench_mode_enabled; then
73
+ local line=" bench $fn_name [$i /$its ] ${dur_ms} ms"
74
+ state::print_line " successful" " $line "
75
+ fi
74
76
done
75
77
76
78
local sum=0
@@ -82,6 +84,10 @@ function benchmark::run_function() {
82
84
}
83
85
84
86
function benchmark::print_results() {
87
+ if ! env::is_bench_mode_enabled; then
88
+ return
89
+ fi
90
+
85
91
if (( ${# _BENCH_NAMES[@]} == 0 )) ; then
86
92
return
87
93
fi
Original file line number Diff line number Diff line change @@ -27,6 +27,7 @@ _DEFAULT_SIMPLE_OUTPUT="false"
27
27
_DEFAULT_STOP_ON_FAILURE=" false"
28
28
_DEFAULT_SHOW_EXECUTION_TIME=" true"
29
29
_DEFAULT_VERBOSE=" false"
30
+ _DEFAULT_BENCH_MODE=" false"
30
31
31
32
: " ${BASHUNIT_PARALLEL_RUN:= ${PARALLEL_RUN:= $_DEFAULT_PARALLEL_RUN } } "
32
33
: " ${BASHUNIT_SHOW_HEADER:= ${SHOW_HEADER:= $_DEFAULT_SHOW_HEADER } } "
@@ -35,6 +36,7 @@ _DEFAULT_VERBOSE="false"
35
36
: " ${BASHUNIT_STOP_ON_FAILURE:= ${STOP_ON_FAILURE:= $_DEFAULT_STOP_ON_FAILURE } } "
36
37
: " ${BASHUNIT_SHOW_EXECUTION_TIME:= ${SHOW_EXECUTION_TIME:= $_DEFAULT_SHOW_EXECUTION_TIME } } "
37
38
: " ${BASHUNIT_VERBOSE:= ${VERBOSE:= $_DEFAULT_VERBOSE } } "
39
+ : " ${BASHUNIT_BENCH_MODE:= ${BENCH_MODE:= $_DEFAULT_BENCH_MODE } } "
38
40
39
41
function env::is_parallel_run_enabled() {
40
42
[[ " $BASHUNIT_PARALLEL_RUN " == " true" ]]
@@ -68,6 +70,10 @@ function env::is_verbose_enabled() {
68
70
[[ " $BASHUNIT_VERBOSE " == " true" ]]
69
71
}
70
72
73
+ function env::is_bench_mode_enabled() {
74
+ [[ " $BASHUNIT_BENCH_MODE " == " true" ]]
75
+ }
76
+
71
77
function env::active_internet_connection() {
72
78
if ping -c 1 -W 3 google.com & > /dev/null; then
73
79
return 0
Original file line number Diff line number Diff line change @@ -28,19 +28,3 @@ function test_run_function_collects_results() {
28
28
assert_same " 1" " ${_BENCH_ITS[0]} "
29
29
[[ -n " ${_BENCH_AVERAGES[0]} " ]]
30
30
}
31
-
32
- function test_print_results_marks_failed_when_threshold_exceeded() {
33
- # shellcheck disable=SC1090
34
- source " $SCRIPT "
35
-
36
- _BENCH_NAMES=()
37
- _BENCH_REVS=()
38
- _BENCH_ITS=()
39
- _BENCH_AVERAGES=()
40
-
41
- benchmark::run_function bench_sleep 1 1 1
42
- local output
43
- output=" $( benchmark::print_results) "
44
-
45
- assert_contains " ${_COLOR_FAILED} " " $output "
46
- }
You can’t perform that action at this time.
0 commit comments