Skip to content

Commit e957e0b

Browse files
authored
Merge pull request #425 from TypedDevs/refactor/bench-loading
Improve bench loading
2 parents 76c6629 + cfaecd8 commit e957e0b

File tree

3 files changed

+22
-22
lines changed

3 files changed

+22
-22
lines changed

bashunit

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ source "$BASHUNIT_ROOT_DIR/src/upgrade.sh"
2727
source "$BASHUNIT_ROOT_DIR/src/assertions.sh"
2828
source "$BASHUNIT_ROOT_DIR/src/reports.sh"
2929
source "$BASHUNIT_ROOT_DIR/src/runner.sh"
30-
source "$BASHUNIT_ROOT_DIR/src/benchmark.sh"
3130
source "$BASHUNIT_ROOT_DIR/src/bashunit.sh"
3231
source "$BASHUNIT_ROOT_DIR/src/main.sh"
3332

@@ -36,21 +35,12 @@ _FILTER=""
3635
_ARGS=()
3736
_BENCH_MODE=false
3837

39-
# Determine bench mode early so path arguments use correct pattern
40-
for arg in "$@"; do
41-
if [[ $arg == "-b" || $arg == "--bench" ]]; then
42-
export BASHUNIT_BENCH_MODE=true
43-
_BENCH_MODE=true
44-
break
45-
fi
46-
done
47-
4838
check_os::init
4939
clock::init
5040

41+
# Argument parsing
5142
while [[ $# -gt 0 ]]; do
52-
argument="$1"
53-
case $argument in
43+
case "$1" in
5444
-a|--assert)
5545
_ASSERT_FN="$2"
5646
shift
@@ -67,13 +57,15 @@ while [[ $# -gt 0 ]]; do
6757
;;
6858
--debug)
6959
OUTPUT_FILE="${2:-}"
70-
if [[ -n $OUTPUT_FILE ]]; then
60+
if [[ -n "$OUTPUT_FILE" ]]; then
7161
exec > "$OUTPUT_FILE" 2>&1
7262
fi
7363
set -x
7464
;;
7565
-b|--bench)
7666
_BENCH_MODE=true
67+
export BASHUNIT_BENCH_MODE=true
68+
source "$BASHUNIT_ROOT_DIR/src/benchmark.sh"
7769
;;
7870
-S|--stop-on-failure)
7971
export BASHUNIT_STOP_ON_FAILURE=true
@@ -90,11 +82,11 @@ while [[ $# -gt 0 ]]; do
9082
shift
9183
;;
9284
-l|--log-junit)
93-
export BASHUNIT_LOG_JUNIT="$2";
85+
export BASHUNIT_LOG_JUNIT="$2"
9486
shift
9587
;;
9688
-r|--report-html)
97-
export BASHUNIT_REPORT_HTML="$2";
89+
export BASHUNIT_REPORT_HTML="$2"
9890
shift
9991
;;
10092
-vvv|--verbose)
@@ -114,22 +106,24 @@ while [[ $# -gt 0 ]]; do
114106
;;
115107
*)
116108
pattern='*[tT]est.sh'
117-
if [[ "$_BENCH_MODE" == true ]]; then
118-
pattern='*[bB]ench.sh'
119-
fi
120-
while IFS='' read -r line; do
121-
_ARGS+=("$line");
122-
done < <(helper::find_files_recursive "$argument" "$pattern")
109+
[[ "$_BENCH_MODE" == true ]] && pattern='*[bB]ench.sh'
110+
while IFS= read -r file; do
111+
_ARGS+=("$file")
112+
done < <(helper::find_files_recursive "$1" "$pattern")
123113
;;
124114
esac
125115
shift
126116
done
127117

118+
# Optional bootstrap
128119
# shellcheck disable=SC1090
129-
[[ -f "$BASHUNIT_BOOTSTRAP" ]] && source "$BASHUNIT_BOOTSTRAP"
120+
[[ -f "${BASHUNIT_BOOTSTRAP:-}" ]] && source "$BASHUNIT_BOOTSTRAP"
130121

131122
set +eu
132123

124+
#################
125+
# Main execution
126+
#################
133127
if [[ -n "$_ASSERT_FN" ]]; then
134128
main::exec_assert "$_ASSERT_FN" "${_ARGS[@]}"
135129
elif [[ "$_BENCH_MODE" == true ]]; then

src/benchmark.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,4 +140,6 @@ function benchmark::print_results() {
140140
"$name" "$revs" "$its" "$avg" \
141141
"$_COLOR_FAILED" "$padded" "${_COLOR_DEFAULT}"
142142
done
143+
144+
console_results::print_execution_time
143145
}

tests/unit/benchmark_test.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
#!/usr/bin/env bash
22

3+
function set_up_before_script() {
4+
source "$BASHUNIT_ROOT_DIR/src/benchmark.sh"
5+
}
6+
37
function set_up() {
48
SCRIPT="tests/benchmark/fixtures/bashunit_sleep_bench.sh"
59
}

0 commit comments

Comments
 (0)