On 14/09/2023 23:05, Sylvestre Ledru wrote:
Hello
Currently, GNU coreutils doesn't have any test verifying the actual
output of ls --dired.
It should generate a list of position (pairs).
//DIRED// 73 82 142 152 ...
The attached patch creates 2 files and one directory and verify that we
can find their names using the position.
Well the existing test did verify --dired output offsets,
albeit constant offsets from the non varying output.
Your tests is a bit more thorough in that it
checks files with varying offsets.
I'll apply the attached in your name later,
which has the following adjustments:
- Uses "tests:" prefix in summary, as we're not changing ls logic
- Keeps lines < 80 chars wide
- Uses more functional style where possible as more concise/natural in shell
- Uses more portable $(($i + 1)) rather than $((i + 1)
- Simplifies main loop by leveraging shell `set -- ...` param handling
- Uses multibyte char in a file name for informative reasons
- Removes redundant LC_MESSAGES=C since we're handling varying output anyway
- Avoids use of awk, which is overkill for this use case
cheers,
Pádraig
From 3564e3a572b64c5384519d735dbbb88690438eae Mon Sep 17 00:00:00 2001
From: Sylvestre Ledru <sylves...@debian.org>
Date: Thu, 14 Sep 2023 23:40:08 +0200
Subject: [PATCH] tests: improve ls --dired testing
* tests/ls/dired.sh: Verify ls --dired output against varying offsets.
---
tests/ls/dired.sh | 37 ++++++++++++++++++++++++++++++++++++-
1 file changed, 36 insertions(+), 1 deletion(-)
diff --git a/tests/ls/dired.sh b/tests/ls/dired.sh
index 150fff206..417d3b594 100755
--- a/tests/ls/dired.sh
+++ b/tests/ls/dired.sh
@@ -19,9 +19,9 @@
. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
print_ver_ ls
+# Check with constant positions
mkdir dir || framework_failure_
-
LC_MESSAGES=C ls -lR --dired dir > out || fail=1
cat <<EOF > exp
dir:
@@ -32,4 +32,39 @@ EOF
compare exp out || fail=1
+
+# Check with varying positions (due to usernames etc.)
+# Also use multibyte characters to show --dired counts bytes not characters
+touch dir/1a dir/2á || framework_failure_
+mkdir -p dir/3dir || framework_failure_
+
+ls -l --dired dir | tee /tmp/pb.ls> out || fail=1
+
+dired_values=$(grep "//DIRED//" out| cut -d' ' -f2-)
+expected_files="1a 2á 3dir"
+
+dired_count=$(printf '%s\n' $dired_values | wc -l)
+expected_count=$(printf '%s\n' $expected_files | wc -l)
+
+if test "$expected_count" -ne $(($dired_count / 2)); then
+ echo "Mismatch in number of files!" \
+ "Expected: $expected_count, Found: $(($dired_count / 2))"
+ fail=1
+fi
+
+# Split the values into pairs and extract the filenames
+index=1
+set -- $dired_values
+while test "$#" -gt 0; do
+ extracted_filename=$(head -c "$2" out | tail -c +"$(($1 + 1))")
+ expected_file=$(echo $expected_files | cut -d' ' -f$index)
+ if test "$extracted_filename" != "$expected_file"; then
+ echo "Mismatch! Expected: $expected_file, Found: $extracted_filename"
+ fail=1
+ fi
+ shift; shift
+ index=$(($index + 1))
+done
+
+
Exit $fail
--
2.41.0