summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKerin Millar <kfm@plushkava.net>2024-08-06 06:47:42 +0100
committerSam James <sam@gentoo.org>2024-08-11 11:10:54 +0100
commit1a39f2c057cd0973910043bd8217e861faa99212 (patch)
tree95a64bf9321bde80144336ab8f1273cabca3e005
parenttest-functions: test the oldest() function (diff)
downloadgentoo-functions-1a39f2c057cd0973910043bd8217e861faa99212.tar.gz
gentoo-functions-1a39f2c057cd0973910043bd8217e861faa99212.tar.bz2
gentoo-functions-1a39f2c057cd0973910043bd8217e861faa99212.zip
test-functions: refactor the newest() test case
Rework the test case for the newest() function in accordance with the recently added test case for the oldest() function. The resulting code is more pleasant to read and maintain. In doing so, an obscure bug has been addressed. Hitherto, an empty NUL-terminated record had erroneously being conveyed to newest() for just one of the 28 individual sub-tests being conducted. Signed-off-by: Kerin Millar <kfm@plushkava.net> Signed-off-by: Sam James <sam@gentoo.org>
-rwxr-xr-xtest-functions46
1 files changed, 29 insertions, 17 deletions
diff --git a/test-functions b/test-functions
index d872a49..2f831c8 100755
--- a/test-functions
+++ b/test-functions
@@ -435,28 +435,31 @@ test_newest() {
eq 0 newer/file newer/file \
eq 0 newer/file non-existent \
eq 0 newer/file older/file \
+ eq 0 newer/file older/file \
eq 0 non-existent newer/file \
eq 0 older/file newer/file \
+ eq 0 older/file newer/file \
\
eq 0 older/file N/A \
eq 0 older/file older/file \
eq 0 older/file non-existent \
- ge 1 newer/file older/file \
eq 0 non-existent older/file \
- ge 1 older/file newer/file
callback() {
shift
test_description="newest $(quote_args "$@")"
row=$(( row + 1 ))
true |
- if [ "${row}" -le 2 ]; then
- newest "$@"
- elif [ "${row}" -le 8 ]; then
- test "$(newest "$@")" = "newer/file"
- else
- test "$(newest "$@")" = "older/file"
- fi
+ case ${row} in
+ [1-2])
+ newest "$@"
+ ;;
+ [3-9]|10)
+ test "$(newest "$@")" = "newer/file"
+ ;;
+ *)
+ test "$(newest "$@")" = "older/file"
+ esac
}
row=0
@@ -464,16 +467,25 @@ test_newest() {
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"
+ if [ "$#" -eq 0 ]; then
+ test_description=": | newest"
else
- test "$(newest)" = "older/file"
+ test_description="printf '%s\\0' $(quote_args "$@") | newest"
fi
+ row=$(( row + 1 ))
+ {
+ test "$#" -gt 0 && printf '%s\0' "$@"
+ } |
+ case ${row} in
+ [1-2])
+ newest
+ ;;
+ [3-9]|10)
+ test "$(newest)" = "newer/file"
+ ;;
+ *)
+ test "$(newest)" = "older/file"
+ esac
}
row=0