doc: update Vala documentation
[automake.git] / t / install-sh-unittests.sh
blob11f3093b356f5ec6317dad056b22d29cc05f99a2
1 #! /bin/sh
2 # Copyright (C) 2002-2024 Free Software Foundation, Inc.
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2, or (at your option)
7 # any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <https://www.gnu.org/licenses/>.
17 # Various install-sh checks.
19 am_create_testdir=empty
20 . test-init.sh
22 install_sh_fail ()
24 err_rx=$1; shift
25 ./install-sh ${1+"$@"} 2>stderr && { cat stderr >&2; exit 1; }
26 cat stderr >&2
27 $EGREP "install-sh:.* $err_rx" stderr || exit 1
30 get_shell_script install-sh
32 # Basic errors.
33 install_sh_fail 'no input file specified'
34 install_sh_fail 'no input file specified' dest
35 install_sh_fail 'no input file specified' -m 644 dest
36 install_sh_fail 'no input file specified' -c -t dest
38 # Incorrect usages.
39 : > bar
40 : > baz
41 : > qux
42 install_sh_fail 'target directory not allowed when installing a directory' \
43 -d -t foo
44 install_sh_fail 'target directory not allowed when installing a directory' \
45 -d -t foo bar
46 install_sh_fail 'foo: [iI]s not a directory' -t foo bar
47 install_sh_fail 'foo: [iI]s not a directory' bar baz foo
48 mkdir foo
49 install_sh_fail 'target directory not allowed when installing a directory' \
50 -d -t foo
51 install_sh_fail 'target directory not allowed when installing a directory' \
52 -d -t foo bar
53 rmdir foo
54 rm -f bar baz qux
56 # Directories.
57 for opts in '-d' '-d -T' '-T -d' '-d -T -d' '-T -d -T -d -T'; do
58 # It should be OK to create no directory. We sometimes need
59 # this when directory are conditionally defined.
60 ./install-sh $opts
61 # One directory.
62 ./install-sh $opts d0
63 test -d d0
64 # Multiple directories (for make installdirs).
65 ./install-sh $opts d1 d2 d3 d4
66 test -d d1
67 test -d d2
68 test -d d3
69 test -d d4
70 rmdir d[0-9]
71 # Subdirectories.
72 ./install-sh $opts p1/p2/p3 p4//p5//p6//
73 test -d p1/p2/p3
74 test -d p4/p5/p6
75 rmdir p[0-9]/p[0-9]/p[0-9]
76 rmdir p[0-9]/p[0-9]
77 rmdir p[0-9]
78 done
80 # Files.
81 mkdir d0 d1 d2 d3 d4
82 : > x
83 ./install-sh -c -m 644 x y
84 test -f x
85 test -f y
86 ./install-sh -m 644 y z
87 test -f y
88 test -f z
89 # Multiple files.
90 ./install-sh -m 644 -c x z d1
91 test -f x
92 test -f z
93 test -f d1/x
94 test -f d1/z
95 ./install-sh -m 644 x z d2//
96 test -f x
97 test -f z
98 test -f d2/x
99 test -f d2/z
100 ./install-sh -t d3 -m 644 x z
101 test -f x
102 test -f z
103 test -f d3/x
104 test -f d3/z
105 ./install-sh -t d4// -m 644 x z
106 test -f x
107 test -f z
108 test -f d4/x
109 test -f d4/z
110 ./install-sh -T x d3/y
111 test -f x
112 test -f d3/y
113 install_sh_fail 'd3: [iI]s a directory' -T x d3
114 install_sh_fail 'd4(//)?: [iI]s a directory' -T x d4//
116 # Ensure that install-sh works with names that include spaces.
117 touch 'a b'
118 mkdir 'x y'
119 ./install-sh 'a b' 'x y'
120 test -f x\ \ y/a\ \ b
121 test -f 'a b'
123 # Ensure we do not run into 'test' operator precedence bugs with Tru64 sh.
124 for c in = '(' ')' '!'; do
125 install_sh_fail 'no input file specified' $c
126 test -f stderr # sanity check
127 grep 'test: ' stderr && exit 1
128 # Skip tests if the file system is not capable.
129 mkdir ./$c || continue
130 rmdir ./$c
131 ./install-sh -d $c/$c/$c
132 rm -rf ./$c
133 ./install-sh -d $c d5/$c/$c
134 test -d ./$c
135 test -d d5/$c/$c
136 ./install-sh x $c
137 test -f ./$c/x
138 rm -f ./$c/x
139 ./install-sh -t $c x
140 test -f ./$c/x
141 rm -rf ./$c
142 ( : > ./$c ) || continue
143 ./install-sh $c x d5/$c/$c
144 test -f d5/$c/$c/x
145 test -f d5/$c/$c/$c
146 rm -f d5/$c/$c/?
147 ./install-sh -t d5/$c/$c $c x
148 test -f d5/$c/$c/x
149 test -f d5/$c/$c/$c
150 done