-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
echo-trim-empty-lines => echo-trim-zero-length
echo-trim-zero-length: only eliminates zero length lines, which is all that it was needed for echo-lines: don't output if there is no input expand-path: add tests, move echo-trim-zero-length usage into expand-path-* expand-path-*: add echo-trim-zero-length unziptar: remove debug-bash usage, as we know where the issue was stdinargs: add IFS='' so that non-zero-length but otherwise empty lines are captured
- Loading branch information
Showing
9 changed files
with
114 additions
and
60 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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#!/usr/bin/env bash | ||
|
||
function echo_trim_zero_length_test() ( | ||
source "$DOROTHY/sources/bash.bash" | ||
source "$(type -P eval-tester)" | ||
echo-segment --h1="TEST: $0" | ||
|
||
local inputs=('a' '' 'b' ' ' 'c' 'null' 'd' 'false') | ||
local expected=$'a\nb\n \nc\nnull\nd\nfalse' | ||
|
||
eval_tester --name='trimming arguments' --stdout="$expected" \ | ||
-- echo-trim-zero-length "${inputs[@]}" | ||
|
||
function trim_stdin { | ||
echo-lines "${inputs[@]}" | echo-trim-zero-length | ||
} | ||
eval_tester --name='trimming arguments' --stdout="$expected" \ | ||
-- trim_stdin | ||
|
||
echo-segment --g1="TEST: $0" | ||
return 0 | ||
) | ||
function echo_trim_zero_length() ( | ||
source "$DOROTHY/sources/bash.bash" | ||
|
||
function help { | ||
cat <<-EOF >/dev/stderr | ||
ABOUT: | ||
Trim inputs that are zero-length. | ||
USAGE: | ||
echo-trim-zero-length <...input> | ||
echo-lines <...input> | echo-trim-zero-length | ||
EXAMPLE: | ||
echo-trim-zero-length 'a' '' 'b' ' ' 'c' 'null' 'd' 'false' | ||
a | ||
b | ||
c | ||
null | ||
d | ||
false | ||
echo-lines 'a' '' 'b' ' ' 'c' 'null' 'd' 'false' | echo-trim-zero-length | ||
a | ||
b | ||
c | ||
null | ||
d | ||
false | ||
EOF | ||
return 22 # EINVAL 22 Invalid argument | ||
} | ||
|
||
function on_input { | ||
if test -n "$1"; then | ||
print_line "$1" | ||
fi | ||
} | ||
|
||
source "$DOROTHY/sources/stdinargs.bash" | ||
) | ||
|
||
# fire if invoked standalone | ||
if test "$0" = "${BASH_SOURCE[0]}"; then | ||
if test "$*" = '--test'; then | ||
echo_trim_zero_length_test | ||
else | ||
echo_trim_zero_length "$@" | ||
fi | ||
fi |
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,18 +1,40 @@ | ||
#!/usr/bin/env bash | ||
|
||
function expand_path_test() ( | ||
source "$DOROTHY/sources/bash.bash" | ||
source "$(type -P eval-tester)" | ||
echo-segment --h1="TEST: $0" | ||
|
||
# test fix for: https://github.com/bevry/dorothy/commit/fcaee87405eccc1b6cfa4b78c2bd3215c74537f0#diff-c2bcdf7f33a51745a999d7b87b788dedbad76901c10e74511e21463f5815a84f | ||
function test_nonexistent_path { | ||
local paths | ||
mapfile -t paths < <(expand-path '/i/do/not exist*') | ||
print_line "${#paths[@]}" | ||
} | ||
|
||
eval_tester --name='test non-existent path' --stdout='0' \ | ||
-- test_nonexistent_path | ||
|
||
echo-segment --g1="TEST: $0" | ||
return 0 | ||
) | ||
function expand_path() ( | ||
source "$DOROTHY/sources/bash.bash" | ||
|
||
# using zsh then bash, works around macos which has old bash, but new zsh | ||
# so this is needed so setup-paths-commands can do its thing | ||
if type -P zsh &>/dev/null; then | ||
expand-path-zsh "$@" 2>/dev/null | echo-wait | echo-trim-empty-lines | ||
expand-path-zsh "$@" 2>/dev/null | ||
else | ||
expand-path-bash "$@" 2>/dev/null | echo-wait | echo-trim-empty-lines | ||
expand-path-bash "$@" 2>/dev/null | ||
fi | ||
) | ||
|
||
# fire if invoked standalone | ||
if test "$0" = "${BASH_SOURCE[0]}"; then | ||
expand_path "$@" | ||
if test "$*" = '--test'; then | ||
expand_path_test | ||
else | ||
expand_path "$@" | ||
fi | ||
fi |
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