* tests/find/ls-format-file.sh: check the output of -ls against the
output of a -printf format which should generate the same
output (though only for files which aren't symlinks or device nodes).
This serves as a guard against accidental changes to field widths. If
an output field is incorrect, carry out the remaining test steps
anyway (but the test still fails). Remove redundant sanity-checks on
the properties of the test file. These were useful during development
of the test but for someone investigating a test failure, they are
distracting noise. Add a check for the block count field.
* tests/find/ls-format-symlink.sh: add a similar check. If an output
field is incorrect, carry out the remaining test steps anyway (but the
test still fails). Eliminate redundant test of the "a -> b" part of
the output. Remove redundant sanity-checks on the properties of the
test file. Skip the test if we cannot create a symbolic link.
---
tests/find/ls-format-file.sh | 47 ++++++++++++++++--
tests/find/ls-format-symlink.sh | 86 +++++++++++++++++++++++----------
2 files changed, 103 insertions(+), 30 deletions(-)
diff --git a/tests/find/ls-format-file.sh b/tests/find/ls-format-file.sh
index ec9f2331..cee3737e 100755
--- a/tests/find/ls-format-file.sh
+++ b/tests/find/ls-format-file.sh
@@ -28,6 +28,11 @@ LC_ALL=C
export LC_ALL
unset LANG
+# We set fail to a nonzero value to indicate that one of the test
+# steps showed a difference between the expected and actual behaviour
+# (that is, the test failed).
+fail=0
+
user_owner="$( id -u -n )"
if [ -z "${user_owner}" ]
then
@@ -149,18 +154,19 @@ fi
grep -e " ${testfile}"'$' < output.txt >/dev/null || fail_ "find -ls output
should end with the file name"
-# The output is supposed to look like this:
+# The output is supposed to look like this (though we've removed
+# consecutive spaces here):
# st_ino st_blocks
# | | symbolic st_mode
# | | | st_nlink
# | | | | Username corresponding to st_uid
-# | | | | | Group corresponding to st_gid
+# | | | | | Group name corresponding to st_gid
# | | | | | | Size in bytes
# | | | | | | | st_mtime
# | | | | | | | | file name
# | | | | | | | | |
-# 4485432 1 -rw------- 1 james james 765 Mar 14 1992 lsme
+# 4485432 1 -rw------- 1 james group 765 Mar 14 1992 lsme
awk < output.txt \
-v ME="${ME_}" \
@@ -283,4 +289,37 @@ END {
'
rv=$?
echo "Awk exit status was ${rv}"
-Exit "${rv}"
+if [ "${rv}" -ne 0 ]
+then
+ warn_ "${ME_}: one of the field values was incorrect (see above) so the
test will eventually fail, but we will carry out the remaining test steps
anyway"
+ fail=1
+fi
+
+
+###############################################################################
+# Checks on the output generated by -ls, including the spaces between
+# fields. If these tests break, this may indicate a bug in find, or
+# alternatively a deliberate change to the spacing of the output
+# (e.g. a deliberate change to lib/listfile.c). If you are
+# deliberately changing the output spacing, it is OK to update the
+# tests below to reflect this. If not, this is likely an
+# unintentional change which you should investigate.
+###############################################################################
+
+# Generate "by hand" in the file printf-output.txt some output which
+# should match the output of -ls.
+rm -f -- printf-output.txt
+if ! find "${testfile}" -printf '%9i %6b %M %3n %-8u %-8g %8s %3Tb %2Td %5TY
%p\n' > printf-output.txt
+then
+ framework_failure_ "unable to create printf-output.txt"
+fi
+
+if ! compare printf-output.txt output.txt
+then
+ # The detailed nature of the problem should already be visible in
+ # the diff output we just emitted into the log.
+ fail=1
+ warn_ "${ME_}: the output of the -ls action seems to be incorrect"
+fi
+
+Exit "${fail}"
diff --git a/tests/find/ls-format-symlink.sh b/tests/find/ls-format-symlink.sh
index 6bf17599..c240ac47 100755
--- a/tests/find/ls-format-symlink.sh
+++ b/tests/find/ls-format-symlink.sh
@@ -28,17 +28,29 @@ LC_ALL=C
export LC_ALL
unset LANG
+# We set fail to a nonzero value to indicate that one of the test
+# steps showed a difference between the expected and actual behaviour
+# (that is, the test failed).
+fail=0
+
# Create a test file with some known properties.
umask 077
+# Note that symlink_target and symlink should not contain characters
+# which are special to find -printf. It's best also to avoid
+# characters which are special to the shell, too.
symlink_target='target'
symlink='symlink'
+
filesize=765
rm -f -- "${symlink_target}" "${symlink}"
if ! ( yes non-empty | dd bs=1 count="${filesize}" of="${symlink_target}" )
2>/dev/null
then
framework_failure_ "failed to create test file ${symlink_target}"
fi
-ln -s "${symlink_target}" "${symlink}"
+if ! ln -s "${symlink_target}" "${symlink}"
+then
+ skip_ "unable to create a symbolic link"
+fi
# Any specific time for the test will do as long as it is far enough
# away from now for ls to display the year. This happens to be the
@@ -53,32 +65,12 @@ then
framework_failure_ "failed to set mtime of ${symlink}"
fi
-# Check the actual properties of the file (to verify that the setup
-# was successful).
-check_prop() {
- printf_fmt="${1}"
- expected="${2}"
- got="$( find "${symlink}" -printf "${printf_fmt}" )"
-
- if [ "${expected}" != "${got}" ]
- then
- framework_failure_ "expected test file ${symlink} to have -printf
'${printf_fmt}\n' result '${expected}' but we got '${got}'"
- fi
-}
-
-check_prop '%M' "lrwxrwxrwx" # file mode
-check_prop '%n' 1 # link count
-check_prop '%s' 6 # size in bytes (length of "target")
-check_prop '%TF' "1999-12-31" # modification date
-check_prop '%TH:%TM' "23:59" # modification time (without seconds)
-
# Remember the file's inode number and block count.
inum="$( find "${symlink}" -printf '%i\n')"
# The system's value of BLOCKSIZE is implementation-dependent
# ("ls -k" forces ls to use 1KiB blocks, but -ls is intended
# to look like the output of ls -dils, without -k)
-
# Generate the ls output.
find "${symlink}" -ls > output.txt
@@ -88,15 +80,20 @@ cat output.txt
echo "same thing in od -c format:"
od -c output.txt
-# Determine whether there is a trailing newline. If not, output.txt
-# is not actually a text file and some other checks may not work the
-# way we expect.
+# Determine whether there is a trailing newline.
if [ $(sed -n -e '$ s/.*//p' < output.txt | wc -c) -eq 0 ]
then
+ # If we get to here, output.txt is not actually a text file and
+ # some other checks may not work the way we expect, so we stop
+ # now.
fail_ "find -ls output does not end in newline"
fi
-grep -e ' symlink -> target$' < output.txt >/dev/null || fail_ "find -ls
output should end with symlink -> target"
+###############################################################################
+# Checks on the output fields generated by -ls, ignoring differences in the
+# number of spaces between fields. If these tests break, this likely indicates
+# a bug in find.
+###############################################################################
# The output is supposed to look like this:
@@ -230,4 +227,41 @@ END {
'
rv=$?
echo "Awk exit status was ${rv}"
-Exit "${rv}"
+if [ "${rv}" -ne 0 ]
+then
+ warn_ "${ME_}: one of the field values was incorrect (see above) so the
test will eventually fail, but we will carry out the remaining test steps
anyway"
+ fail=1
+fi
+
+
+###############################################################################
+# Checks on the output generated by -ls, including the spaces between
+# fields. If these tests break, this may indicate a bug in find, or
+# alternatively a deliberate change to the spacing of the output
+# (e.g. a deliberate change to lib/listfile.c). If you are
+# deliberately changing the output spacing, it is OK to update the
+# tests below to reflect this. If not, this is likely an
+# unintentional change which you should investigate.
+###############################################################################
+
+# Generate "by hand" in the file printf-output.txt some output which
+# should match the output of -ls. Take care when updating the format
+# string, because it is interpreted both by the shell (as it uses
+# double-quotes) then also by find -printf.
+rm -f -- printf-output.txt
+if ! find "${symlink}" \
+ -printf "%9i %6b %M %3n %-8u %-8g %8s %3Tb %2Td %5TY ${symlink} ->
${symlink_target}\n" \
+ > printf-output.txt
+then
+ framework_failure_ "unable to create printf-output.txt"
+fi
+
+if ! compare printf-output.txt output.txt
+then
+ # The detailed nature of the problem should already be visible in
+ # the diff output we just emitted into the log.
+ fail=1
+ warn_ "${ME_}: the output of the -ls action seems to be incorrect"
+fi
+
+Exit "${fail}"
--
2.47.3