diff options
author | Shuiqing Zhou <zhoushuiqing321@outlook.com> | 2022-06-23 15:17:23 +0800 |
---|---|---|
committer | Bernhard Voelker <mail@bernhard-voelker.de> | 2022-08-09 23:45:57 +0200 |
commit | 3c2d824ef5467c5b2adc711c175b74237b3cd018 (patch) | |
tree | 44f413f518c8286ebdac4ba8ac307658f4373403 | |
parent | e5c697eccf5c063b9b9ffe43b03e23ddd7532af1 (diff) | |
download | findutils-3c2d824ef5467c5b2adc711c175b74237b3cd018.tar.gz |
tests: add tests for the 'find -newer' family
* tests/find/newer.sh: Add to improve test coverage.
* tests/local.mk (all_tests): Reference the test.
Co-authored-by: Bernhard Voelker <mail@bernhard-voelker.de>
Copyright-paperwork-exempt: Yes
-rwxr-xr-x | tests/find/newer.sh | 65 | ||||
-rw-r--r-- | tests/local.mk | 1 |
2 files changed, 66 insertions, 0 deletions
diff --git a/tests/find/newer.sh b/tests/find/newer.sh new file mode 100755 index 00000000..e7659239 --- /dev/null +++ b/tests/find/newer.sh @@ -0,0 +1,65 @@ +#!/bin/sh +# Exercise -anewer -cnewer -newer -newerXY. + +# Copyright (C) 2022 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; fu_path_prepend_ +print_ver_ find + +# Verify the -newer test family - omitting birth time as support for this +# is not common enough yet. + +# Although 'touch -t' is standardized by POSIX, that would not set the ctime +# to the given timestamp. Therefore, we have to use sleep(1) to prepare the +# test files 1..3. +touch file1 \ + && sleep 1 \ + && touch file2 \ + && sleep 1 \ + && touch file3 \ + || skip_ "creating files with different timestamp failed" + +# Stat the test files for debug purposes. +stat file? || : ignored + +echo "./file3" > exp || framework_failure_ + +# Exercise -new options using a reference file. +for x in \ + -anewer -cnewer -newer \ + -neweraa -newerac -neweram \ + -newerca -newercc -newercm \ + -newerma -newermc -newermm \ + ; do + rm -f out || framework_failure_ + find . $x file2 -name 'file*' > out || fail=1 + compare exp out || fail=1 +done + +# Exercise -new options using a reference timestamp (if possible). +tref="$( stat -c '%y' file2 )" || tref='' + +if test "${tref}"; then + for x in -newerat -newerct -newermt; do + rm -f out || framework_failure_ + find . $x "${tref}" -name 'file*' > out || fail=1 + compare exp out || fail=1 + done +else + echo "Determining reference timestamp failed - skipping this part." +fi + +Exit $fail diff --git a/tests/local.mk b/tests/local.mk index 4e8efd41..739936c3 100644 --- a/tests/local.mk +++ b/tests/local.mk @@ -120,6 +120,7 @@ all_tests = \ tests/find/refuse-noop.sh \ tests/find/debug-missing-arg.sh \ tests/find/used.sh \ + tests/find/newer.sh \ tests/xargs/conflicting_opts.sh \ tests/xargs/verbose-quote.sh \ $(all_root_tests) |