home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 22 gnu / 22-gnu.zip / rcs567s.zip / rcs / src / rcstest < prev    next >
Text File  |  1994-03-20  |  11KB  |  454 lines

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