tests: factor 350 fail=0 initializations into test-lib.sh
[platform/upstream/coreutils.git] / tests / ls / multihardlink
1 #!/bin/sh
2 # Ensure "ls --color" properly colorizes hard linked files.
3
4 # Copyright (C) 2008-2009 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 <http://www.gnu.org/licenses/>.
18
19 if test "$VERBOSE" = yes; then
20   set -x
21   ls --version
22 fi
23
24 . $srcdir/test-lib.sh
25 working_umask_or_skip_
26
27 touch file file1 || framework_failure
28 ln file1 file2 || skip_test_ "can't create hard link"
29 code_mh='44;37'
30 code_ex='01;32'
31 code_png='01;35'
32 c0=$(printf '\033[0m')
33 c_end=$(printf '\033[m')
34 c_mh=$(printf '\033[%sm' $code_mh)
35 c_ex=$(printf '\033[%sm' $code_ex)
36 c_png=$(printf '\033[%sm' $code_png)
37
38 # regular file - not hard linked
39 LS_COLORS="mh=$code_mh" ls -U1 --color=always file > out || fail=1
40 printf "file\n" > out_ok || framework_failure
41 compare out out_ok || fail=1
42
43 # hard links
44 LS_COLORS="mh=$code_mh" ls -U1 --color=always file1 file2 > out || fail=1
45 printf "$c0${c_mh}file1$c0
46 ${c_mh}file2$c0
47 $c_end" > out_ok || framework_failure
48 compare out out_ok || fail=1
49
50 # hard links and png (hard link coloring takes precedence)
51 mv file2 file2.png || framework_failure
52 LS_COLORS="mh=$code_mh:*.png=$code_png" ls -U1 --color=always file1 file2.png \
53   > out || fail=1
54 printf "$c0${c_mh}file1$c0
55 ${c_mh}file2.png$c0
56 $c_end" > out_ok || framework_failure
57 compare out out_ok || fail=1
58
59 # hard links and exe (exe coloring takes precedence)
60 chmod a+x file2.png || framework_failure
61 LS_COLORS="mh=$code_mh:*.png=$code_png:ex=$code_ex" \
62   ls -U1 --color=always file1 file2.png > out || fail=1
63 chmod a-x file2.png || framework_failure
64 printf "$c0${c_ex}file1$c0
65 ${c_ex}file2.png$c0
66 $c_end" > out_ok || framework_failure
67 compare out out_ok || fail=1
68
69 # hard links and png (hard link coloring disabled => png coloring enabled)
70 LS_COLORS="mh=00:*.png=$code_png" ls -U1 --color=always file1 file2.png > out \
71   || fail=1
72 printf "file1
73 $c0${c_png}file2.png$c0
74 $c_end" > out_ok || framework_failure
75 compare out out_ok || fail=1
76
77 # hard links and png (hard link coloring not enabled explicitly => png coloring)
78 LS_COLORS="*.png=$code_png" ls -U1 --color=always file1 file2.png > out \
79   || fail=1
80 printf "file1
81 $c0${c_png}file2.png$c0
82 $c_end" > out_ok || framework_failure
83 compare out out_ok || fail=1
84
85 Exit $fail