update-copyright-tests: improve portability
[gnulib.git] / tests / test-update-copyright.sh
1 #!/bin/sh
2 # Test suite for update-copyright.
3 # Copyright (C) 2009 Free Software Foundation, Inc.
4 # This file is part of the GNUlib Library.
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 diffout=`diff -u /dev/null /dev/null 2>&1`
20 if test x"$diffout" = x"" && test $? -eq 0; then
21   compare() { diff -u "$@"; }
22 else
23   compare() { cmp "$@"; }
24 fi
25
26 TMP_BASE=update-copyright.test
27
28 ## ----------------------------- ##
29 ## Examples from documentation.  ##
30 ## ----------------------------- ##
31
32 TMP=$TMP_BASE-ex
33 cat > $TMP.1 <<EOF
34 Copyright @copyright{} 1990-2005, 2007-2009 Free Software
35 Foundation, Inc.
36 EOF
37 cat > $TMP.2 <<EOF
38 # Copyright (C) 1990-2005, 2007-2009 Free Software
39 # Foundation, Inc.
40 EOF
41 cat > $TMP.3 <<EOF
42 /*
43  * Copyright &copy; 90,2005,2007-2009
44  * Free Software Foundation, Inc.
45  */
46 EOF
47 cat > $TMP.4 <<EOF
48 /* Copyright (C) 1990-2005, 2007-2009 Free Software
49  * Foundation, Inc.  */
50
51 Copyright (C) 1990-2005, 2007-2009 Free Software Foundation,
52 Inc.
53 EOF
54 cat > $TMP.5 <<EOF
55 Copyright (C) 1990-2005, 2007-2009 Acme, Inc.
56
57 # Copyright (C) 1990-2005, 2007-2009 Free Software
58 # Foundation, Inc.
59 EOF
60
61 UPDATE_COPYRIGHT_YEAR=2009 \
62   update-copyright $TMP.* 1> $TMP-stdout 2> $TMP-stderr
63 compare /dev/null $TMP-stdout || exit 1
64 compare - $TMP-stderr <<EOF || exit 1
65 $TMP.4: warning: FSF copyright statement not found
66 $TMP.5: warning: FSF copyright statement not found
67 EOF
68 compare - $TMP.1 <<EOF || exit 1
69 Copyright @copyright{} 1990-2005, 2007-2009 Free Software
70 Foundation, Inc.
71 EOF
72 compare - $TMP.2 <<EOF || exit 1
73 # Copyright (C) 1990-2005, 2007-2009 Free Software
74 # Foundation, Inc.
75 EOF
76 compare - $TMP.3 <<EOF || exit 1
77 /*
78  * Copyright &copy; 90,2005,2007-2009
79  * Free Software Foundation, Inc.
80  */
81 EOF
82 compare - $TMP.4 <<EOF || exit 1
83 /* Copyright (C) 1990-2005, 2007-2009 Free Software
84  * Foundation, Inc.  */
85
86 Copyright (C) 1990-2005, 2007-2009 Free Software Foundation,
87 Inc.
88 EOF
89 compare - $TMP.5 <<EOF || exit 1
90 Copyright (C) 1990-2005, 2007-2009 Acme, Inc.
91
92 # Copyright (C) 1990-2005, 2007-2009 Free Software
93 # Foundation, Inc.
94 EOF
95
96 UPDATE_COPYRIGHT_YEAR=2010 \
97   update-copyright $TMP.* 1> $TMP-stdout 2> $TMP-stderr
98 compare /dev/null $TMP-stdout || exit 1
99 compare - $TMP-stderr <<EOF || exit 1
100 $TMP.4: warning: FSF copyright statement not found
101 $TMP.5: warning: FSF copyright statement not found
102 EOF
103 compare - $TMP.1 <<EOF || exit 1
104 Copyright @copyright{} 1990-2005, 2007-2010 Free Software Foundation,
105 Inc.
106 EOF
107 compare - $TMP.2 <<EOF || exit 1
108 # Copyright (C) 1990-2005, 2007-2010 Free Software Foundation, Inc.
109 EOF
110 compare - $TMP.3 <<EOF || exit 1
111 /*
112  * Copyright &copy; 90, 2005, 2007-2010 Free Software Foundation, Inc.
113  */
114 EOF
115 compare - $TMP.4 <<EOF || exit 1
116 /* Copyright (C) 1990-2005, 2007-2009 Free Software
117  * Foundation, Inc.  */
118
119 Copyright (C) 1990-2005, 2007-2009 Free Software Foundation,
120 Inc.
121 EOF
122 compare - $TMP.5 <<EOF || exit 1
123 Copyright (C) 1990-2005, 2007-2009 Acme, Inc.
124
125 # Copyright (C) 1990-2005, 2007-2009 Free Software
126 # Foundation, Inc.
127 EOF
128
129 rm $TMP*
130
131 ## -------------- ##
132 ## Current year.  ##
133 ## -------------- ##
134
135 TMP=$TMP_BASE-current-year
136 YEAR=`/usr/bin/perl -e 'print [localtime]->[5] + 1900'`;
137 cat > $TMP <<EOF
138 '\" Copyright (C) 2006
139 '\" Free Software Foundation,
140 '\" Inc.
141 EOF
142 update-copyright $TMP 1> $TMP-stdout 2> $TMP-stderr
143 compare /dev/null $TMP-stdout || exit 1
144 compare /dev/null $TMP-stderr || exit 1
145 compare - $TMP <<EOF || exit 1
146 '\" Copyright (C) 2006, $YEAR Free Software Foundation, Inc.
147 EOF
148 rm $TMP*
149
150 ## ------------------ ##
151 ## Surrounding text.  ##
152 ## ------------------ ##
153
154 TMP=$TMP_BASE-surrounding-text
155 cat > $TMP <<EOF
156     Undisturbed text.
157 dnl Undisturbed text.
158 dnl Copyright (C) 89
159 dnl Free Software Foundation, Inc.
160 dnl   Undisturbed text.
161 EOF
162 UPDATE_COPYRIGHT_YEAR=2010 \
163   update-copyright $TMP 1> $TMP-stdout 2> $TMP-stderr
164 compare /dev/null $TMP-stdout || exit 1
165 compare /dev/null $TMP-stderr || exit 1
166 compare - $TMP <<EOF || exit 1
167     Undisturbed text.
168 dnl Undisturbed text.
169 dnl Copyright (C) 1989, 2010 Free Software Foundation, Inc.
170 dnl   Undisturbed text.
171 EOF
172 rm $TMP*
173
174 ## --------------- ##
175 ## Widest prefix.  ##
176 ## --------------- ##
177
178 TMP=$TMP_BASE-widest-prefix
179 cat > $TMP <<EOF
180 #### Copyright (C) 1976, 1977, 1978, 1979, 1980, 1981, 1982, 1983, 1984, 1985,
181 #### 1986, 1987, 1988, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
182 #### 2008 Free Software Foundation, Inc.
183 EOF
184 UPDATE_COPYRIGHT_YEAR=2010 \
185   update-copyright $TMP 1> $TMP-stdout 2> $TMP-stderr
186 compare /dev/null $TMP-stdout || exit 1
187 compare /dev/null $TMP-stderr || exit 1
188 compare - $TMP <<EOF || exit 1
189 #### Copyright (C) 1976, 1977, 1978, 1979, 1980, 1981, 1982, 1983, 1984,
190 #### 1985, 1986, 1987, 1988, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
191 #### 2006, 2007, 2008, 2010 Free Software Foundation, Inc.
192 EOF
193 rm $TMP*
194
195 ## ------------------- ##
196 ## Prefix too large.  ##
197 ## ------------------- ##
198
199 TMP=$TMP_BASE-prefix-too-large
200 cat > $TMP <<EOF
201 ####  Copyright (C) 1976, 1977, 1978, 1979, 1980, 1981, 1982, 1983, 1984, 1985,
202 ####  1986, 1987, 1988, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
203 ####  2008 Free Software Foundation, Inc.
204 EOF
205 UPDATE_COPYRIGHT_YEAR=2010 \
206   update-copyright $TMP 1> $TMP-stdout 2> $TMP-stderr
207 compare /dev/null $TMP-stdout || exit 1
208 compare - $TMP-stderr <<EOF || exit 1
209 $TMP: warning: FSF copyright statement not found
210 EOF
211 compare - $TMP <<EOF || exit 1
212 ####  Copyright (C) 1976, 1977, 1978, 1979, 1980, 1981, 1982, 1983, 1984, 1985,
213 ####  1986, 1987, 1988, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
214 ####  2008 Free Software Foundation, Inc.
215 EOF
216 rm $TMP*
217
218 ## ------------- ##
219 ## Blank lines.  ##
220 ## ------------- ##
221
222 TMP=$TMP_BASE-blank-lines
223 cat > $TMP <<EOF
224 #Copyright (C) 1976, 1977, 1978, 1979, 1980, 1981, 1982, 1983, 1984, 1985,
225 #
226 #1986, 1987, 1988, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
227 #2008 Free Software Foundation, Inc.
228
229 Copyright (C) 1976, 1977, 1978, 1979, 1980, 1981, 1982, 1983, 1984, 1985,
230
231 1986, 1987, 1988, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
232 2008 Free Software Foundation, Inc.
233 EOF
234 UPDATE_COPYRIGHT_YEAR=2010 \
235   update-copyright $TMP 1> $TMP-stdout 2> $TMP-stderr
236 compare /dev/null $TMP-stdout || exit 1
237 compare - $TMP-stderr <<EOF || exit 1
238 $TMP: warning: FSF copyright statement not found
239 EOF
240 compare - $TMP <<EOF || exit 1
241 #Copyright (C) 1976, 1977, 1978, 1979, 1980, 1981, 1982, 1983, 1984, 1985,
242 #
243 #1986, 1987, 1988, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
244 #2008 Free Software Foundation, Inc.
245
246 Copyright (C) 1976, 1977, 1978, 1979, 1980, 1981, 1982, 1983, 1984, 1985,
247
248 1986, 1987, 1988, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
249 2008 Free Software Foundation, Inc.
250 EOF
251 rm $TMP*
252
253 ## -------------- ##
254 ## Leading tabs.  ##
255 ## -------------- ##
256
257 TMP=$TMP_BASE-leading-tabs
258 cat > $TMP <<EOF
259         Copyright (C) 87, 88, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 98,
260          1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free
261         Software Foundation, Inc.
262 EOF
263 UPDATE_COPYRIGHT_YEAR=2010 \
264   update-copyright $TMP 1> $TMP-stdout 2> $TMP-stderr
265 compare /dev/null $TMP-stdout || exit 1
266 compare /dev/null $TMP-stderr || exit 1
267 compare - $TMP <<EOF || exit 1
268         Copyright (C) 87, 88, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
269         98, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
270         2009-2010 Free Software Foundation, Inc.
271 EOF
272 rm $TMP*
273
274 ## -------------------- ##
275 ## Unusual whitespace.  ##
276 ## -------------------- ##
277
278 TMP=$TMP_BASE-unusual-ws
279 cat > $TMP <<EOF
280                 # Copyright (C) 87, 88, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
281                 # 98, 1999, 2000, 2001, 2002, 2003,             \f         2004, 2005, 2006, 2007, 2008,
282                 # 2009 Free Software Foundation, Inc.
283 EOF
284 UPDATE_COPYRIGHT_YEAR=2010 \
285   update-copyright $TMP 1> $TMP-stdout 2> $TMP-stderr
286 compare /dev/null $TMP-stdout || exit 1
287 compare /dev/null $TMP-stderr || exit 1
288 compare - $TMP <<EOF || exit 1
289                 # Copyright (C) 87, 88, 1991, 1992, 1993, 1994, 1995,
290                 # 1996, 1997, 98, 1999, 2000, 2001, 2002, 2003, 2004,
291                 # 2005, 2006, 2007, 2008, 2009-2010 Free Software
292                 # Foundation, Inc.
293 EOF
294 rm $TMP*
295
296 ## --------- ##
297 ## DOS EOL.  ##
298 ## --------- ##
299
300 TMP=$TMP_BASE-dos-eol
301 tr @ '\015' > $TMP <<\EOF
302 Rem Copyright (C) 87, 88, 1991, 1992, 1993, 1994, 1995, 1996, 1997,@
303 Rem 98, 1999, 2000, 2001, 2002, 2003,  2004, 2005, 2006, 2007, 2008,@
304 Rem 2009 Free Software Foundation, Inc.@
305 EOF
306 UPDATE_COPYRIGHT_YEAR=2010 \
307   update-copyright $TMP 1> $TMP-stdout 2> $TMP-stderr
308 compare /dev/null $TMP-stdout || exit 1
309 compare /dev/null $TMP-stderr || exit 1
310 tr @ '\015' > $TMP-exp <<\EOF
311 Rem Copyright (C) 87, 88, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 98,@
312 Rem 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,@
313 Rem 2009-2010 Free Software Foundation, Inc.@
314 EOF
315 compare $TMP-exp $TMP || exit 1
316 rm $TMP*
317
318 exit 0