tests: cksum: add incorrect data to verify --check & --strict
[coreutils.git] / tests / ls / dired.sh
blob7c6c03bd468bce9c5946ef3b833f91ff78f42758
1 #!/bin/sh
2 # make sure --dired option works
4 # Copyright (C) 2001-2024 Free Software Foundation, Inc.
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <https://www.gnu.org/licenses/>.
19 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
20 print_ver_ ls
23 # Check with constant positions
24 mkdir dir || framework_failure_
26 cat <<EOF > exp
27 dir:
28 total 0
29 //SUBDIRED// 2 5
30 //DIRED-OPTIONS// --quoting-style=literal
31 EOF
32 for opt in '-l' '' '--hyperlink' '-x'; do
33 LC_MESSAGES=C ls $opt -R --dired dir > out || fail=1
34 compare exp out || fail=1
35 done
38 # Check with varying positions (due to usernames etc.)
39 # Also use multibyte characters to show --dired counts bytes not characters
40 touch dir/1a dir/2á || framework_failure_
41 mkdir -p dir/3dir || framework_failure_
43 ls -l --dired dir > out || fail=1
45 dired_values=$(grep "//DIRED//" out| cut -d' ' -f2-)
46 expected_files="1a 2á 3dir"
48 dired_count=$(printf '%s\n' $dired_values | wc -l)
49 expected_count=$(printf '%s\n' $expected_files | wc -l)
51 if test "$expected_count" -ne $(($dired_count / 2)); then
52 echo "Mismatch in number of files!" \
53 "Expected: $expected_count, Found: $(($dired_count / 2))"
54 fail=1
57 # Split the values into pairs and extract the filenames
58 index=1
59 set -- $dired_values
60 while test "$#" -gt 0; do
61 extracted_filename=$(head -c "$2" out | tail -c+"$(($1 + 1))")
62 expected_file=$(echo $expected_files | cut -d' ' -f$index)
63 if test "$extracted_filename" != "$expected_file"; then
64 echo "Mismatch! Expected: $expected_file, Found: $extracted_filename"
65 fail=1
67 shift; shift
68 index=$(($index + 1))
69 done
72 Exit $fail