Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids. Most
[dragonfly.git] / gnu / usr.bin / rcs / rcstest
1 #! /bin/sh
2
3 # Test RCS's functions.
4 # The RCS commands are searched for in the PATH as usual;
5 # to test the working directory's commands, prepend . to your PATH.
6
7 # Test RCS by creating files RCS/a.* and RCS/a.c.
8 # If all goes well, output nothing, and remove the temporary files.
9 # Otherwise, send a message to standard output.
10 # Exit status is 0 if OK, 1 if an RCS bug is found, and 2 if scaffolding fails.
11 # With the -v option, output more debugging info.
12
13 # If diff outputs `No differences encountered' when comparing identical files,
14 # then rcstest may also output these noise lines; ignore them.
15
16 # The current directory and ./RCS must be readable, writable, and searchable.
17
18 # $FreeBSD: src/gnu/usr.bin/rcs/rcstest,v 1.5 1999/08/27 23:36:37 peter Exp $
19 # $DragonFly: src/gnu/usr.bin/rcs/rcstest,v 1.2 2003/06/17 04:25:47 dillon Exp $
20
21
22 #    Copyright 1990, 1991, 1992, 1993, 1994, 1995 Paul Eggert
23 #    Distributed under license by the Free Software Foundation, Inc.
24 #
25 # This file is part of RCS.
26 #
27 # RCS is free software; you can redistribute it and/or modify
28 # it under the terms of the GNU General Public License as published by
29 # the Free Software Foundation; either version 2, or (at your option)
30 # any later version.
31 #
32 # RCS is distributed in the hope that it will be useful,
33 # but WITHOUT ANY WARRANTY; without even the implied warranty of
34 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
35 # GNU General Public License for more details.
36 #
37 # You should have received a copy of the GNU General Public License
38 # along with RCS; see the file COPYING.
39 # If not, write to the Free Software Foundation,
40 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
41 #
42 # Report problems and direct all questions to:
43 #
44 #     rcs-bugs@cs.purdue.edu
45
46 # The Makefile overrides the following defaults.
47 : ${ALL_CFLAGS=-Dhas_conf_h}
48 : ${CC=cc}
49 : ${DIFF=diff}
50 # : ${LDFLAGS=} ${LIBS=} tickles old shell bug
51
52 CL="$CC $ALL_CFLAGS $LDFLAGS -o a.out"
53 L=$LIBS
54
55 RCSINIT=-x
56 export RCSINIT
57
58 SLASH=/
59 RCSfile=RCS${SLASH}a.c
60 RCS_alt=RCS${SLASH}a.d
61 lockfile=RCS${SLASH}a._
62
63 case $1 in
64 -v) q=; set -x;;
65 '') q=-q;;
66 *) echo >&2 "$0: usage: $0 [-v]"; exit 2
67 esac
68
69 if test -d RCS
70 then rmdir=:
71 else rmdir=rmdir; mkdir RCS || exit
72 fi
73
74 rm -f a.* $RCSfile $RCS_alt $lockfile &&
75 echo 1.1 >a.11 &&
76 echo 1.1.1.1 >a.3x1 &&
77 echo 1.2 >a.12 || { echo "#initialization failed"; exit 2; }
78
79 case "`$DIFF -c a.11 a.3x1`" in
80 *!\ 1.1.1.1)
81         diff="$DIFF -c";;
82 *)
83         echo "#warning: $DIFF -c does not work, so diagnostics may be cryptic"
84         diff=$DIFF
85 esac
86
87 rcs -i -L -ta.11 $q a.c &&
88 test -r $RCSfile || {
89         echo "#rcs -i -L failed; perhaps RCS is not properly installed."
90         exit 1
91 }
92
93 rlog a.c >/dev/null || { echo "#rlog failed on empty RCS file"; exit 1; }
94 rm -f $RCSfile || exit 2
95
96 cp a.11 a.c &&
97 ci -ta.11 -mm $q a.c &&
98 test -r $RCSfile &&
99 rcs -L $q a.c || { echo "#ci+rcs -L failed"; exit 1; }
100 test ! -f a.c || { echo "#ci did not remove working file"; exit 1; }
101 for l in '' '-l'
102 do
103         co $l $q a.c &&
104         test -f a.c || { echo '#co' $l did not create working file; exit 1; }
105         $diff a.11 a.c || { echo '#ci' followed by co $l is not a no-op; exit 1; }
106 done
107
108 cp a.12 a.c &&
109 ci -mm $q a.c &&
110 co $q a.c &&
111 $diff a.12 a.c || { echo "#ci+co failed"; exit 1; }
112
113 rm -f a.c &&
114 co -r1.1 $q a.c &&
115 $diff a.11 a.c || { echo "#can't retrieve first revision"; exit 1; }
116
117 rm -f a.c &&
118 cp a.3x1 a.c &&
119 ci -r1.1.1 -mm $q a.c &&
120 co -r1.1.1.1 $q a.c &&
121 $diff a.3x1 a.c || { echo "#branches failed"; exit 1; }
122
123 rm -f a.c &&
124 co -l $q a.c &&
125 ci -f -mm $q a.c &&
126 co -r1.3 $q a.c &&
127 $diff a.12 a.c || { echo "#(co -l; ci -f) failed"; exit 1; }
128
129 rm -f a.c &&
130 co -l $q a.c &&
131 echo 1.4 >a.c &&
132 ci -l -mm $q a.c &&
133 echo error >a.c &&
134 ci -mm $q a.c || { echo "#ci -l failed"; exit 1; }
135
136 rm -f a.c &&
137 co -l $q a.c &&
138 echo 1.5 >a.c &&
139 ci -u -mm $q a.c &&
140 test -r a.c || { echo "#ci -u didn't create a working file"; exit 1; }
141 rm -f a.c &&
142 echo error >a.c || exit 2
143 ci -mm $q a.c 2>/dev/null && { echo "#ci -u didn't unlock the file"; exit 1; }
144
145 rm -f a.c &&
146 rcs -l $q a.c &&
147 co -u $q a.c || { echo "#rcs -l + co -u failed"; exit 1; }
148 rm -f a.c &&
149 echo error >a.c || exit 2
150 ci -mm $q a.c 2>/dev/null && { echo "#co -u didn't unlock the file"; exit 1; }
151
152 rm -f a.c &&
153 cp a.11 a.c &&
154 co -f $q a.c || { echo "#co -f failed"; exit 1; }
155 $diff a.11 a.c >/dev/null && { echo "#co -f had no effect"; exit 1; }
156
157 co -p1.1 $q a.c >a.t &&
158 $diff a.11 a.t || { echo "#co -p failed"; exit 1; }
159
160 for n in n N
161 do
162         rm -f a.c &&
163         co -l $q a.c &&
164         echo $n >a.$n &&
165         cp a.$n a.c &&
166         ci -${n}n -mm $q a.c &&
167         co -rn $q a.c &&
168         $diff a.$n a.c || { echo "#ci -$n failed"; exit 1; }
169 done
170
171 case $LOGNAME in
172 ?*) me=$LOGNAME;;
173 *)
174         case $USER in
175         ?*) me=$USER;;
176         *)
177                 me=`who am i` || exit 2
178                 me=`echo "$me" | sed -e 's/ .*//' -e 's/.*!//'`
179                 case $me in
180                 '') echo >&2 "$0: cannot deduce user name"; exit 2
181                 esac
182         esac
183 esac
184
185
186 # Get the date of the previous revision in UTC.
187 date=`rlog -r a.c | sed -n '/^date: /{ s///; s/;.*//; p; q; }'` || exit
188 case $date in
189 [0-9][0-9][0-9]*[0-9]/[0-1][0-9]/[0-3][0-9]\ [0-2][0-9]:[0-5][0-9]:[0-6][0-9]);;
190 *) echo >&2 "$0: $date: bad rlog date output"; exit 1
191 esac
192 PWD=`pwd` && export PWD &&
193 rm -f a.c &&
194 co -l $q a.c &&
195 sed 's/@/$/g' >a.kv <<EOF
196 @Author: w @
197 @Date: $date @
198 @Header: $PWD$SLASH$RCSfile 2.1 $date w s @
199 @Id: a.c 2.1 $date w s @
200 @Locker:  @
201  * @Log: a.c @
202  * Revision 2.1  $date  w
203  * m
204  *
205 @Name: Oz @
206 @RCSfile: a.c @
207 @Revision: 2.1 @
208 @Source: $PWD$SLASH$RCSfile @
209 @State: s @
210 EOF
211 test $? = 0 &&
212 sed 's/:.*\$/$/' a.kv >a.k &&
213 sed -e 's/w s [$]/w s '"$me"' $/' -e 's/[$]Locker: /&'"$me/" a.kv >a.kvl &&
214 sed s/Oz//g a.kv >a.e &&
215 sed s/Oz/N/g a.kv >a.N &&
216 sed -e '/\$/!d' -e 's/\$$/: old $/' a.k >a.o &&
217 sed -e 's/\$[^ ]*: //' -e 's/ \$//' a.kv >a.v &&
218 cp a.o a.c &&
219 ci -d"$date" -nOz -ss -ww -u2.1 -mm $q a.c &&
220 $diff a.kv a.c || { echo "#keyword expansion failed"; exit 1; }
221 co -pOz -ko $q a.c >a.oo &&
222 $diff a.o a.oo || { echo "#co -p -ko failed"; exit 1; }
223 cp a.kv a.o && cp a.o a.b || exit 2
224 rcs -oOz $q a.c &&
225 rcs -l $q a.c &&
226 ci -k -u $q a.c &&
227 $diff a.kv a.c || { echo "#ci -k failed"; exit 1; }
228 sed -n 's/^[^$]*\$/$/p' a.kv >a.i &&
229 ident a.c >a.i1 &&
230 sed -e 1d -e 's/^[       ]*//' a.i1 >a.i2 &&
231 $diff a.i a.i2 || { echo "#ident failed"; exit 1; }
232
233 rcs -i $q a.c 2>/dev/null && { echo "#rcs -i permitted existing file"; exit 1; }
234
235 rm -f a.c &&
236 co -l $q a.c &&
237 echo 2.2 >a.c &&
238 ci -mm $q a.c &&
239 echo 1.1.1.2 >a.c &&
240 rcs -l1.1.1 $q a.c &&
241 ci -r1.1.1.2 -mm $q a.c &&
242 rcs -b1.1.1 $q a.c &&
243 test " `co -p $q a.c`" = ' 1.1.1.2' || { echo "#rcs -b1.1.1 failed"; exit 1; }
244 rcs -b $q a.c &&
245 test " `co -p $q a.c`" = ' 2.2' || { echo "#rcs -b failed"; exit 1; }
246
247 echo 2.3 >a.c || exit 2
248 rcs -U $q a.c || { echo "#rcs -U failed"; exit 1; }
249 ci -mm $q a.c || { echo "#rcs -U didn't unset strict locking"; exit 1; }
250 rcs -L $q a.c || { echo "#rcs -L failed"; exit 1; }
251 echo error >a.c || exit 2
252 ci -mm $q a.c 2>/dev/null && { echo "#ci retest failed"; exit 1; }
253
254 rm -f a.c &&
255 log0=`rlog -h a.c` &&
256 co -l $q a.c &&
257 ci -mm $q a.c &&
258 log1=`rlog -h a.c` &&
259 test " $log0" = " $log1" || { echo "#unchanged ci didn't revert"; exit 1; }
260
261 rm -f a.c &&
262 rcs -nN:1.1 $q a.c &&
263 co -rN $q a.c &&
264 $diff a.11 a.c || { echo "#rcs -n failed"; exit 1; }
265
266 rm -f a.c &&
267 rcs -NN:2.1 $q a.c &&
268 co -rN $q a.c &&
269 $diff a.N a.c || { echo "#rcs -N failed"; exit 1; }
270
271 rm -f a.c &&
272 co -l $q a.c &&
273 echo ':::$''Log$' >a.c &&
274 ci -u -mm $q a.c &&
275 test " `sed '$!d' a.c`" = ' :::' || { echo "#comment leader failed"; exit 1; }
276
277 rm -f a.c &&
278 rcs -o2.2: $q a.c &&
279 co $q a.c &&
280 $diff a.e a.c || { echo "#rcs -o failed"; exit 1; }
281
282 rcsdiff -r1.1 -rOz $q a.c >a.0
283 case $? in
284 1) ;;
285 *) echo "#rcsdiff bad status"; exit 1
286 esac
287 $DIFF a.11 a.kv >a.1
288 $diff a.0 a.1 || { echo "#rcsdiff failed"; exit 1; }
289
290 rcs -l2.1 $q a.c || { echo "#rcs -l2.1 failed"; exit 1; }
291 for i in b k kv kvl o v
292 do
293         rm -f a.c &&
294         cp a.$i a.c &&
295         rcsdiff -k$i -rOz $q a.c || { echo "#rcsdiff -k$i failed"; exit 1; }
296 done
297 co -p1.1 -ko $q a.c >a.t &&
298 $diff a.11 a.t || { echo "#co -p1.1 -ko failed"; exit 1; }
299 rcs -u2.1 $q a.c || { echo "#rcs -u2.1 failed"; exit 1; }
300
301 rm -f a.c &&
302 rcsclean $q a.c &&
303 rcsclean -u $q a.c || { echo "#rcsclean botched a nonexistent file"; exit 1; }
304
305 rm -f a.c &&
306 co $q a.c &&
307 rcsclean -n $q a.c &&
308 rcsclean -n -u $q a.c &&
309 test -f a.c || { echo "#rcsclean -n removed a file"; exit 1; }
310
311 rm -f a.c &&
312 co $q a.c &&
313 rcsclean $q a.c &&
314 test ! -f a.c || { echo "#rcsclean missed an unlocked file"; exit 1; }
315
316 rm -f a.c &&
317 co -l $q a.c &&
318 rcsclean $q a.c &&
319 test -f a.c || { echo "#rcsclean removed a locked file"; exit 1; }
320 rcsclean -u $q a.c &&
321 test ! -f a.c || {
322         echo "#rcsclean -u missed an unchanged locked file"; exit 1;
323 }
324
325 rm -f a.c &&
326 co -l $q a.c &&
327 echo change >>a.c &&
328 rcsclean $q a.c &&
329 rcsclean $q -u a.c &&
330 test -f a.c || { echo "#rcsclean removed a changed file"; exit 1; }
331
332 rm -f a.c &&
333 co -l $q a.c &&
334 cat >a.c <<'EOF'
335 2.2
336 a
337 b
338 c
339 d
340 EOF
341 test $? = 0 &&
342 ci -l -mm $q a.c &&
343 co -p2.2 $q a.c | sed -e s/2.2/2.3/ -e s/b/b1/ >a.c &&
344 ci -l -mm $q a.c &&
345 co -p2.2 $q a.c | sed -e s/2.2/new/ -e s/d/d1/ >a.c || exit 2
346 cat >a.0 <<'EOF'
347 2.3
348 a
349 b1
350 c
351 d1
352 EOF
353 cat >a.1 <<'EOF'
354 <<<<<<< a.c
355 new
356 =======
357 2.3
358 >>>>>>> 2.3
359 a
360 b1
361 c
362 d1
363 EOF
364 rcsmerge -E -r2.2 -r2.3 $q a.c
365 case $? in
366 0)
367         if $diff a.0 a.c >/dev/null
368         then echo "#warning: diff3 -E does not work, " \
369                 "so merge and rcsmerge ignore overlaps and suppress overlap lines."
370         else
371                 $diff a.1 a.c || { echo "#rcsmerge failed (status 0)"; exit 1; }
372                 echo "#warning: The diff3 lib program exit status ignores overlaps," \
373                         "so rcsmerge does not warn about overlap lines that it generates."
374         fi
375         ;;
376 1)
377         $diff a.1 a.c || { echo "#rcsmerge failed (status 1)"; exit 1; }
378         ;;
379 *)
380         echo "#rcsmerge bad status"; exit 1
381 esac
382
383 # Avoid `tr' if possible; it's not portable, and it can't handle null bytes.
384 # Our substitute exclusive-ORs with '\n';
385 # this ensures null bytes on output, which is even better than `tr',
386 # since some diffs think a file is binary only if it contains null bytes.
387 cat >a.c <<'EOF'
388 #include <stdio.h>
389 int main() {
390         int c;
391         while ((c=getchar()) != EOF)
392                 putchar(c ^ '\n');
393         return 0;
394 }
395 EOF
396 tr=tr
397 if (rm -f a.exe a.out && $CL a.c $L >&2) >/dev/null 2>&1
398 then
399         if test -s a.out
400         then tr=./a.out
401         elif test -s a.exe
402         then tr=./a.exe
403         fi
404 fi
405 {
406         co -p $q a.c | $tr '\012' '\200' >a.24 &&
407         cp a.24 a.c &&
408         ciOut=`(ci -l -mm $q a.c 2>&1)` &&
409         case $ciOut in
410         ?*) echo >&2 "$ciOut"
411         esac &&
412         co -p $q a.c | $tr '\200' '\012' >a.c &&
413         rcsdiff -r2.3 $q a.c >/dev/null &&
414
415         echo 2.5 >a.c &&
416         ci -l -mm $q a.c &&
417         cp a.24 a.c &&
418         rcsdiff -r2.4 $q a.c >/dev/null
419 } || echo "#warning: Traditional diff is used, so RCS is limited to text files."
420
421 rcs -u -o2.4: $q a.c || { echo "#rcs -u -o failed"; exit 1; }
422
423 rcs -i -Aa.c -t- $q a.d || { echo "#rcs -i -A failed"; exit 1; }
424
425 rlog -r2.1 a.c >a.t &&
426 grep '^checked in with -k' a.t >/dev/null &&
427 sed '/^checked in with -k/d' a.t >a.u &&
428 $diff - a.u <<EOF
429
430 RCS file: $RCSfile
431 Working file: a.c
432 head: 2.3
433 branch:
434 locks: strict
435 access list:
436 symbolic names:
437         N: 2.1
438         Oz: 2.1
439         n: 1.8
440 keyword substitution: kv
441 total revisions: 13;    selected revisions: 1
442 description:
443 1.1
444 ----------------------------
445 revision 2.1
446 date: $date;  author: w;  state: s;  lines: +14 -1
447 =============================================================================
448 EOF
449 test $? = 0 || { echo "#rlog failed"; exit 1; }
450
451
452 test ! -f $lockfile || { echo "#lock file not removed"; exit 1; }
453
454 rm -f a.* $RCSfile $RCS_alt
455 $rmdir RCS