Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show execution time #201

Merged
merged 2 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ SHOW_HEADER=
HEADER_ASCII_ART=
SIMPLE_OUTPUT=
STOP_ON_FAILURE=
SHOW_EXECUTION_TIME=
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Installer no longer needs git
- Add `assert_contains_ignore_case`
- Add `assert_equals_ignore_colors`
- Add `SHOW_EXECUTION_TIME` to environment config

## [0.9.0](https://github.com/TypedDevs/bashunit/compare/0.8.0...0.9.0) - 2023-10-15

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"vanilla-tilt": "^1.8.1"
},
"devDependencies": {
"vitepress": "^1.0.0-rc.21",
"vitepress": "^1.0.0-rc.22",
"vue": "^3.3.4"
}
}
4 changes: 4 additions & 0 deletions src/console_results.sh
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ function console_results::render_result() {
}

function console_results::print_execution_time() {
if [[ $SHOW_EXECUTION_TIME == false ]]; then
return
fi

if [[ "$_OS" != "OSX" ]]; then
_EXECUTION_TIME=$((($(date +%s%N) - "$_START_TIME") / 1000000))
printf "${_COLOR_BOLD}%s${_COLOR_DEFAULT}\n" "Time taken: ${_EXECUTION_TIME} ms"
Expand Down
1 change: 1 addition & 0 deletions src/default_env_config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ _DEFAULT_SHOW_HEADER=true
_DEFAULT_HEADER_ASCII_ART=false
_DEFAULT_SIMPLE_OUTPUT=false
_DEFAULT_STOP_ON_FAILURE=false
_DEFAULT_SHOW_EXECUTION_TIME=true
CAT="$(which cat)"
4 changes: 4 additions & 0 deletions src/env_configuration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,7 @@ fi
if [[ -z "$STOP_ON_FAILURE" ]]; then
STOP_ON_FAILURE=$_DEFAULT_STOP_ON_FAILURE
fi

if [[ -z "$SHOW_EXECUTION_TIME" ]]; then
SHOW_EXECUTION_TIME=$_DEFAULT_SHOW_EXECUTION_TIME
fi
25 changes: 24 additions & 1 deletion tests/unit/console_results_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,30 @@ function test_render_execution_time() {
return
fi

assert_matches "Time taken: [[:digit:]]+ ms" "$(console_results::render_result)"
local render_result
render_result=$(
# shellcheck disable=SC2034
SHOW_EXECUTION_TIME=true

console_results::render_result
)
assert_matches "Time taken: [[:digit:]]+ ms" "$render_result"
}

function test_not_render_execution_time() {
if [[ $_OS == "OSX" ]]; then
skip "Skipping in OSX"
return
fi

local render_result
render_result=$(
# shellcheck disable=SC2034
SHOW_EXECUTION_TIME=false

console_results::render_result
)
assert_not_matches "Time taken" "$render_result"
}

function test_not_render_execution_time_on_osx() {
Expand Down
12 changes: 6 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ estree-walker@^2.0.2:
resolved "https://registry.yarnpkg.com/estree-walker/-/estree-walker-2.0.2.tgz#52f010178c2a4c117a7757cfe942adb7d2da4cac"
integrity sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==

focus-trap@^7.5.3:
focus-trap@^7.5.4:
version "7.5.4"
resolved "https://registry.yarnpkg.com/focus-trap/-/focus-trap-7.5.4.tgz#6c4e342fe1dae6add9c2aa332a6e7a0bbd495ba2"
integrity sha512-N7kHdlgsO/v+iD/dMoJKtsSqs5Dz/dXZVebRgJw23LDk+jMi/974zyiOYDziY2JPp8xivq9BmUGwIJMiuSBi7w==
Expand Down Expand Up @@ -589,18 +589,18 @@ vite@^4.4.11:
optionalDependencies:
fsevents "~2.3.2"

vitepress@^1.0.0-rc.21:
version "1.0.0-rc.21"
resolved "https://registry.yarnpkg.com/vitepress/-/vitepress-1.0.0-rc.21.tgz#fbe1a63db86a37729c554048e4df3c606ba0d803"
integrity sha512-eHX057NgAqmrj6FIqh7Sqsbk/kftrFMBUpCKjuQIZ+c+bYTbmzXsXrHSbT5b4WWy4vLx1993a+H3wIRy2dHi8g==
vitepress@^1.0.0-rc.22:
version "1.0.0-rc.22"
resolved "https://registry.yarnpkg.com/vitepress/-/vitepress-1.0.0-rc.22.tgz#9855edc0991a57cf88561e790b0b35ddc447fbf0"
integrity sha512-n7le5iikCFgWMuX7sKfzDGJGlrsYQ5trG3S97BghNz2alOTr4Xp+GrB6ShwogUTX9gNgeNmrACjokhW55LNeBA==
dependencies:
"@docsearch/css" "^3.5.2"
"@docsearch/js" "^3.5.2"
"@types/markdown-it" "^13.0.2"
"@vue/devtools-api" "^6.5.1"
"@vueuse/core" "^10.5.0"
"@vueuse/integrations" "^10.5.0"
focus-trap "^7.5.3"
focus-trap "^7.5.4"
mark.js "8.11.1"
minisearch "^6.1.0"
shiki "^0.14.5"
Expand Down