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.
Cheers,
Sylvestre
From a3eeb7419f8380ddaec4d2047b3ac85966ba590a Mon Sep 17 00:00:00 2001
From: Sylvestre Ledru <sylves...@debian.org>
Date: Thu, 14 Sep 2023 23:40:08 +0200
Subject: [PATCH] ls: Verify the output of ls --dired
---
tests/ls/dired.sh | 48 +++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 48 insertions(+)
diff --git a/tests/ls/dired.sh b/tests/ls/dired.sh
index 150fff206..81304aa19 100755
--- a/tests/ls/dired.sh
+++ b/tests/ls/dired.sh
@@ -32,4 +32,52 @@ EOF
compare exp out || fail=1
+touch dir/a1 || framework_failure_
+touch dir/a2 || framework_failure_
+
+mkdir -p dir/dir2 || framework_failure_
+
+LC_MESSAGES=C ls -l --dired dir > out || fail=1
+
+dired_values=$(grep "//DIRED//" out| cut -d' ' -f2-)
+
+expected_files="a1 a2 dir2"
+
+# Count the number of items in dired_values
+dired_count=0
+for item in $dired_values; do
+ dired_count=$((dired_count + 1))
+done
+
+# Count the number of items in expected_files
+expected_count=0
+for item in $expected_files; do
+ expected_count=$((expected_count + 1))
+done
+
+# Verify the size of expected_files and the number of filenames from dired_values
+if [ $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
+i=0
+for value in $dired_values; do
+ if [ $((i % 2)) -eq 0 ]; then
+ start="$value"
+ else
+ end="$value"
+ extracted_filename=$(cat out | head -c "$end" | tail -c +"$((start + 1))")
+ expected_file=$(echo $expected_files | awk -v var="$index" '{print $var}')
+ if [ "$extracted_filename" != "$expected_file" ]; then
+ echo "Mismatch! Expected: $expected_file, Found: $extracted_filename"
+ fail=1
+ fi
+ index=$((index + 1))
+ fi
+ i=$((i + 1))
+done
+
Exit $fail
--
2.39.2