tests: improve ls --dired testing

* tests/ls/dired.sh: Verify ls --dired output against varying offsets.
This commit is contained in:
Sylvestre Ledru
2023-09-14 23:40:08 +02:00
committed by Pádraig Brady
parent 3b0f5b9971
commit 3564e3a572

View File

@@ -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