-
Notifications
You must be signed in to change notification settings - Fork 2.3k
command duration fix #2366
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
Merged
Merged
command duration fix #2366
Changes from all commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
0119368
Delete preexec vendor
BarbUk 027b7ae
Squashed 'vendor/github.com/rcaloras/bash-preexec/' content from comm…
BarbUk b509d72
Add "preexec" from "https://github.com/rcaloras/bash-preexec@0.6.0"
BarbUk 7ab0074
Update precommit
BarbUk ee821b3
Rework command duration plugin to handle locale with . or , and remov…
BarbUk f630441
Sh format
BarbUk b42c3ac
Revert "Update precommit"
BarbUk 1857412
Fix cmd-returned-notify.plugin.bash
BarbUk 83f11a8
Fix _shell_duration_en function call, restore original variable names
BarbUk 64ec7e7
With recent version of bash preexec set PROMPT_COMMAND as an array
BarbUk 4c60358
But leave test for old macos version of bash
BarbUk 5ae5522
New version of preexec add a :
BarbUk f689001
Fix preexec bats tests shellcheck errors
BarbUk d65288f
, and . are not the only possibilities of decimal_point
BarbUk 2339683
Ignore warning for vendors bats test files
BarbUk 3e3ddf3
Add default for COMMAND_DURATION_START_SECONDS
BarbUk 7373708
Fix shellcheck SC1091 for vendor bats tests
BarbUk 9e88c2a
Ignore last shellcheck error in vendor bats tests
BarbUk 1fb6e65
Add more information about the reason of this change
BarbUk f775bbd
Get the current time from command_duration lib function
BarbUk 53de05d
Work with microseconds, truncate the output to display
BarbUk 4d86661
Only calculate and display microseconds if precision > 0
BarbUk ee1c783
Add documentation about COMMAND_DURATION_PRECISION
BarbUk 42b8086
Handle case with leading 0 in microseconds
BarbUk 5ef3b70
Handle case with leading 0 in microseconds
BarbUk 9e5f7ce
No quote for integer local var
BarbUk c0f2a5d
Add tests
BarbUk 964e9bc
Disable shellcheck false positive for bats tests
BarbUk 67cb1b2
local -> locale
BarbUk 3c39331
Rephrase
BarbUk 275c8d3
overide -> override
BarbUk 910dbed
Fix phrasing
BarbUk 43f1bd4
Add tests when EPOCHREALTIME is not available
BarbUk b848e5b
Uses string instead of int
BarbUk 71a8a71
Reintroduce paste documentation to keep context about this change
BarbUk dd80054
Remove unused code branch
BarbUk ed314d5
Add test with precision 0 and microseconds time
BarbUk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| # shellcheck shell=bats | ||
| # shellcheck disable=2034,2329 | ||
|
|
||
| load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash" | ||
|
|
||
| function local_setup_file() { | ||
| setup_libs "command_duration" | ||
| } | ||
|
|
||
| @test "command_duration: _command_duration_current_time" { | ||
| run _command_duration_current_time | ||
| assert_success | ||
| assert_output --regexp '^[0-9]+(\.[0-9]+)?$' | ||
| } | ||
|
|
||
| @test "command_duration: _command_duration_current_time without EPOCHREALTIME" { | ||
| _command_duration_current_time_no_epoch() { | ||
| local EPOCHREALTIME | ||
| unset EPOCHREALTIME | ||
| local SECONDS=123 | ||
| _command_duration_current_time | ||
| } | ||
| run _command_duration_current_time_no_epoch | ||
| assert_success | ||
| assert_output "123" | ||
| } | ||
|
|
||
| @test "command_duration: _command_duration_pre_exec" { | ||
| _command_duration_pre_exec | ||
| assert [ -n "$COMMAND_DURATION_START_SECONDS" ] | ||
| } | ||
|
|
||
| @test "command_duration: _command_duration_pre_cmd" { | ||
| COMMAND_DURATION_START_SECONDS="1234.567" | ||
| _command_duration_pre_cmd | ||
| assert [ -z "$COMMAND_DURATION_START_SECONDS" ] | ||
| } | ||
|
|
||
| @test "command_duration: _dynamic_clock_icon" { | ||
| _dynamic_clock_icon 1 | ||
| assert [ -n "$COMMAND_DURATION_ICON" ] | ||
| } | ||
|
|
||
| @test "command_duration: _command_duration disabled" { | ||
| unset BASH_IT_COMMAND_DURATION | ||
| COMMAND_DURATION_START_SECONDS="100" | ||
| run _command_duration | ||
| assert_output "" | ||
| } | ||
|
|
||
| @test "command_duration: _command_duration no start time" { | ||
| BASH_IT_COMMAND_DURATION=true | ||
| unset COMMAND_DURATION_START_SECONDS | ||
| run _command_duration | ||
| assert_output "" | ||
| } | ||
|
|
||
| @test "command_duration: _command_duration below threshold" { | ||
| BASH_IT_COMMAND_DURATION=true | ||
| COMMAND_DURATION_MIN_SECONDS=2 | ||
| # Mock _command_duration_current_time | ||
| _command_duration_current_time() { echo 101; } | ||
|
||
| COMMAND_DURATION_START_SECONDS=100 | ||
| run _command_duration | ||
| assert_output "" | ||
| } | ||
|
|
||
| @test "command_duration: _command_duration above threshold (seconds)" { | ||
| BASH_IT_COMMAND_DURATION=true | ||
| COMMAND_DURATION_MIN_SECONDS=1 | ||
| COMMAND_DURATION_PRECISION=0 | ||
| # Mock _command_duration_current_time | ||
| _command_duration_current_time() { echo 105; } | ||
|
||
| COMMAND_DURATION_START_SECONDS=100 | ||
| run _command_duration | ||
| assert_output --regexp ".* 5s$" | ||
| } | ||
|
|
||
| @test "command_duration: _command_duration precision 0 with microseconds time" { | ||
| BASH_IT_COMMAND_DURATION=true | ||
| COMMAND_DURATION_MIN_SECONDS=1 | ||
| COMMAND_DURATION_PRECISION=0 | ||
| # Mock _command_duration_current_time | ||
| _command_duration_current_time() { echo 105.600005; } | ||
| COMMAND_DURATION_START_SECONDS=100.200007 | ||
| run _command_duration | ||
| assert_output --regexp ".* 5s$" | ||
| } | ||
|
|
||
| @test "command_duration: _command_duration with precision" { | ||
| BASH_IT_COMMAND_DURATION=true | ||
| COMMAND_DURATION_MIN_SECONDS=1 | ||
| COMMAND_DURATION_PRECISION=1 | ||
| # Mock _command_duration_current_time | ||
| _command_duration_current_time() { echo 105.600000; } | ||
|
||
| COMMAND_DURATION_START_SECONDS=100.200000 | ||
| run _command_duration | ||
| assert_output --regexp ".* 5.4s$" | ||
| } | ||
|
|
||
| @test "command_duration: _command_duration with minutes" { | ||
| BASH_IT_COMMAND_DURATION=true | ||
| COMMAND_DURATION_MIN_SECONDS=1 | ||
| # Mock _command_duration_current_time | ||
| _command_duration_current_time() { echo 200; } | ||
|
||
| COMMAND_DURATION_START_SECONDS=70 | ||
| run _command_duration | ||
| assert_output --regexp ".* 2m 10s$" | ||
| } | ||
|
|
||
| @test "command_duration: _command_duration with microsecond rollover" { | ||
| BASH_IT_COMMAND_DURATION=true | ||
| COMMAND_DURATION_MIN_SECONDS=0 | ||
| COMMAND_DURATION_PRECISION=1 | ||
| # Mock _command_duration_current_time | ||
| # 105.1 - 100.2 = 4.9 | ||
| _command_duration_current_time() { echo 105.100000; } | ||
|
||
| COMMAND_DURATION_START_SECONDS=100.200000 | ||
| run _command_duration | ||
| assert_output --regexp ".* 4.9s$" | ||
| } | ||
|
|
||
| @test "command_duration: _command_duration with precision and leading zeros" { | ||
| BASH_IT_COMMAND_DURATION=true | ||
|
||
| COMMAND_DURATION_MIN_SECONDS=0 | ||
|
||
| COMMAND_DURATION_PRECISION=3 | ||
|
||
| COMMAND_DURATION_START_SECONDS=100.001000 | ||
| _command_duration_current_time() { echo 105.002000; } | ||
| run _command_duration | ||
| assert_output --regexp ".* 5.001s$" | ||
| } | ||
|
|
||
| @test "command_duration: _command_duration without EPOCHREALTIME (SECONDS only)" { | ||
| BASH_IT_COMMAND_DURATION=true | ||
| COMMAND_DURATION_MIN_SECONDS=1 | ||
| COMMAND_DURATION_PRECISION=1 | ||
| # Mock _command_duration_current_time to return integer (like SECONDS would) | ||
| _command_duration_current_time() { echo 105; } | ||
| COMMAND_DURATION_START_SECONDS=100 | ||
| run _command_duration | ||
| assert_output --regexp ".* 5s$" | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
vendor/github.com/rcaloras/bash-preexec/.github/workflows/bats.yaml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.