1#!/bin/sh 2# Ensure "ls --color" properly colors file name extensions. 3 4# Copyright (C) 2018-2023 Free Software Foundation, Inc. 5 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. 10 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. 15 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/>. 18 19. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src 20print_ver_ ls 21working_umask_or_skip_ 22 23touch img1.jpg IMG2.JPG img3.JpG file1.z file2.Z || framework_failure_ 24code_jpg='01;35' 25code_JPG='01;35;46' 26code_z='01;31' 27c0=$(printf '\033[0m') 28c_jpg=$(printf '\033[%sm' $code_jpg) 29c_JPG=$(printf '\033[%sm' $code_JPG) 30c_z=$(printf '\033[%sm' $code_z) 31 32# Case insensitive extensions 33LS_COLORS="*.jpg=$code_jpg:*.Z=$code_z" ls -U1 --color=always \ 34 img1.jpg IMG2.JPG file1.z file2.Z > out || fail=1 35printf "$c0\ 36${c_jpg}img1.jpg$c0 37${c_jpg}IMG2.JPG$c0 38${c_z}file1.z$c0 39${c_z}file2.Z$c0 40" > out_ok || framework_failure_ 41compare out out_ok || fail=1 42 43# Case sensitive extensions 44LS_COLORS="*.jpg=$code_jpg:*.JPG=$code_JPG" ls -U1 --color=always \ 45 img1.jpg IMG2.JPG img3.JpG > out || fail=1 46printf "$c0\ 47${c_jpg}img1.jpg$c0 48${c_JPG}IMG2.JPG$c0 49img3.JpG 50" > out_ok || framework_failure_ 51compare out out_ok || fail=1 52 53# Case insensitive extensions (due to same sequences) 54LS_COLORS="*.jpg=$code_jpg:*.JPG=$code_jpg" ls -U1 --color=always \ 55 img1.jpg IMG2.JPG img3.JpG > out || fail=1 56printf "$c0\ 57${c_jpg}img1.jpg$c0 58${c_jpg}IMG2.JPG$c0 59${c_jpg}img3.JpG$c0 60" > out_ok || framework_failure_ 61compare out out_ok || fail=1 62 63# Case insensitive extensions (due to same sequences (after ignored sequences)) 64# Note later entries in LS_COLORS take precedence. 65LS_COLORS="*.jpg=$code_jpg:*.jpg=$code_JPG:*.JPG=$code_JPG" \ 66 ls -U1 --color=always img1.jpg IMG2.JPG img3.JpG > out || fail=1 67printf "$c0\ 68${c_JPG}img1.jpg$c0 69${c_JPG}IMG2.JPG$c0 70${c_JPG}img3.JpG$c0 71" > out_ok || framework_failure_ 72compare out out_ok || fail=1 73 74# Case sensitive extensions (due to diff sequences (after ignored sequences)) 75# Note later entries in LS_COLORS take precedence. 76LS_COLORS="*.jpg=$code_JPG:*.jpg=$code_jpg:*.JPG=$code_JPG" \ 77 ls -U1 --color=always img1.jpg IMG2.JPG img3.JpG > out || fail=1 78printf "$c0\ 79${c_jpg}img1.jpg$c0 80${c_JPG}IMG2.JPG$c0 81img3.JpG 82" > out_ok || framework_failure_ 83compare out out_ok || fail=1 84 85Exit $fail 86