diff options
author | Kerin Millar <kfm@plushkava.net> | 2024-08-06 05:58:03 +0100 |
---|---|---|
committer | Sam James <sam@gentoo.org> | 2024-08-11 11:10:53 +0100 |
commit | 13729f370881557f8f7c21692732d093ce5b06cd (patch) | |
tree | 5fa8f4746637eaef93101bd771d2fcd21e9bec9a | |
parent | test_functions: check that genfun_time is greater than -1 (diff) | |
download | gentoo-functions-13729f370881557f8f7c21692732d093ce5b06cd.tar.gz gentoo-functions-13729f370881557f8f7c21692732d093ce5b06cd.tar.bz2 gentoo-functions-13729f370881557f8f7c21692732d093ce5b06cd.zip |
Make _select_by_mtime() work correctly for paths read from STDIN
The _select_by_mtime() function is called by both newest() and oldest().
Pathnames may be specified as positional parameters or as NUL-separated
records to be read from the standard input. Unfortunately, the latter
interface does not work at all. Rectify this by checking whether the
number of parameters is greater then 0, rather than greater than or
equal to 0.
Also, extend the existing test case in such a way that the interface in
question is tested.
Signed-off-by: Kerin Millar <kfm@plushkava.net>
Signed-off-by: Sam James <sam@gentoo.org>
-rw-r--r-- | functions.sh | 2 | ||||
-rwxr-xr-x | test-functions | 20 |
2 files changed, 19 insertions, 3 deletions
diff --git a/functions.sh b/functions.sh index 561a98f..177dad8 100644 --- a/functions.sh +++ b/functions.sh @@ -680,7 +680,7 @@ _select_by_mtime() sort_opt=$1 shift - if [ "$#" -ge 0 ]; then + if [ "$#" -gt 0 ]; then printf '%s\0' "$@" else cat diff --git a/test-functions b/test-functions index 940f07d..989cc4c 100755 --- a/test-functions +++ b/test-functions @@ -445,8 +445,6 @@ test_newest() { eq 0 non-existent older/file \ ge 1 older/file newer/file - row=0 - callback() { shift test_description="newest $(quote_args "$@")" @@ -461,6 +459,24 @@ test_newest() { fi } + row=0 + iterate_tests 4 "$@" + + callback() { + shift + test_description="printf '%s\\0' $(quote_args "$@") | newest" + row=$(( row + 1 )) + printf '%s\0' "$@" | + if [ "${row}" -le 2 ]; then + newest + elif [ "${row}" -le 8 ]; then + test "$(newest)" = "newer/file" + else + test "$(newest)" = "older/file" + fi + } + + row=0 iterate_tests 4 "$@" } |