-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ensure that bash v3 tests run with bash v3
this fixes our ability to catch the error from 3b85eb1 this is necessary as the movement from sourcing to commands causes `env` to be used, which will reset to the preferred bash rather than the active bash. other changes: - confirm: tests no longer hang indefinitely on macos sonoma - read-key: fix timeouts for bash v3 - read-key: fix special character detection on bash v3 - is-number: it now works on decimal numbers, and supports bash v3 - is-integer: it now supports bash v3 - bash.bash: fix `get_read_decimal_timeout` always returning 1 - bash.bash: fix uppercase_first_letter and lowercase_string on bash v3 - stdinargs: fix empty timeouts causing error
- Loading branch information
Showing
9 changed files
with
229 additions
and
74 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 |
---|---|---|
@@ -1,14 +1,64 @@ | ||
#!/usr/bin/env bash | ||
|
||
function is_number_test() ( | ||
source "$DOROTHY/sources/bash.bash" | ||
echo-segment --h1="TEST: $0" | ||
|
||
eval-tester --name='zero' --status=0 \ | ||
-- is-number 0 | ||
|
||
eval-tester --name='one' --status=0 \ | ||
-- is-number 1 | ||
|
||
eval-tester --name='ten' --status=0 \ | ||
-- is-number 10 | ||
|
||
eval-tester --name='decimal' --status=0 \ | ||
-- is-number 0.1 | ||
|
||
eval-tester --name='triple decimal' --status=1 \ | ||
-- is-number 1.1.1 | ||
|
||
eval-tester --name='negative' --status=0 \ | ||
-- is-number -1 | ||
|
||
eval-tester --name='negative 10' --status=0 \ | ||
-- is-number -10 | ||
|
||
eval-tester --name='negative decimal' --status=0 \ | ||
-- is-number -1.1 | ||
|
||
eval-tester --name='negative triple decimal' --status=1 \ | ||
-- is-number -1.1.1 | ||
|
||
eval-tester --name='empty' --status=1 \ | ||
-- is-number '' | ||
|
||
eval-tester --name='letter' --status=1 \ | ||
-- is-number 'a' | ||
|
||
eval-tester --name='combo' --status=1 \ | ||
-- is-number '-0a' | ||
|
||
echo-segment --g1="TEST: $0" | ||
return 0 | ||
) | ||
function is_number() ( | ||
source "$DOROTHY/sources/bash.bash" | ||
|
||
# hide stdout and stderr | ||
# trunk-ignore(shellcheck/SC2219) | ||
(test "$1" = '0' || let "$1") &>/dev/null | ||
# if [[ $1 == ?(-)+([0-9])?([.]+([0-9])) ]]; then # does not work in bash v3 | ||
if [[ $1 =~ ^[-]?[0-9]+(\.[0-9]+)?$ ]]; then # does not work in bash v3 | ||
return 0 | ||
else | ||
return 1 | ||
fi | ||
) | ||
|
||
# fire if invoked standalone | ||
if test "$0" = "${BASH_SOURCE[0]}"; then | ||
is_number "$@" | ||
if test "$*" = '--test'; then | ||
is_number_test | ||
else | ||
is_number "$@" | ||
fi | ||
fi |
Oops, something went wrong.