xref: /dragonfly/gnu/usr.bin/rcs/rcstest (revision a4da4a90)
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
52CL="$CC $ALL_CFLAGS $LDFLAGS -o a.out"
53L=$LIBS
54
55RCSINIT=-x
56export RCSINIT
57
58SLASH=/
59RCSfile=RCS${SLASH}a.c
60RCS_alt=RCS${SLASH}a.d
61lockfile=RCS${SLASH}a._
62
63case $1 in
64-v) q=; set -x;;
65'') q=-q;;
66*) echo >&2 "$0: usage: $0 [-v]"; exit 2
67esac
68
69if test -d RCS
70then rmdir=:
71else rmdir=rmdir; mkdir RCS || exit
72fi
73
74rm -f a.* $RCSfile $RCS_alt $lockfile &&
75echo 1.1 >a.11 &&
76echo 1.1.1.1 >a.3x1 &&
77echo 1.2 >a.12 || { echo "#initialization failed"; exit 2; }
78
79case "`$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
85esac
86
87rcs -i -L -ta.11 $q a.c &&
88test -r $RCSfile || {
89	echo "#rcs -i -L failed; perhaps RCS is not properly installed."
90	exit 1
91}
92
93rlog a.c >/dev/null || { echo "#rlog failed on empty RCS file"; exit 1; }
94rm -f $RCSfile || exit 2
95
96cp a.11 a.c &&
97ci -ta.11 -mm $q a.c &&
98test -r $RCSfile &&
99rcs -L $q a.c || { echo "#ci+rcs -L failed"; exit 1; }
100test ! -f a.c || { echo "#ci did not remove working file"; exit 1; }
101for l in '' '-l'
102do
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; }
106done
107
108cp a.12 a.c &&
109ci -mm $q a.c &&
110co $q a.c &&
111$diff a.12 a.c || { echo "#ci+co failed"; exit 1; }
112
113rm -f a.c &&
114co -r1.1 $q a.c &&
115$diff a.11 a.c || { echo "#can't retrieve first revision"; exit 1; }
116
117rm -f a.c &&
118cp a.3x1 a.c &&
119ci -r1.1.1 -mm $q a.c &&
120co -r1.1.1.1 $q a.c &&
121$diff a.3x1 a.c || { echo "#branches failed"; exit 1; }
122
123rm -f a.c &&
124co -l $q a.c &&
125ci -f -mm $q a.c &&
126co -r1.3 $q a.c &&
127$diff a.12 a.c || { echo "#(co -l; ci -f) failed"; exit 1; }
128
129rm -f a.c &&
130co -l $q a.c &&
131echo 1.4 >a.c &&
132ci -l -mm $q a.c &&
133echo error >a.c &&
134ci -mm $q a.c || { echo "#ci -l failed"; exit 1; }
135
136rm -f a.c &&
137co -l $q a.c &&
138echo 1.5 >a.c &&
139ci -u -mm $q a.c &&
140test -r a.c || { echo "#ci -u didn't create a working file"; exit 1; }
141rm -f a.c &&
142echo error >a.c || exit 2
143ci -mm $q a.c 2>/dev/null && { echo "#ci -u didn't unlock the file"; exit 1; }
144
145rm -f a.c &&
146rcs -l $q a.c &&
147co -u $q a.c || { echo "#rcs -l + co -u failed"; exit 1; }
148rm -f a.c &&
149echo error >a.c || exit 2
150ci -mm $q a.c 2>/dev/null && { echo "#co -u didn't unlock the file"; exit 1; }
151
152rm -f a.c &&
153cp a.11 a.c &&
154co -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
157co -p1.1 $q a.c >a.t &&
158$diff a.11 a.t || { echo "#co -p failed"; exit 1; }
159
160for n in n N
161do
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; }
169done
170
171case $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
183esac
184
185
186# Get the date of the previous revision in UTC.
187date=`rlog -r a.c | sed -n '/^date: /{ s///; s/;.*//; p; q; }'` || exit
188case $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
191esac
192PWD=`pwd` && export PWD &&
193rm -f a.c &&
194co -l $q a.c &&
195sed '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 @
210EOF
211test $? = 0 &&
212sed 's/:.*\$/$/' a.kv >a.k &&
213sed -e 's/w s [$]/w s '"$me"' $/' -e 's/[$]Locker: /&'"$me/" a.kv >a.kvl &&
214sed s/Oz//g a.kv >a.e &&
215sed s/Oz/N/g a.kv >a.N &&
216sed -e '/\$/!d' -e 's/\$$/: old $/' a.k >a.o &&
217sed -e 's/\$[^ ]*: //' -e 's/ \$//' a.kv >a.v &&
218cp a.o a.c &&
219ci -d"$date" -nOz -ss -ww -u2.1 -mm $q a.c &&
220$diff a.kv a.c || { echo "#keyword expansion failed"; exit 1; }
221co -pOz -ko $q a.c >a.oo &&
222$diff a.o a.oo || { echo "#co -p -ko failed"; exit 1; }
223cp a.kv a.o && cp a.o a.b || exit 2
224rcs -oOz $q a.c &&
225rcs -l $q a.c &&
226ci -k -u $q a.c &&
227$diff a.kv a.c || { echo "#ci -k failed"; exit 1; }
228sed -n 's/^[^$]*\$/$/p' a.kv >a.i &&
229ident a.c >a.i1 &&
230sed -e 1d -e 's/^[	 ]*//' a.i1 >a.i2 &&
231$diff a.i a.i2 || { echo "#ident failed"; exit 1; }
232
233rcs -i $q a.c 2>/dev/null && { echo "#rcs -i permitted existing file"; exit 1; }
234
235rm -f a.c &&
236co -l $q a.c &&
237echo 2.2 >a.c &&
238ci -mm $q a.c &&
239echo 1.1.1.2 >a.c &&
240rcs -l1.1.1 $q a.c &&
241ci -r1.1.1.2 -mm $q a.c &&
242rcs -b1.1.1 $q a.c &&
243test " `co -p $q a.c`" = ' 1.1.1.2' || { echo "#rcs -b1.1.1 failed"; exit 1; }
244rcs -b $q a.c &&
245test " `co -p $q a.c`" = ' 2.2' || { echo "#rcs -b failed"; exit 1; }
246
247echo 2.3 >a.c || exit 2
248rcs -U $q a.c || { echo "#rcs -U failed"; exit 1; }
249ci -mm $q a.c || { echo "#rcs -U didn't unset strict locking"; exit 1; }
250rcs -L $q a.c || { echo "#rcs -L failed"; exit 1; }
251echo error >a.c || exit 2
252ci -mm $q a.c 2>/dev/null && { echo "#ci retest failed"; exit 1; }
253
254rm -f a.c &&
255log0=`rlog -h a.c` &&
256co -l $q a.c &&
257ci -mm $q a.c &&
258log1=`rlog -h a.c` &&
259test " $log0" = " $log1" || { echo "#unchanged ci didn't revert"; exit 1; }
260
261rm -f a.c &&
262rcs -nN:1.1 $q a.c &&
263co -rN $q a.c &&
264$diff a.11 a.c || { echo "#rcs -n failed"; exit 1; }
265
266rm -f a.c &&
267rcs -NN:2.1 $q a.c &&
268co -rN $q a.c &&
269$diff a.N a.c || { echo "#rcs -N failed"; exit 1; }
270
271rm -f a.c &&
272co -l $q a.c &&
273echo ':::$''Log$' >a.c &&
274ci -u -mm $q a.c &&
275test " `sed '$!d' a.c`" = ' :::' || { echo "#comment leader failed"; exit 1; }
276
277rm -f a.c &&
278rcs -o2.2: $q a.c &&
279co $q a.c &&
280$diff a.e a.c || { echo "#rcs -o failed"; exit 1; }
281
282rcsdiff -r1.1 -rOz $q a.c >a.0
283case $? in
2841) ;;
285*) echo "#rcsdiff bad status"; exit 1
286esac
287$DIFF a.11 a.kv >a.1
288$diff a.0 a.1 || { echo "#rcsdiff failed"; exit 1; }
289
290rcs -l2.1 $q a.c || { echo "#rcs -l2.1 failed"; exit 1; }
291for i in b k kv kvl o v
292do
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; }
296done
297co -p1.1 -ko $q a.c >a.t &&
298$diff a.11 a.t || { echo "#co -p1.1 -ko failed"; exit 1; }
299rcs -u2.1 $q a.c || { echo "#rcs -u2.1 failed"; exit 1; }
300
301rm -f a.c &&
302rcsclean $q a.c &&
303rcsclean -u $q a.c || { echo "#rcsclean botched a nonexistent file"; exit 1; }
304
305rm -f a.c &&
306co $q a.c &&
307rcsclean -n $q a.c &&
308rcsclean -n -u $q a.c &&
309test -f a.c || { echo "#rcsclean -n removed a file"; exit 1; }
310
311rm -f a.c &&
312co $q a.c &&
313rcsclean $q a.c &&
314test ! -f a.c || { echo "#rcsclean missed an unlocked file"; exit 1; }
315
316rm -f a.c &&
317co -l $q a.c &&
318rcsclean $q a.c &&
319test -f a.c || { echo "#rcsclean removed a locked file"; exit 1; }
320rcsclean -u $q a.c &&
321test ! -f a.c || {
322	echo "#rcsclean -u missed an unchanged locked file"; exit 1;
323}
324
325rm -f a.c &&
326co -l $q a.c &&
327echo change >>a.c &&
328rcsclean $q a.c &&
329rcsclean $q -u a.c &&
330test -f a.c || { echo "#rcsclean removed a changed file"; exit 1; }
331
332rm -f a.c &&
333co -l $q a.c &&
334cat >a.c <<'EOF'
3352.2
336a
337b
338c
339d
340EOF
341test $? = 0 &&
342ci -l -mm $q a.c &&
343co -p2.2 $q a.c | sed -e s/2.2/2.3/ -e s/b/b1/ >a.c &&
344ci -l -mm $q a.c &&
345co -p2.2 $q a.c | sed -e s/2.2/new/ -e s/d/d1/ >a.c || exit 2
346cat >a.0 <<'EOF'
3472.3
348a
349b1
350c
351d1
352EOF
353cat >a.1 <<'EOF'
354<<<<<<< a.c
355new
356=======
3572.3
358>>>>>>> 2.3
359a
360b1
361c
362d1
363EOF
364rcsmerge -E -r2.2 -r2.3 $q a.c
365case $? in
3660)
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	;;
3761)
377	$diff a.1 a.c || { echo "#rcsmerge failed (status 1)"; exit 1; }
378	;;
379*)
380	echo "#rcsmerge bad status"; exit 1
381esac
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.
387cat >a.c <<'EOF'
388#include <stdio.h>
389int main() {
390	int c;
391	while ((c=getchar()) != EOF)
392		putchar(c ^ '\n');
393	return 0;
394}
395EOF
396tr=tr
397if (rm -f a.exe a.out && $CL a.c $L >&2) >/dev/null 2>&1
398then
399	if test -s a.out
400	then tr=./a.out
401	elif test -s a.exe
402	then tr=./a.exe
403	fi
404fi
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
421rcs -u -o2.4: $q a.c || { echo "#rcs -u -o failed"; exit 1; }
422
423rcs -i -Aa.c -t- $q a.d || { echo "#rcs -i -A failed"; exit 1; }
424
425rlog -r2.1 a.c >a.t &&
426grep '^checked in with -k' a.t >/dev/null &&
427sed '/^checked in with -k/d' a.t >a.u &&
428$diff - a.u <<EOF
429
430RCS file: $RCSfile
431Working file: a.c
432head: 2.3
433branch:
434locks: strict
435access list:
436symbolic names:
437	N: 2.1
438	Oz: 2.1
439	n: 1.8
440keyword substitution: kv
441total revisions: 13;	selected revisions: 1
442description:
4431.1
444----------------------------
445revision 2.1
446date: $date;  author: w;  state: s;  lines: +14 -1
447=============================================================================
448EOF
449test $? = 0 || { echo "#rlog failed"; exit 1; }
450
451
452test ! -f $lockfile || { echo "#lock file not removed"; exit 1; }
453
454rm -f a.* $RCSfile $RCS_alt
455$rmdir RCS
456