summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorPádraig Brady <P@draigBrady.com>2022-09-04 19:59:25 +0100
committerPádraig Brady <P@draigBrady.com>2023-03-13 16:20:38 +0000
commit47988fad885e8129f9dc36f0ed4d63375de23603 (patch)
tree1eb1b78b48bb2472081c56c7a3a35208889d2e26 /tests
parent1ac1d6def69e1faaefd1b41492764ef27c90b7a5 (diff)
downloadcoreutils-47988fad885e8129f9dc36f0ed4d63375de23603.tar.gz
ls: --color: honor separate sequences for extension cases
Following on from commit v8.29-45-g24053fbd8 which unconditionally used case insensitive extension matching, support selective case sensitive matching when there are separate extension cases defined with different display sequences. * src/dircolors.hin: Document how file name suffixes are matched. Note this is displayed with `dircolors --print-database` which the texi info recommends to use for details. * src/ls.c (parse_ls_color): Postprocess the list to mark entries for case sensitive matching, and also adjust so that unmatchable entries are more quickly ignored. (get_color_indicator): Use exact matching rather than case insensitive matching if so marked. * tests/ls/color-ext.sh: Add test cases. * NEWS: Mention the change in behavior. Addresses https://bugs.gnu.org/33123
Diffstat (limited to 'tests')
-rwxr-xr-xtests/ls/color-ext.sh46
1 files changed, 45 insertions, 1 deletions
diff --git a/tests/ls/color-ext.sh b/tests/ls/color-ext.sh
index 091895c9f..ab045ec6a 100755
--- a/tests/ls/color-ext.sh
+++ b/tests/ls/color-ext.sh
@@ -20,13 +20,16 @@
print_ver_ ls
working_umask_or_skip_
-touch img1.jpg IMG2.JPG file1.z file2.Z || framework_failure_
+touch img1.jpg IMG2.JPG img3.JpG file1.z file2.Z || framework_failure_
code_jpg='01;35'
+code_JPG='01;35;46'
code_z='01;31'
c0=$(printf '\033[0m')
c_jpg=$(printf '\033[%sm' $code_jpg)
+c_JPG=$(printf '\033[%sm' $code_JPG)
c_z=$(printf '\033[%sm' $code_z)
+# Case insenitive extensions
LS_COLORS="*.jpg=$code_jpg:*.Z=$code_z" ls -U1 --color=always \
img1.jpg IMG2.JPG file1.z file2.Z > out || fail=1
printf "$c0\
@@ -37,5 +40,46 @@ ${c_z}file2.Z$c0
" > out_ok || framework_failure_
compare out out_ok || fail=1
+# Case sensitive extensions
+LS_COLORS="*.jpg=$code_jpg:*.JPG=$code_JPG" ls -U1 --color=always \
+ img1.jpg IMG2.JPG img3.JpG > out || fail=1
+printf "$c0\
+${c_jpg}img1.jpg$c0
+${c_JPG}IMG2.JPG$c0
+img3.JpG
+" > out_ok || framework_failure_
+compare out out_ok || fail=1
+
+# Case insensitive extensions (due to same sequences)
+LS_COLORS="*.jpg=$code_jpg:*.JPG=$code_jpg" ls -U1 --color=always \
+ img1.jpg IMG2.JPG img3.JpG > out || fail=1
+printf "$c0\
+${c_jpg}img1.jpg$c0
+${c_jpg}IMG2.JPG$c0
+${c_jpg}img3.JpG$c0
+" > out_ok || framework_failure_
+compare out out_ok || fail=1
+
+# Case insensitive extensions (due to same sequences (after ignored sequences))
+# Note later entries in LS_COLORS take precedence.
+LS_COLORS="*.jpg=$code_jpg:*.jpg=$code_JPG:*.JPG=$code_JPG" \
+ ls -U1 --color=always img1.jpg IMG2.JPG img3.JpG > out || fail=1
+printf "$c0\
+${c_JPG}img1.jpg$c0
+${c_JPG}IMG2.JPG$c0
+${c_JPG}img3.JpG$c0
+" > out_ok || framework_failure_
+compare out out_ok || fail=1
+
+# Case sensitive extensions (due to diff sequences (after ignored sequences))
+# Note later entries in LS_COLORS take precedence.
+LS_COLORS="*.jpg=$code_JPG:*.jpg=$code_jpg:*.JPG=$code_JPG" \
+ ls -U1 --color=always img1.jpg IMG2.JPG img3.JpG > out || fail=1
+printf "$c0\
+${c_jpg}img1.jpg$c0
+${c_JPG}IMG2.JPG$c0
+img3.JpG
+" > out_ok || framework_failure_
+compare out out_ok || fail=1
Exit $fail