PageRenderTime 3256ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 1ms

/src/freebsd/contrib/cvs/src/sanity.sh

https://bitbucket.org/killerpenguinassassins/open_distrib_devel
Shell | 1901 lines | 1360 code | 228 blank | 313 comment | 104 complexity | 6f832bed8d77cb0f940f92906595fc5d MD5 | raw file
Possible License(s): CC0-1.0, MIT, LGPL-2.0, LGPL-3.0, WTFPL, GPL-2.0, BSD-2-Clause, AGPL-3.0, CC-BY-SA-3.0, MPL-2.0, JSON, BSD-3-Clause-No-Nuclear-License-2014, LGPL-2.1, CPL-1.0, AGPL-1.0, 0BSD, ISC, Apache-2.0, GPL-3.0, IPL-1.0, MPL-2.0-no-copyleft-exception, BSD-3-Clause
  1. #! /bin/sh
  2. :
  3. # sanity.sh -- a growing testsuite for cvs.
  4. #
  5. # The copyright notice said: "Copyright (C) 1992, 1993 Cygnus Support"
  6. # I'm not adding new copyright notices for new years as our recent
  7. # practice has been to include copying terms without copyright notices.
  8. #
  9. # This program is free software; you can redistribute it and/or modify
  10. # it under the terms of the GNU General Public License as published by
  11. # the Free Software Foundation; either version 2, or (at your option)
  12. # any later version.
  13. #
  14. # This program is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. # GNU General Public License for more details.
  18. #
  19. # Original Author: K. Richard Pixley
  20. # usage:
  21. usage ()
  22. {
  23. echo "Usage: `basename $0` --help"
  24. echo "Usage: `basename $0` [-eklrv] [-f FROM-TEST] [-h HOSTNAME] CVS-TO-TEST [TESTS-TO-RUN...]"
  25. }
  26. exit_usage ()
  27. {
  28. usage 1>&2
  29. exit 2
  30. }
  31. exit_help ()
  32. {
  33. usage
  34. echo
  35. echo "-H|--help Display this text."
  36. echo "-e|--skipfail Treat tests that would otherwise be nonfatally skipped"
  37. echo " for reasons like missing tools as failures, exiting"
  38. echo " with an error message. Also treat warnings as"
  39. echo " failures."
  40. echo "-f FROM-TEST Run TESTS-TO-RUN, skipping all tests in the list before"
  41. echo " FROM-TEST."
  42. echo "-h HOSTNAME Use :ext:HOSTNAME to run remote tests rather than"
  43. echo " :fork:. Implies --remote and assumes that \$TESTDIR"
  44. echo " resolves to the same directory on both the client and"
  45. echo " the server."
  46. echo "-k|--keep Try to keep directories created by individual tests"
  47. echo " around, exiting after the first test which supports"
  48. echo " --keep."
  49. echo "-l|--link-root"
  50. echo " Test CVS using a symlink to a real CVSROOT."
  51. echo "-r|--remote Test remote instead of local cvs."
  52. echo "-v|--verbose List test names as they are executed."
  53. echo
  54. echo "CVS-TO-TEST The path to the CVS executable to be tested."
  55. echo "TESTS-TO-RUN The names of the tests to run (defaults to all tests)."
  56. exit 2
  57. }
  58. # See TODO list at end of file.
  59. # required to make this script work properly.
  60. unset CVSREAD
  61. # This will cause malloc to run slower but should also catch some common errors
  62. # when CVS is linked with glibc 2.x.
  63. MALLOC_CHECK_=2; export MALLOC_CHECK_
  64. # We want to invoke a predictable set of i18n behaviors, not whatever
  65. # the user running this script might have set.
  66. # In particular:
  67. # 'sort' and tabs and spaces (LC_COLLATE).
  68. # Messages from getopt (LC_MESSAGES) (in the future, CVS itself might
  69. # also alter its messages based on LC_MESSAGES).
  70. LANG=C
  71. export LANG
  72. LC_ALL=C
  73. export LC_ALL
  74. #
  75. # Initialize the test counts.
  76. #
  77. passed=0
  78. skipped=0
  79. warnings=0
  80. #
  81. # read our options
  82. #
  83. unset fromtest
  84. unset remotehost
  85. keep=false
  86. linkroot=false
  87. remote=false
  88. skipfail=false
  89. verbose=false
  90. while getopts ef:h:Hklrv-: option ; do
  91. # convert the long opts to short opts
  92. if test x$option = x-; then
  93. case "$OPTARG" in
  94. [hH]|[hH][eE]|[hH][eE][lL]|[hH][eE][lL][pP])
  95. option=H;
  96. OPTARG=
  97. ;;
  98. [kK]|[kK][eE]|[kK][eE][eE]|[kK][eE][eE][pP])
  99. option=k;
  100. OPTARG=
  101. ;;
  102. l|li|lin|link|link-|link-r]|link-ro|link-roo|link-root)
  103. option=l;
  104. OPTARG=
  105. ;;
  106. [rR]|[rR][eE]|[rR][eE][mM]|[rR][eE][mM][oO]|[rR][eE][mM][oO][tT]|[rR][eE][mM][oO][tT][eE])
  107. option=k;
  108. OPTARG=
  109. ;;
  110. s|sk|ski|skip|skipf|skipfa|skipfai|skipfail)
  111. option=e
  112. OPTARG=
  113. ;;
  114. v|ve|ver|verb|verbo|verbos|verbose)
  115. option=v
  116. OPTARG=
  117. ;;
  118. *)
  119. option=\?
  120. OPTARG=
  121. esac
  122. fi
  123. case "$option" in
  124. e)
  125. skipfail=:
  126. ;;
  127. f)
  128. fromtest="$OPTARG"
  129. ;;
  130. h)
  131. # Set a remotehost to run the remote tests on via :ext:
  132. # Implies `-r' and assumes that $TESTDIR resolves to the same
  133. # directory on the client and the server.
  134. remotehost="$OPTARG"
  135. remote=:
  136. ;;
  137. H)
  138. exit_help
  139. ;;
  140. k)
  141. # The -k (keep) option will eventually cause all the tests to
  142. # leave around the contents of the /tmp directory; right now only
  143. # some implement it. Not originally intended to be useful with
  144. # more than one test, but this should work if each test uses a
  145. # uniquely named dir (use the name of the test).
  146. keep=:
  147. ;;
  148. l)
  149. linkroot=:
  150. ;;
  151. r)
  152. remote=:
  153. ;;
  154. v)
  155. verbose=:
  156. ;;
  157. \?)
  158. exit_usage
  159. ;;
  160. esac
  161. done
  162. # boot the arguments we used above
  163. while test $OPTIND -gt 1 ; do
  164. shift
  165. OPTIND=`expr $OPTIND - 1`
  166. done
  167. # Use full path for CVS executable, so that CVS_SERVER gets set properly
  168. # for remote.
  169. case $1 in
  170. "")
  171. exit_usage
  172. ;;
  173. /*)
  174. testcvs=$1
  175. ;;
  176. *)
  177. testcvs=`pwd`/$1
  178. ;;
  179. esac
  180. shift
  181. # If $remotehost is set, warn if $TESTDIR isn't since we are pretty sure
  182. # that its default value of `/tmp/cvs-sanity' will not resolve to the same
  183. # directory on two different machines.
  184. if test -n "$remotehost" && test -z "$TESTDIR"; then
  185. echo "WARNING: CVS server hostname is set and \$TESTDIR is not. If" >&2
  186. echo "$remotehost is not the local machine, then it is unlikely that" >&2
  187. echo "the default value assigned to \$TESTDIR will resolve to the same" >&2
  188. echo "directory on both this client and the CVS server." >&2
  189. fi
  190. ###
  191. ### GUTS
  192. ###
  193. # "debugger"
  194. #set -x
  195. echo 'This test should produce no other output than this message, and a final "OK".'
  196. echo '(Note that the test can take an hour or more to run and periodically stops'
  197. echo 'for as long as one minute. Do not assume there is a problem just because'
  198. echo 'nothing seems to happen for a long time. If you cannot live without'
  199. echo 'running status, use the -v option or try the command:'
  200. echo "\`tail -f check.log' from another window.)"
  201. # Regexp to match what CVS will call itself in output that it prints.
  202. # FIXME: we don't properly quote this--if the name contains . we'll
  203. # just spuriously match a few things; if the name contains other regexp
  204. # special characters we are probably in big trouble.
  205. PROG=`basename ${testcvs}`
  206. # Match the hostname
  207. hostname="[-_.a-zA-Z0-9]*"
  208. # Regexp to match the name of a temporary file (from cvs_temp_name).
  209. # This appears in certain diff output.
  210. tempname="[-a-zA-Z0-9/.%_]*"
  211. # Regexp to match a date in RFC822 format (as amended by RFC1123).
  212. RFCDATE="[a-zA-Z0-9 ][a-zA-Z0-9 ]* [0-9:][0-9:]* -0000"
  213. RFCDATE_EPOCH="1 Jan 1970 00:00:00 -0000"
  214. # Regexp to match a date in standard Unix format as used by rdiff
  215. # FIXCVS: There's no reason for rdiff to use a different date format
  216. # than diff does
  217. DATE="[a-zA-Z]* [a-zA-Z]* [ 1-3][0-9] [0-9:]* [0-9]*"
  218. # Which directories should Which and find_tool search for executables?
  219. SEARCHPATH=$PATH:/usr/local/bin:/usr/contrib/bin:/usr/contrib:/usr/gnu/bin:/local/bin:/local/gnu/bin:/gnu/bin:/sw/bin:/usr/pkg/bin
  220. # Do not assume that `type -p cmd` is portable
  221. # Usage: Which [-a] [-x|-f|-r] prog [$SEARCHPATH:/with/directories:/to/search]
  222. Which() {
  223. # Optional first argument for file type, defaults to -x.
  224. # Second argument is the file or directory to be found.
  225. # Third argument is the PATH to search.
  226. # By default, print only the first file that matches,
  227. # -a will cause all matches to be printed.
  228. notevery=:
  229. if [ "x$1" = "x-a" ]; then notevery=false; shift; fi
  230. case "$1" in
  231. -*) t=$1; shift ;;
  232. *) t=-x ;;
  233. esac
  234. case "$1" in
  235. # FIXME: Someday this may need to be fixed
  236. # to deal better with C:\some\path\to\ssh values...
  237. /*) test $t $1 && echo $1 ;;
  238. *) for d in `IFS=:; echo ${2-$SEARCHPATH}`
  239. do
  240. test $t $d/$1 && { echo $d/$1; if $notevery; then break; fi; }
  241. done
  242. ;;
  243. esac
  244. }
  245. # On cygwin32, we may not have /bin/sh.
  246. if test -r /bin/sh; then
  247. TESTSHELL="/bin/sh"
  248. else
  249. TESTSHELL=`Which -f sh`
  250. if test ! -r "$TESTSHELL"; then
  251. TESTSHELL="/bin/sh"
  252. fi
  253. fi
  254. # FIXME: try things (what things? checkins?) without -m.
  255. #
  256. # Some of these tests are written to expect -Q. But testing with
  257. # -Q is kind of bogus, it is not the way users actually use CVS (usually).
  258. # So new tests probably should invoke ${testcvs} directly, rather than ${CVS}.
  259. # and then they've obviously got to do something with the output....
  260. #
  261. CVS="${testcvs} -Q"
  262. LOGFILE=`pwd`/check.log
  263. # Save the previous log in case the person running the tests decides
  264. # they want to look at it. The extension ".plog" is chosen for consistency
  265. # with dejagnu.
  266. if test -f check.log; then
  267. mv check.log check.plog
  268. fi
  269. # Create the log file so check.log can be tailed almost immediately after
  270. # this script is started. Otherwise it can take up to a minute or two before
  271. # the log file gets created when $remotehost is specified on some systems,
  272. # which makes for a lot of failed `tail -f' attempts.
  273. touch check.log
  274. # Workaround any X11Forwarding by ssh. Otherwise this text:
  275. # Warning: No xauth data; using fake authentication data for X11 forwarding.
  276. # has been known to end up in the test results below
  277. # causing the test to fail.
  278. [ -n "$DISPLAY" ] && unset DISPLAY
  279. # The default value of /tmp/cvs-sanity for TESTDIR is dubious,
  280. # because it loses if two people/scripts try to run the tests
  281. # at the same time. Some possible solutions:
  282. # 1. Use /tmp/cvs-test$$. One disadvantage is that the old
  283. # cvs-test* directories would pile up, because they wouldn't
  284. # necessarily get removed.
  285. # 2. Have everyone/everything running the testsuite set
  286. # TESTDIR to some appropriate directory.
  287. # 3. Have the default value of TESTDIR be some variation of
  288. # `pwd`/cvs-sanity. The biggest problem here is that we have
  289. # been fairly careful to test that CVS prints in messages the
  290. # actual pathnames that we pass to it, rather than a different
  291. # pathname for the same directory, as may come out of `pwd`.
  292. # So this would be lost if everything was `pwd`-based. I suppose
  293. # if we wanted to get baroque we could start making symlinks
  294. # to ensure the two are different.
  295. : ${CVS_RSH=rsh}; export CVS_RSH
  296. if test -n "$remotehost"; then
  297. # We need to set $tmp on the server since $TMPDIR is compared against
  298. # messages generated by the server.
  299. tmp=`$CVS_RSH $remotehost 'cd /tmp; /bin/pwd || pwd' 2>/dev/null`
  300. if test $? != 0; then
  301. echo "$CVS_RSH $remotehost failed." >&2
  302. exit 1
  303. fi
  304. else
  305. tmp=`(cd /tmp; /bin/pwd || pwd) 2>/dev/null`
  306. fi
  307. # Now:
  308. # 1) Set TESTDIR if it's not set already
  309. # 2) Remove any old test remnants
  310. # 3) Create $TESTDIR
  311. # 4) Normalize TESTDIR with `cd && (/bin/pwd || pwd)`
  312. # (This will match CVS output later)
  313. : ${TESTDIR=$tmp/cvs-sanity}
  314. # clean any old remnants (we need the chmod because some tests make
  315. # directories read-only)
  316. if test -d ${TESTDIR}; then
  317. chmod -R a+wx ${TESTDIR}
  318. rm -rf ${TESTDIR}
  319. fi
  320. # These exits are important. The first time I tried this, if the `mkdir && cd`
  321. # failed then the build directory would get blown away. Some people probably
  322. # wouldn't appreciate that.
  323. mkdir ${TESTDIR} || exit 1
  324. cd ${TESTDIR} || exit 1
  325. # Ensure $TESTDIR is absolute
  326. if echo "${TESTDIR}" |grep '^[^/]'; then
  327. # Don't resolve this unless we have to. This keeps symlinks intact. This
  328. # is important at least when testing using -h $remotehost, because the same
  329. # value for $TESTDIR must resolve to the same directory on the client and
  330. # the server and we likely used Samba, and possibly symlinks, to do this.
  331. TESTDIR=`(/bin/pwd || pwd) 2>/dev/null`
  332. fi
  333. if test -z "${TESTDIR}" || echo "${TESTDIR}" |grep '^[^/]'; then
  334. echo "Unable to resolve TESTDIR to an absolute directory." >&2
  335. exit 1
  336. fi
  337. cd ${TESTDIR}
  338. # Now set $TMPDIR if the user hasn't overridden it.
  339. #
  340. # We use a $TMPDIR under $TESTDIR by default so that two tests may be run at
  341. # the same time without bumping heads without requiring the user to specify
  342. # more than $TESTDIR. See the test for leftover cvs-serv* directories near the
  343. # end of this script at the end of "The big loop".
  344. : ${TMPDIR=$TESTDIR/tmp}
  345. export TMPDIR
  346. if test -d $TMPDIR; then :; else
  347. mkdir $TMPDIR
  348. fi
  349. # Make sure various tools work the way we expect, or try to find
  350. # versions that do.
  351. : ${AWK=awk}
  352. : ${EXPR=expr}
  353. : ${ID=id}
  354. : ${TR=tr}
  355. # Keep track of tools that are found, but do NOT work as we hope
  356. # in order to avoid them in future
  357. badtools=
  358. set_bad_tool ()
  359. {
  360. badtools=$badtools:$1
  361. }
  362. is_bad_tool ()
  363. {
  364. case ":$badtools:" in *:$1:*) return 0 ;; *) return 1 ; esac
  365. }
  366. version_test ()
  367. {
  368. vercmd=$1
  369. verbad=:
  370. if RES=`$vercmd --version </dev/null 2>&1`; then
  371. if test "X$RES" != "X--version" && test "X$RES" != "X" ; then
  372. echo "$RES"
  373. verbad=false
  374. fi
  375. fi
  376. if $verbad; then
  377. echo "The command \`$vercmd' does not support the --version option."
  378. fi
  379. # It does not really matter that --version is not supported
  380. return 0
  381. }
  382. # Try to find a tool that satisfies all of the tests.
  383. # Usage: list:of:colon:separated:alternatives test1 test2 test3 test4...
  384. # Example: find_tool awk:gawk:nawk awk_tooltest1 awk_tooltest2
  385. find_tool ()
  386. {
  387. default_TOOL=$1
  388. echo find_tool: ${1+"$@"} >>$LOGFILE
  389. cmds="`IFS=:; echo $1`"; shift; tooltests="${1+$@}"
  390. if test -z "$tooltests"; then tooltests=version_test; fi
  391. clist=; for cmd in $cmds; do clist="$clist `Which -a $cmd`"; done
  392. # Make sure the default tool is just the first real command name
  393. for default_TOOL in $clist `IFS=:; echo $default_TOOL`; do break; done
  394. TOOL=""
  395. for trytool in $clist ; do
  396. pass=:
  397. for tooltest in $tooltests; do
  398. result=`eval $tooltest $trytool`
  399. rc=$?
  400. echo "Running $tooltest $trytool" >>$LOGFILE
  401. if test -n "$result"; then
  402. echo "$result" >>$LOGFILE
  403. fi
  404. if test "$rc" = "0"; then
  405. echo "PASS: $tooltest $trytool" >>$LOGFILE
  406. elif test "$rc" = "77"; then
  407. echo "MARGINAL: $tooltest $trytool; rc=$rc" >>$LOGFILE
  408. TOOL=$trytool
  409. pass=false
  410. else
  411. set_bad_tool $trytool
  412. echo "FAIL: $tooltest $trytool; rc=$rc" >>$LOGFILE
  413. pass=false
  414. fi
  415. done
  416. if $pass; then
  417. echo $trytool
  418. return 0
  419. fi
  420. done
  421. if test -n "$TOOL"; then
  422. echo "Notice: The default version of \`$default_TOOL' is defective." >>$LOGFILE
  423. echo "using \`$TOOL' and hoping for the best." >>$LOGFILE
  424. echo "Notice: The default version of \`$default_TOOL' is defective." >&2
  425. echo "using \`$TOOL' and hoping for the best." >&2
  426. echo $TOOL
  427. else
  428. echo $default_TOOL
  429. fi
  430. }
  431. id_tool_test ()
  432. {
  433. id=$1
  434. if $id -u >/dev/null 2>&1 && $id -un >/dev/null 2>&1; then
  435. return 0
  436. else
  437. echo "Running these tests requires an \`id' program that understands the"
  438. echo "-u and -n flags. Make sure that such an id (GNU, or many but not"
  439. echo "all vendor-supplied versions) is in your path."
  440. return 1
  441. fi
  442. }
  443. ID=`find_tool id version_test id_tool_test`
  444. echo "Using ID=$ID" >>$LOGFILE
  445. # You can't run CVS as root; print a nice error message here instead
  446. # of somewhere later, after making a mess.
  447. for pass in false :; do
  448. case "`$ID -u 2>/dev/null`" in
  449. "0")
  450. echo "Test suite does not work correctly when run as root" >&2
  451. exit 1
  452. ;;
  453. *)
  454. break
  455. ;;
  456. esac
  457. done
  458. # Cause NextStep 3.3 users to lose in a more graceful fashion.
  459. expr_tooltest1 ()
  460. {
  461. expr=$1
  462. if $expr 'abc
  463. def' : 'abc
  464. def' >/dev/null; then
  465. # good, it works
  466. return 0
  467. else
  468. echo 'Running these tests requires an "expr" program that can handle'
  469. echo 'multi-line patterns. Make sure that such an expr (GNU, or many but'
  470. echo 'not all vendor-supplied versions) is in your path.'
  471. return 1
  472. fi
  473. }
  474. # Warn SunOS, SysVr3.2, etc., users that they may be partially losing
  475. # if we can't find a GNU expr to ease their troubles...
  476. expr_tooltest2 ()
  477. {
  478. expr=$1
  479. if $expr 'a
  480. b' : 'a
  481. c' >/dev/null; then
  482. echo 'WARNING: you are using a version of expr that does not correctly'
  483. echo 'match multi-line patterns. Some tests may spuriously pass or fail.'
  484. echo 'You may wish to make sure GNU expr is in your path.'
  485. return 1
  486. else
  487. return 0
  488. fi
  489. }
  490. expr_create_bar ()
  491. {
  492. echo 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' >${TESTDIR}/foo
  493. cat ${TESTDIR}/foo ${TESTDIR}/foo ${TESTDIR}/foo ${TESTDIR}/foo >${TESTDIR}/bar
  494. cat ${TESTDIR}/bar ${TESTDIR}/bar ${TESTDIR}/bar ${TESTDIR}/bar >${TESTDIR}/foo
  495. cat ${TESTDIR}/foo ${TESTDIR}/foo ${TESTDIR}/foo ${TESTDIR}/foo >${TESTDIR}/bar
  496. rm -f ${TESTDIR}/foo
  497. }
  498. expr_tooltest3 ()
  499. {
  500. expr=$1
  501. # More SunOS lossage...
  502. test ! -f ${TESTDIR}/bar && expr_create_bar
  503. if $expr "`cat ${TESTDIR}/bar`" : "`cat ${TESTDIR}/bar`" >/dev/null; then
  504. : good, it works
  505. else
  506. echo 'WARNING: you are using a version of expr that does not correctly'
  507. echo 'match large patterns. Some tests may spuriously pass or fail.'
  508. echo 'You may wish to make sure GNU expr is in your path.'
  509. return 1
  510. fi
  511. if $expr "`cat ${TESTDIR}/bar`x" : "`cat ${TESTDIR}/bar`y" >/dev/null; then
  512. echo 'WARNING: you are using a version of expr that does not correctly'
  513. echo 'match large patterns. Some tests may spuriously pass or fail.'
  514. echo 'You may wish to make sure GNU expr is in your path.'
  515. return 1
  516. fi
  517. # good, it works
  518. return 0
  519. }
  520. # That we should have to do this is total bogosity, but GNU expr
  521. # version 1.9.4-1.12 uses the emacs definition of "$" instead of the unix
  522. # (e.g. SunOS 4.1.3 expr) one. Rumor has it this will be fixed in the
  523. # next release of GNU expr after 1.12 (but we still have to cater to the old
  524. # ones for some time because they are in many linux distributions).
  525. ENDANCHOR="$"
  526. expr_set_ENDANCHOR ()
  527. {
  528. expr=$1
  529. ENDANCHOR="$"
  530. if $expr 'abc
  531. def' : 'abc$' >/dev/null; then
  532. ENDANCHOR='\'\'
  533. echo "Notice: An ENDANCHOR of dollar does not work."
  534. echo "Using a workaround for GNU expr versions 1.9.4 thru 1.12"
  535. fi
  536. return 0
  537. }
  538. # Work around another GNU expr (version 1.10-1.12) bug/incompatibility.
  539. # "." doesn't appear to match a newline (it does with SunOS 4.1.3 expr).
  540. # Note that the workaround is not a complete equivalent of .* because
  541. # the first parenthesized expression in the regexp must match something
  542. # in order for expr to return a successful exit status.
  543. # Rumor has it this will be fixed in the
  544. # next release of GNU expr after 1.12 (but we still have to cater to the old
  545. # ones for some time because they are in many linux distributions).
  546. DOTSTAR='.*'
  547. expr_set_DOTSTAR ()
  548. {
  549. expr=$1
  550. DOTSTAR='.*'
  551. if $expr 'abc
  552. def' : "a${DOTSTAR}f" >/dev/null; then
  553. : good, it works
  554. else
  555. DOTSTAR='\(.\|
  556. \)*'
  557. echo "Notice: DOTSTAR changed from sane \`.*' value to \`$DOTSTAR\`"
  558. echo "to workaround GNU expr version 1.10 thru 1.12 bug where \`.'"
  559. echo "does not match a newline."
  560. fi
  561. return 0
  562. }
  563. # Now that we have DOTSTAR, make sure it works with big matches
  564. expr_tooltest_DOTSTAR ()
  565. {
  566. expr=$1
  567. test ! -f ${TESTDIR}/bar && expr_create_bar
  568. if $expr "`cat ${TESTDIR}/bar`" : "${DOTSTAR}xyzABC${DOTSTAR}$" >/dev/null; then
  569. # good, it works
  570. return 0
  571. else
  572. echo 'WARNING: you are using a version of expr that does not correctly'
  573. echo 'match large patterns. Some tests may spuriously pass or fail.'
  574. echo 'You may wish to make sure GNU expr is in your path.'
  575. return 77
  576. fi
  577. }
  578. # FreeBSD 5.2 and 6.1 support 'expr [-e] expression'
  579. # They get confused unless '--' is used before the expressions
  580. # when those expressions begin with a '-' character, such as the
  581. # output of an ls -l command. The EXPR_COMPAT environment variable may
  582. # be used to go back to the non-POSIX behavior as an alternative.
  583. # (GNU expr appears to accept the '--' argument and work correctly or
  584. # not have it and still get the results we want.)
  585. exprDASHDASH='false'
  586. expr_set_DASHDASH ()
  587. {
  588. expr=$1
  589. exprDASHDASH='false'
  590. # Not POSIX, but works on a lot of expr versions.
  591. if $expr "-rw-rw-r--" : "-rw-rw-r--" >/dev/null 2>&1; then
  592. # good, it works
  593. return 0
  594. else
  595. # Do things in the POSIX manner.
  596. if $expr -- "-rw-rw-r--" : "-rw-rw-r--" >/dev/null 2>&1; then
  597. exprDASHDASH=':'
  598. return 0
  599. else
  600. echo 'WARNING: Your $expr does not correctly handle'
  601. echo 'leading "-" characters in regular expressions to'
  602. echo 'be matched. You may wish to see if there is an'
  603. echo 'environment variable or other setting to allow'
  604. echo 'POSIX functionality to be enabled.'
  605. return 77
  606. fi
  607. fi
  608. }
  609. EXPR=`find_tool ${EXPR}:gexpr \
  610. version_test expr_tooltest1 expr_tooltest2 expr_tooltest3 \
  611. expr_set_ENDANCHOR expr_set_DOTSTAR expr_tooltest_DOTSTAR`
  612. # Set the ENDANCHOR and DOTSTAR for the chosen expr version.
  613. expr_set_ENDANCHOR ${EXPR} >/dev/null
  614. expr_tooltest_DOTSTAR ${EXPR} >/dev/null
  615. # Is $EXPR a POSIX or non-POSIX implementation
  616. # with regard to command-line arguments?
  617. expr_set_DASHDASH ${EXPR}
  618. $exprDASHDASH && EXPR="$EXPR --"
  619. echo "Using EXPR=$EXPR" >>$LOGFILE
  620. echo "Using ENDANCHOR=$ENDANCHOR" >>$LOGFILE
  621. echo "Using DOTSTAR=$DOTSTAR" >>$LOGFILE
  622. # Cleanup
  623. rm -f ${TESTDIR}/bar
  624. # Work around yet another GNU expr (version 1.10) bug/incompatibility.
  625. # "+" is a special character, yet for unix expr (e.g. SunOS 4.1.3)
  626. # it is not. I doubt that POSIX allows us to use \+ and assume it means
  627. # (non-special) +, so here is another workaround
  628. # Rumor has it this will be fixed in the
  629. # next release of GNU expr after 1.12 (but we still have to cater to the old
  630. # ones for some time because they are in many linux distributions).
  631. PLUS='+'
  632. if $EXPR 'a +b' : "a ${PLUS}b" >/dev/null; then
  633. : good, it works
  634. else
  635. PLUS='\+'
  636. fi
  637. # Likewise, for ?
  638. QUESTION='?'
  639. if $EXPR 'a?b' : "a${QUESTION}b" >/dev/null; then
  640. : good, it works
  641. else
  642. QUESTION='\?'
  643. fi
  644. # Now test the username to make sure it contains only valid characters
  645. username=`$ID -un`
  646. if $EXPR "${username}" : "${username}" >/dev/null; then
  647. : good, it works
  648. else
  649. echo "Test suite does not work correctly when run by a username" >&2
  650. echo "containing regular expression meta-characters." >&2
  651. exit 1
  652. fi
  653. # Only 8 characters of $username appear in some output.
  654. if test `echo $username |wc -c` -gt 8; then
  655. username8=`echo $username |sed 's/^\(........\).*/\1/'`
  656. else
  657. username8=$username
  658. fi
  659. # Rarely, we need to match any username, not just the name of the user
  660. # running this test.
  661. #
  662. # I'm not really sure what characters should be here. a-zA-Z obviously.
  663. # People complained when 0-9 were not allowed in usernames. Other than that
  664. # I'm not sure.
  665. anyusername="[-a-zA-Z0-9][-a-zA-Z0-9]*"
  666. # now make sure that tr works on NULs
  667. tr_tooltest1 ()
  668. {
  669. tr=$1
  670. if $EXPR `echo "123" | $tr '2' '\0'` : "123" >/dev/null 2>&1; then
  671. echo 'Warning: you are using a version of tr which does not correctly'
  672. echo 'handle NUL bytes. Some tests may spuriously pass or fail.'
  673. echo 'You may wish to make sure GNU tr is in your path.'
  674. return 77
  675. fi
  676. # good, it works
  677. return 0
  678. }
  679. TR=`find_tool ${TR}:gtr version_test tr_tooltest1`
  680. echo "Using TR=$TR" >>$LOGFILE
  681. # Awk testing
  682. awk_tooltest1 ()
  683. {
  684. awk=$1
  685. $awk 'BEGIN {printf("one\ntwo\nthree\nfour\nfive\nsix")}' </dev/null >abc
  686. if $EXPR "`cat abc`" : \
  687. 'one
  688. two
  689. three
  690. four
  691. five
  692. six'; then
  693. rm abc
  694. return 0
  695. else
  696. rm abc
  697. echo "Notice: awk BEGIN clause or printf is not be working properly."
  698. return 1
  699. fi
  700. }
  701. # Format item %c check
  702. awk_tooltest2 ()
  703. {
  704. awk=$1
  705. $awk 'BEGIN { printf "%c%c%c", 2, 3, 4 }' </dev/null \
  706. | ${TR} '\002\003\004' '123' >abc
  707. if $EXPR "`cat abc`" : "123" ; then
  708. : good, found it
  709. else
  710. echo "Notice: awk format %c string may not be working properly."
  711. rm abc
  712. return 77
  713. fi
  714. rm abc
  715. return 0
  716. }
  717. AWK=`find_tool gawk:nawk:awk version_test awk_tooltest1 awk_tooltest2`
  718. echo "Using AWK=$AWK" >>$LOGFILE
  719. # Test that $1 works as a remote shell. If so, set $host, $CVS_RSH, &
  720. # $save_CVS_RSH to match and return 0. Otherwise, set $skipreason and return
  721. # 77.
  722. depends_on_rsh ()
  723. {
  724. host=${remotehost-"`hostname`"}
  725. result=`$1 $host 'echo test'`
  726. rc=$?
  727. if test $? != 0 || test "x$result" != "xtest"; then
  728. skipreason="\`$1 $host' failed rc=$rc result=$result"
  729. return 77
  730. fi
  731. save_CVS_RSH=$CVS_RSH
  732. CVS_RSH=$1; export CVS_RSH
  733. return 0
  734. }
  735. # Find a usable SSH. When a usable ssh is found, set $host, $CVS_RSH, and
  736. # $save_CVS_RSH and return 0. Otherwise, set $skipreason and return 77.
  737. depends_on_ssh ()
  738. {
  739. case "$CVS_RSH" in
  740. *ssh*|*putty*)
  741. tryssh=`Which $CVS_RSH`
  742. if [ ! -n "$tryssh" ]; then
  743. skipreason="Unable to find CVS_RSH=$CVS_RSH executable"
  744. return 77
  745. elif [ ! -x "$tryssh" ]; then
  746. skipreason="Unable to execute $tryssh program"
  747. return 77
  748. fi
  749. ;;
  750. *)
  751. # Look in the user's PATH for "ssh"
  752. tryssh=`Which ssh`
  753. if test ! -r "$tryssh"; then
  754. skipreason="Unable to find ssh program"
  755. return 77
  756. fi
  757. ;;
  758. esac
  759. depends_on_rsh "$tryssh"
  760. return $?
  761. }
  762. pass ()
  763. {
  764. echo "PASS: $1" >>${LOGFILE}
  765. passed=`expr $passed + 1`
  766. }
  767. # Like skip(), but don't fail when $skipfail is set.
  768. skip_always ()
  769. {
  770. echo "SKIP: $1${2+ ($2)}" >>$LOGFILE
  771. skipped=`expr $skipped + 1`
  772. }
  773. skip ()
  774. {
  775. if $skipfail; then
  776. fail "$1${2+ ($2)}"
  777. else
  778. echo "SKIP: $1${2+ ($2)}" >>$LOGFILE
  779. fi
  780. skipped=`expr $skipped + 1`
  781. }
  782. warn ()
  783. {
  784. if $skipfail; then
  785. fail "$1${2+ ($2)}"
  786. else
  787. echo "WARNING: $1${2+ ($2)}" >>$LOGFILE
  788. fi
  789. warnings=`expr $warnings + 1`
  790. }
  791. # Convenience function for skipping tests run only in local mode.
  792. localonly ()
  793. {
  794. skip_always $1 "only tested in local mode"
  795. }
  796. fail ()
  797. {
  798. echo "FAIL: $1" | tee -a ${LOGFILE}
  799. echo "*** Please see the \`TESTS' and \`check.log' files for more information." >&2
  800. # This way the tester can go and see what remnants were left
  801. exit 1
  802. }
  803. verify_tmp_empty ()
  804. {
  805. # Test our temp directory for cvs-serv* directories and cvsXXXXXX temp
  806. # files. We would like to not leave any behind.
  807. if $remote && ls $TMPDIR/cvs-serv* >/dev/null 2>&1; then
  808. # A true value means ls found files/directories with these names.
  809. # Give the server some time to finish, then retry.
  810. sleep 1
  811. if ls $TMPDIR/cvs-serv* >/dev/null 2>&1; then
  812. warn "$1" "Found cvs-serv* directories in $TMPDIR."
  813. # The above will exit if $skipfail
  814. rm -rf $TMPDIR/cvs-serv*
  815. fi
  816. fi
  817. if ls $TMPDIR/cvs?????? >/dev/null 2>&1; then
  818. # A true value means ls found files/directories with these names.
  819. warn "$1" "Found cvsXXXXXX temp files in $TMPDIR."
  820. # The above will exit if $skipfail
  821. rm -f ls $TMPDIR/cvs??????
  822. fi
  823. }
  824. # Restore changes to CVSROOT admin files.
  825. restore_adm ()
  826. {
  827. rm -rf $CVSROOT_DIRNAME/CVSROOT
  828. cp -Rp $TESTDIR/CVSROOT.save $CVSROOT_DIRNAME/CVSROOT
  829. }
  830. # See dotest and dotest_fail for explanation (this is the parts
  831. # of the implementation common to the two).
  832. dotest_internal ()
  833. {
  834. if $EXPR "`cat ${TESTDIR}/dotest.tmp`" : "$3${ENDANCHOR}" >/dev/null; then
  835. # Why, I hear you ask, do we write this to the logfile
  836. # even when the test passes? The reason is that the test
  837. # may give us the regexp which we were supposed to match,
  838. # but sometimes it may be useful to look at the exact
  839. # text which was output. For example, suppose one wants
  840. # to grep for a particular warning, and make _sure_ that
  841. # CVS never hits it (even in cases where the tests might
  842. # match it with .*). Or suppose one wants to see the exact
  843. # date format output in a certain case (where the test will
  844. # surely use a somewhat non-specific pattern).
  845. cat ${TESTDIR}/dotest.tmp >>${LOGFILE}
  846. pass "$1"
  847. verify_tmp_empty "$1"
  848. # expr can't distinguish between "zero characters matched" and "no match",
  849. # so special-case it.
  850. elif test -z "$3" && test ! -s ${TESTDIR}/dotest.tmp; then
  851. pass "$1"
  852. verify_tmp_empty "$1"
  853. elif test x"$4" != x; then
  854. if $EXPR "`cat ${TESTDIR}/dotest.tmp`" : "$4${ENDANCHOR}" >/dev/null; then
  855. cat ${TESTDIR}/dotest.tmp >>${LOGFILE}
  856. pass "$1"
  857. verify_tmp_empty "$1"
  858. else
  859. echo "** expected: " >>${LOGFILE}
  860. echo "$3" >>${LOGFILE}
  861. echo "$3" > ${TESTDIR}/dotest.ex1
  862. echo "** or: " >>${LOGFILE}
  863. echo "$4" >>${LOGFILE}
  864. echo "$4" > ${TESTDIR}/dotest.ex2
  865. echo "** got: " >>${LOGFILE}
  866. cat ${TESTDIR}/dotest.tmp >>${LOGFILE}
  867. fail "$1"
  868. fi
  869. else
  870. echo "** expected: " >>${LOGFILE}
  871. echo "$3" >>${LOGFILE}
  872. echo "$3" > ${TESTDIR}/dotest.exp
  873. echo "** got: " >>${LOGFILE}
  874. cat ${TESTDIR}/dotest.tmp >>${LOGFILE}
  875. fail "$1"
  876. fi
  877. }
  878. dotest_all_in_one ()
  879. {
  880. if $EXPR "`cat ${TESTDIR}/dotest.tmp`" : \
  881. "`cat ${TESTDIR}/dotest.exp`" >/dev/null; then
  882. return 0
  883. fi
  884. return 1
  885. }
  886. # WARNING: this won't work with REs that match newlines....
  887. #
  888. dotest_line_by_line ()
  889. {
  890. line=1
  891. while [ $line -le `wc -l <${TESTDIR}/dotest.tmp` ] ; do
  892. if $EXPR "`sed -n ${line}p ${TESTDIR}/dotest.tmp`" : \
  893. "`sed -n ${line}p ${TESTDIR}/dotest.exp`" >/dev/null; then
  894. :
  895. elif test -z "`sed -n ${line}p ${TESTDIR}/dotest.tmp`" &&
  896. test -z "`sed -n ${line}p ${TESTDIR}/dotest.exp`"; then
  897. :
  898. else
  899. echo "Line $line:" >> ${LOGFILE}
  900. echo "**** expected: " >>${LOGFILE}
  901. sed -n ${line}p ${TESTDIR}/dotest.exp >>${LOGFILE}
  902. echo "**** got: " >>${LOGFILE}
  903. sed -n ${line}p ${TESTDIR}/dotest.tmp >>${LOGFILE}
  904. unset line
  905. return 1
  906. fi
  907. line=`expr $line + 1`
  908. done
  909. unset line
  910. return 0
  911. }
  912. # If you are having trouble telling which line of a multi-line
  913. # expression is not being matched, replace calls to dotest_internal()
  914. # with calls to this function:
  915. #
  916. dotest_internal_debug ()
  917. {
  918. if test -z "$3"; then
  919. if test -s ${TESTDIR}/dotest.tmp; then
  920. echo "** expected: " >>${LOGFILE}
  921. echo "$3" >>${LOGFILE}
  922. echo "$3" > ${TESTDIR}/dotest.exp
  923. rm -f ${TESTDIR}/dotest.ex2
  924. echo "** got: " >>${LOGFILE}
  925. cat ${TESTDIR}/dotest.tmp >>${LOGFILE}
  926. fail "$1"
  927. else
  928. pass "$1"
  929. verify_tmp_empty "$1"
  930. fi
  931. else
  932. echo "$3" > ${TESTDIR}/dotest.exp
  933. if dotest_line_by_line "$1" "$2"; then
  934. pass "$1"
  935. verify_tmp_empty "$1"
  936. else
  937. if test x"$4" != x; then
  938. mv ${TESTDIR}/dotest.exp ${TESTDIR}/dotest.ex1
  939. echo "$4" > ${TESTDIR}/dotest.exp
  940. if dotest_line_by_line "$1" "$2"; then
  941. pass "$1"
  942. verify_tmp_empty "$1"
  943. else
  944. mv ${TESTDIR}/dotest.exp ${TESTDIR}/dotest.ex2
  945. echo "** expected: " >>${LOGFILE}
  946. echo "$3" >>${LOGFILE}
  947. echo "** or: " >>${LOGFILE}
  948. echo "$4" >>${LOGFILE}
  949. echo "** got: " >>${LOGFILE}
  950. cat ${TESTDIR}/dotest.tmp >>${LOGFILE}
  951. fail "$1"
  952. fi
  953. else
  954. echo "** expected: " >>${LOGFILE}
  955. echo "$3" >>${LOGFILE}
  956. echo "** got: " >>${LOGFILE}
  957. cat ${TESTDIR}/dotest.tmp >>${LOGFILE}
  958. fail "$1"
  959. fi
  960. fi
  961. fi
  962. }
  963. # Usage:
  964. # dotest TESTNAME COMMAND OUTPUT [OUTPUT2]
  965. # TESTNAME is the name used in the log to identify the test.
  966. # COMMAND is the command to run; for the test to pass, it exits with
  967. # exitstatus zero.
  968. # OUTPUT is a regexp which is compared against the output (stdout and
  969. # stderr combined) from the test. It is anchored to the start and end
  970. # of the output, so should start or end with ".*" if that is what is desired.
  971. # Trailing newlines are stripped from the command's actual output before
  972. # matching against OUTPUT.
  973. # If OUTPUT2 is specified and the output matches it, then it is also
  974. # a pass (partial workaround for the fact that some versions of expr
  975. # lack \|).
  976. dotest ()
  977. {
  978. rm -f ${TESTDIR}/dotest.ex? 2>&1
  979. eval "$2" >${TESTDIR}/dotest.tmp 2>&1
  980. status=$?
  981. if test "$status" != 0; then
  982. cat ${TESTDIR}/dotest.tmp >>${LOGFILE}
  983. echo "exit status was $status" >>${LOGFILE}
  984. fail "$1"
  985. fi
  986. dotest_internal "$@"
  987. }
  988. # Like dotest except only 2 args and result must exactly match stdin
  989. dotest_lit ()
  990. {
  991. rm -f ${TESTDIR}/dotest.ex? 2>&1
  992. eval "$2" >${TESTDIR}/dotest.tmp 2>&1
  993. status=$?
  994. if test "$status" != 0; then
  995. cat ${TESTDIR}/dotest.tmp >>${LOGFILE}
  996. echo "exit status was $status" >>${LOGFILE}
  997. fail "$1"
  998. fi
  999. cat >${TESTDIR}/dotest.exp
  1000. if cmp ${TESTDIR}/dotest.exp ${TESTDIR}/dotest.tmp >/dev/null 2>&1; then
  1001. pass "$1"
  1002. verify_tmp_empty "$1"
  1003. else
  1004. echo "** expected: " >>${LOGFILE}
  1005. cat ${TESTDIR}/dotest.exp >>${LOGFILE}
  1006. echo "** got: " >>${LOGFILE}
  1007. cat ${TESTDIR}/dotest.tmp >>${LOGFILE}
  1008. fail "$1"
  1009. fi
  1010. }
  1011. # Like dotest except exitstatus should be nonzero.
  1012. dotest_fail ()
  1013. {
  1014. rm -f ${TESTDIR}/dotest.ex? 2>&1
  1015. eval "$2" >${TESTDIR}/dotest.tmp 2>&1
  1016. status=$?
  1017. if test "$status" = 0; then
  1018. cat ${TESTDIR}/dotest.tmp >>${LOGFILE}
  1019. echo "exit status was $status" >>${LOGFILE}
  1020. fail "$1"
  1021. fi
  1022. dotest_internal "$@"
  1023. }
  1024. # Like dotest except output is sorted.
  1025. dotest_sort ()
  1026. {
  1027. rm -f ${TESTDIR}/dotest.ex? 2>&1
  1028. eval "$2" >${TESTDIR}/dotest.tmp1 2>&1
  1029. status=$?
  1030. if test "$status" != 0; then
  1031. cat ${TESTDIR}/dotest.tmp1 >>${LOGFILE}
  1032. echo "exit status was $status" >>${LOGFILE}
  1033. fail "$1"
  1034. fi
  1035. ${TR} ' ' ' ' < ${TESTDIR}/dotest.tmp1 | sort > ${TESTDIR}/dotest.tmp
  1036. dotest_internal "$@"
  1037. }
  1038. # A function for fetching the timestamp of a revison of a file
  1039. getrlogdate () {
  1040. ${testcvs} -n rlog -N ${1+"$@"} |
  1041. while read token value; do
  1042. case "$token" in
  1043. date:)
  1044. echo $value | sed "s,;.*,,"
  1045. break;
  1046. ;;
  1047. esac
  1048. done
  1049. }
  1050. # Avoid picking up any stray .cvsrc, etc., from the user running the tests
  1051. mkdir home
  1052. HOME=${TESTDIR}/home; export HOME
  1053. # Make sure this variable is not defined to anything that would
  1054. # change the format of rcs dates. Otherwise people using e.g.,
  1055. # RCSINIT=-zLT get lots of spurious failures.
  1056. RCSINIT=; export RCSINIT
  1057. # Remaining arguments are the names of tests to run.
  1058. #
  1059. # The testsuite is broken up into (hopefully manageably-sized)
  1060. # independently runnable tests, so that one can quickly get a result
  1061. # from a cvs or testsuite change, and to facilitate understanding the
  1062. # tests.
  1063. if test x"$*" = x; then
  1064. # Basic/miscellaneous functionality
  1065. tests="version basica basicb basicc basic1 deep basic2"
  1066. tests="${tests} parseroot parseroot2 files spacefiles commit-readonly"
  1067. tests="${tests} commit-add-missing"
  1068. tests="$tests add-restricted"
  1069. tests="${tests} status"
  1070. # Branching, tagging, removing, adding, multiple directories
  1071. tests="${tests} rdiff rdiff-short"
  1072. tests="${tests} rdiff2 diff diffnl death death2 death-rtag"
  1073. tests="${tests} rm-update-message rmadd rmadd2 rmadd3 resurrection"
  1074. tests="${tests} dirs dirs2 branches branches2 tagc tagf "
  1075. tests="${tests} tag-log tag-space"
  1076. tests="${tests} rcslib multibranch import importb importc import-CVS"
  1077. tests="$tests import-quirks"
  1078. tests="${tests} update-p import-after-initial branch-after-import"
  1079. tests="${tests} join join2 join3 join4 join5 join6 join7 join8 join9"
  1080. tests="${tests} join-readonly-conflict join-admin join-admin-2"
  1081. tests="${tests} join-rm"
  1082. tests="${tests} new newb conflicts conflicts2 conflicts3 conflicts4"
  1083. tests="${tests} clean"
  1084. # Checking out various places (modules, checkout -d, &c)
  1085. tests="${tests} modules modules2 modules3 modules4 modules5 modules6"
  1086. tests="${tests} modules7 mkmodules co-d"
  1087. tests="${tests} cvsadm emptydir abspath abspath2 toplevel toplevel2"
  1088. tests="${tests} rstar-toplevel trailingslashes checkout_repository"
  1089. # Log messages, error messages.
  1090. tests="${tests} mflag editor errmsg1 errmsg2 adderrmsg opterrmsg"
  1091. # Watches, binary files, history browsing, &c.
  1092. tests="${tests} devcom devcom2 devcom3 watch4 watch5 watch6"
  1093. tests="${tests} unedit-without-baserev"
  1094. tests="${tests} ignore ignore-on-branch binfiles binfiles2 binfiles3"
  1095. tests="${tests} mcopy binwrap binwrap2"
  1096. tests="${tests} binwrap3 mwrap info taginfo config"
  1097. tests="${tests} serverpatch log log2 logopt ann ann-id"
  1098. # Repository Storage (RCS file format, CVS lock files, creating
  1099. # a repository without "cvs init", &c).
  1100. tests="${tests} crerepos crerepos-extssh rcs rcs2 rcs3 rcs4 rcs5 rcs6"
  1101. tests="$tests lockfiles backuprecover"
  1102. tests="${tests} sshstdio"
  1103. # More history browsing, &c.
  1104. tests="${tests} history"
  1105. tests="${tests} big modes modes2 modes3 stamps"
  1106. # PreservePermissions stuff: permissions, symlinks et al.
  1107. # tests="${tests} perms symlinks symlinks2 hardlinks"
  1108. # More tag and branch tests, keywords.
  1109. tests="${tests} sticky keyword keywordlog keywordname keyword2"
  1110. tests="${tests} head tagdate multibranch2 tag8k"
  1111. # "cvs admin", reserved checkouts.
  1112. tests="${tests} admin reserved"
  1113. # Nuts and bolts of diffing/merging (diff library, &c)
  1114. tests="${tests} diffmerge1 diffmerge2"
  1115. # Release of multiple directories
  1116. tests="${tests} release"
  1117. tests="${tests} recase"
  1118. # Multiple root directories and low-level protocol tests.
  1119. tests="${tests} multiroot multiroot2 multiroot3 multiroot4"
  1120. tests="$tests rmroot reposmv pserver server server2 server3"
  1121. tests="$tests client client2"
  1122. tests="${tests} dottedroot fork commit-d"
  1123. else
  1124. tests="$*"
  1125. fi
  1126. # Now check the -f argument for validity.
  1127. if test -n "$fromtest"; then
  1128. # Don't allow spaces - they are our delimiters in tests
  1129. count=0
  1130. for sub in $fromtest; do
  1131. count=`expr $count + 1`
  1132. done
  1133. if test $count != 1; then
  1134. echo "No such test \`$fromtest'." >&2
  1135. exit 2
  1136. fi
  1137. # make sure it is in $tests
  1138. case " $tests " in
  1139. *" $fromtest "*)
  1140. ;;
  1141. *)
  1142. echo "No such test \`$fromtest'." >&2
  1143. exit 2
  1144. ;;
  1145. esac
  1146. fi
  1147. # a simple function to compare directory contents
  1148. #
  1149. # Returns: 0 for same, 1 for different
  1150. #
  1151. directory_cmp ()
  1152. {
  1153. OLDPWD=`pwd`
  1154. DIR_1=$1
  1155. DIR_2=$2
  1156. cd $DIR_1
  1157. find . -print | fgrep -v /CVS | sort > $TESTDIR/dc$$d1
  1158. # go back where we were to avoid symlink hell...
  1159. cd $OLDPWD
  1160. cd $DIR_2
  1161. find . -print | fgrep -v /CVS | sort > $TESTDIR/dc$$d2
  1162. if diff $TESTDIR/dc$$d1 $TESTDIR/dc$$d2 >/dev/null 2>&1
  1163. then
  1164. :
  1165. else
  1166. return 1
  1167. fi
  1168. cd $OLDPWD
  1169. while read a
  1170. do
  1171. if test -f $DIR_1/"$a" ; then
  1172. cmp -s $DIR_1/"$a" $DIR_2/"$a"
  1173. if test $? -ne 0 ; then
  1174. return 1
  1175. fi
  1176. fi
  1177. done < $TESTDIR/dc$$d1
  1178. rm -f $TESTDIR/dc$$*
  1179. return 0
  1180. }
  1181. #
  1182. # The following 4 functions are used by the diffmerge1 test case. They set up,
  1183. # respectively, the four versions of the files necessary:
  1184. #
  1185. # 1. Ancestor revisions.
  1186. # 2. "Your" changes.
  1187. # 3. "My" changes.
  1188. # 4. Expected merge result.
  1189. #
  1190. # Create ancestor revisions for diffmerge1
  1191. diffmerge_create_older_files() {
  1192. # This test case was supplied by Noah Friedman:
  1193. cat >testcase01 <<EOF
  1194. // Button.java
  1195. package random.application;
  1196. import random.util.*;
  1197. public class Button
  1198. {
  1199. /* Instantiates a Button with origin (0, 0) and zero width and height.
  1200. * You must call an initializer method to properly initialize the Button.
  1201. */
  1202. public Button ()
  1203. {
  1204. super ();
  1205. _titleColor = Color.black;
  1206. _disabledTitleColor = Color.gray;
  1207. _titleFont = Font.defaultFont ();
  1208. }
  1209. /* Convenience constructor for instantiating a Button with
  1210. * bounds x, y, width, and height. Equivalent to
  1211. * foo = new Button ();
  1212. * foo.init (x, y, width, height);
  1213. */
  1214. public Button (int x, int y, int width, int height)
  1215. {
  1216. this ();
  1217. init (x, y, width, height);
  1218. }
  1219. }
  1220. EOF
  1221. # This test case was supplied by Jacob Burckhardt:
  1222. cat >testcase02 <<EOF
  1223. a
  1224. a
  1225. a
  1226. a
  1227. a
  1228. EOF
  1229. # This test case was supplied by Karl Tomlinson who also wrote the
  1230. # patch which lets CVS correctly handle this and several other cases:
  1231. cat >testcase03 <<EOF
  1232. x
  1233. s
  1234. a
  1235. b
  1236. s
  1237. y
  1238. EOF
  1239. # This test case was supplied by Karl Tomlinson:
  1240. cat >testcase04 <<EOF
  1241. s
  1242. x
  1243. m
  1244. m
  1245. x
  1246. s
  1247. v
  1248. s
  1249. x
  1250. m
  1251. m
  1252. x
  1253. s
  1254. EOF
  1255. # This test case was supplied by Karl Tomlinson:
  1256. cat >testcase05 <<EOF
  1257. s
  1258. x
  1259. m
  1260. m
  1261. x
  1262. x
  1263. x
  1264. x
  1265. x
  1266. x
  1267. x
  1268. x
  1269. x
  1270. x
  1271. s
  1272. s
  1273. s
  1274. s
  1275. s
  1276. s
  1277. s
  1278. s
  1279. s
  1280. s
  1281. v
  1282. EOF
  1283. # This test case was supplied by Jacob Burckhardt:
  1284. cat >testcase06 <<EOF
  1285. g
  1286. i
  1287. EOF
  1288. # This test is supposed to verify that the horizon lines are the same
  1289. # for both 2-way diffs, but unfortunately, it does not fail with the
  1290. # old version of cvs. However, Karl Tomlinson still thought it would
  1291. # be good to test it anyway:
  1292. cat >testcase07 <<EOF
  1293. h
  1294. f
  1295. g
  1296. r
  1297. i
  1298. i
  1299. EOF
  1300. # This test case was supplied by Jacob Burckhardt:
  1301. cat >testcase08 <<EOF
  1302. Both changes move this line to the end of the file.
  1303. no
  1304. changes
  1305. here
  1306. First change will delete this line.
  1307. First change will also delete this line.
  1308. no
  1309. changes
  1310. here
  1311. Second change will change it here.
  1312. no
  1313. changes
  1314. here
  1315. EOF
  1316. # This test case was supplied by Jacob Burckhardt. Note that I do not
  1317. # think cvs has ever failed with this case, but I include it anyway,
  1318. # since I think it is a hard case. It is hard because Peter Miller's
  1319. # fmerge utility fails on it:
  1320. cat >testcase09 <<EOF
  1321. m
  1322. a
  1323. {
  1324. }
  1325. b
  1326. {
  1327. }
  1328. EOF
  1329. # This test case was supplied by Martin Dorey and simplified by Jacob
  1330. # Burckhardt:
  1331. cat >testcase10 <<EOF
  1332. petRpY ( MtatRk );
  1333. fV ( MtatRk != Zy ) UDTXUK_DUUZU ( BGKT_ZFDK_qjT_HGTG );
  1334. MtatRk = MQfr_GttpfIRte_MtpeaL ( &acI, jfle_Uecopd_KRLIep * jfle_Uecopd_MfJe_fY_nEtek );
  1335. OjZy MtatRk = Uead_GttpfIRte_MtpeaL ( &acI, jfle_Uecopd_MfJe_fY_nEtek, nRVVep );
  1336. Bloke_GttpfIRte_MtpeaL ( &acI );
  1337. MTGTXM Uead_Ktz_qjT_jfle_Uecopd ( fYt Y, uofd *nRVVep )
  1338. {
  1339. fV ( Y < 16 )
  1340. {
  1341. petRpY ( Uead_Mectopk ( noot_Uecopd.qVtHatabcY0 * noot_Uecopd.MectopkFepBlRktep +
  1342. Y * jfle_Uecopd_MfJe_fY_Mectopk,
  1343. jfle_Uecopd_MfJe_fY_Mectopk,
  1344. nRVVep ) );
  1345. }
  1346. elke
  1347. {
  1348. petRpY ( Uead_Mectopk ( noot_Uecopd.qVtqfppHatabcY0 * noot_Uecopd.MectopkFepBlRktep +
  1349. ( Y - 16 ) * jfle_Uecopd_MfJe_fY_Mectopk,
  1350. jfle_Uecopd_MfJe_fY_Mectopk,
  1351. nRVVep ) );
  1352. }
  1353. }
  1354. /****************************************************************************
  1355. * *
  1356. * Uead Mectopk ( Uelatfue to tze cRppeYt raptftfoY ) *
  1357. * *
  1358. ****************************************************************************/
  1359. MTGTXM Uead_Mectopk ( RfYt64 Mtapt_Mectop, RfYt64 KRL_Mectopk, uofd *nRVVep )
  1360. {
  1361. MTGTXM MtatRk = Zy;
  1362. MtatRk = Uead_HfkQ ( FaptftfoY_TaIle.Uelatfue_Mectop + Mtapt_Mectop, KRL_Mectopk, nRVVep );
  1363. petRpY ( MtatRk );
  1364. }
  1365. HfkQipfte ( waYdle, /* waYdle */
  1366. waYdleFok, /* ZVVket VpoL ktapt oV dfkQ */
  1367. (coYkt RfYt8*) nRVVep, /* nRVVep */
  1368. 0, /* MRrepVlRoRk KfxoYfkL */
  1369. beYgtz /* nEtek to Apfte */
  1370. );
  1371. petRpY ( Zy );
  1372. }
  1373. EOF
  1374. }
  1375. # Create "your" revisions for diffmerge1
  1376. diffmerge_create_your_files() {
  1377. # remove the Button() method
  1378. cat >testcase01 <<\EOF
  1379. // Button.java
  1380. package random.application;
  1381. import random.util.*;
  1382. public class Button
  1383. {
  1384. /* Instantiates a Button with origin (0, 0) and zero width and height.
  1385. * You must call an initializer method to properly initialize the Button.
  1386. */
  1387. public Button ()
  1388. {
  1389. super ();
  1390. _titleColor = Color.black;
  1391. _disabledTitleColor = Color.gray;
  1392. _titleFont = Font.defaultFont ();
  1393. }
  1394. }
  1395. EOF
  1396. cat >testcase02 <<\EOF
  1397. y
  1398. a
  1399. a
  1400. a
  1401. a
  1402. EOF
  1403. cat >testcase03 <<\EOF
  1404. x
  1405. s
  1406. a
  1407. b
  1408. s
  1409. b
  1410. s
  1411. y
  1412. EOF
  1413. cat >testcase04 <<\EOF
  1414. s
  1415. m
  1416. s
  1417. v
  1418. s
  1419. m
  1420. s
  1421. EOF
  1422. cat >testcase05 <<\EOF
  1423. v
  1424. s
  1425. m
  1426. s
  1427. s
  1428. s
  1429. s
  1430. s
  1431. s
  1432. s
  1433. s
  1434. s
  1435. s
  1436. v
  1437. EOF
  1438. # Test case 6 and test case 7 both use the same input files, but they
  1439. # order the input files differently. In one case, a certain file is
  1440. # used as the older file, but in the other test case, that same file
  1441. # is used as the file which has changes. I could have put echo
  1442. # commands here, but since the echo lines would be the same as those
  1443. # in the previous function, I decided to save space and avoid repeating
  1444. # several lines of code. Instead, I merely swap the files:
  1445. mv testcase07 tmp
  1446. mv testcase06 testcase07
  1447. mv tmp testcase06
  1448. # Make the date newer so that cvs thinks that the files are changed:
  1449. touch testcase06 testcase07
  1450. cat >testcase08 <<\EOF
  1451. no
  1452. changes
  1453. here
  1454. First change has now added this in.
  1455. no
  1456. changes
  1457. here
  1458. Second change will change it here.
  1459. no
  1460. changes
  1461. here
  1462. Both changes move this line to the end of the file.
  1463. EOF
  1464. cat >testcase09 <<\EOF
  1465. m
  1466. a
  1467. {
  1468. }
  1469. b
  1470. {
  1471. }
  1472. c
  1473. {
  1474. }
  1475. EOF
  1476. cat >testcase10 <<\EOF
  1477. fV ( BzQkV_URYYfYg ) (*jfle_Uecopdk)[0].jfle_Uecopd_KRLIep = ZpfgfYal_jUK;
  1478. petRpY ( MtatRk );
  1479. fV ( MtatRk != Zy ) UDTXUK_DUUZU ( BGKT_ZFDK_qjT_HGTG );
  1480. fV ( jfle_Uecopd_KRLIep < 16 )
  1481. {
  1482. MtatRk = Uead_Ktz_qjT_jfle_Uecopd ( jfle_Uecopd_KRLIep, (uofd*)nRVVep );
  1483. }
  1484. elke
  1485. {
  1486. MtatRk = ZreY_GttpfIRte_MtpeaL ( qjT_jfle_Uecopdk, qjT_jfle_Uecopd_BoRYt, HGTG_TvFD, KXbb, KXbb, &acI );
  1487. fV ( MtatRk != Zy ) UDTXUK_DUUZU ( BGKT_ZFDK_qjT_HGTG );
  1488. MtatRk = MQfr_GttpfIRte_MtpeaL ( &acI, jfle_Uecopd_KRLIep * jfle_Uecopd_MfJe_fY_nEtek );
  1489. OjZy MtatRk = Uead_GttpfIRte_MtpeaL ( &acI, jfle_Uecopd_MfJe_fY_nEtek, nRVVep );
  1490. Bloke_GttpfIRte_MtpeaL ( &acI );
  1491. MTGTXM Uead_Ktz_qjT_jfle_Uecopd ( fYt Y, uofd *nRVVep )
  1492. {
  1493. MTGTXM MtatRk = Zy;
  1494. fV ( Y < 16 )
  1495. {
  1496. petRpY ( Uead_Mectopk ( noot_Uecopd.qVtHatabcY0 * noot_Uecopd.MectopkFepBlRktep +
  1497. Y * jfle_Uecopd_MfJe_fY_Mectopk,
  1498. jfle_Uecopd_MfJe_fY_Mectopk,
  1499. nRVVep ) );
  1500. }
  1501. elke
  1502. {
  1503. petRpY ( Uead_Mectopk ( noot_Uecopd.qVtqfppHatabcY0 * noot_Uecopd.MectopkFepBlRktep +
  1504. ( Y - 16 ) * jfle_Uecopd_MfJe_fY_Mectopk,
  1505. jfle_Uecopd_MfJe_fY_Mectopk,
  1506. nRVVep ) );
  1507. }
  1508. petRpY ( MtatRk );
  1509. }
  1510. /****************************************************************************
  1511. * *
  1512. * Uead Mectopk ( Uelatfue to tze cRppeYt raptftfoY ) *
  1513. * *
  1514. ****************************************************************************/
  1515. MTGTXM Uead_Mectopk ( RfYt64 Mtapt_Mectop, RfYt64 KRL_Mectopk, uofd *nRVVep )
  1516. {
  1517. MTGTXM MtatRk = Zy;
  1518. MtatRk = Uead_HfkQ ( FaptftfoY_TaIle.Uelatfue_Mectop + Mtapt_Mectop, KRL_Mectopk, nRVVep );
  1519. petRpY ( MtatRk );
  1520. }
  1521. HfkQipfte ( waYdle, /* waYdle */
  1522. waYdleFok, /* ZVVket VpoL ktapt oV dfkQ */
  1523. (coYkt RfYt8*) nRVVep, /* nRVVep */
  1524. 0, /* MRrepVlRoRk KfxoYfkL */
  1525. beYgtz /* nEtek to Apfte */
  1526. );
  1527. petRpY ( Zy );
  1528. }
  1529. EOF
  1530. }
  1531. # Create "my" revisions for diffmerge1
  1532. diffmerge_create_my_files() {
  1533. # My working copy still has the Button() method, but I
  1534. # comment out some code at the top of the class.
  1535. cat >testcase01 <<\EOF
  1536. // Button.java
  1537. package random.application;
  1538. import random.util.*;
  1539. public class Button
  1540. {
  1541. /* Instantiates a Button with origin (0, 0) and zero width and height.
  1542. * You must call an initializer method to properly initialize the Button.
  1543. */
  1544. public Button ()
  1545. {
  1546. super ();
  1547. // _titleColor = Color.black;
  1548. // _disabledTitleColor = Color.gray;
  1549. // _titleFont = Font.defaultFont ();
  1550. }
  1551. /* Convenience constructor for instantiating a Button with
  1552. * bounds x, y, width, and height. Equivalent to
  1553. * foo = new Button ();
  1554. * foo.init (x, y, width, height);
  1555. */
  1556. public Button (int x, int y, int width, int height)
  1557. {
  1558. this ();
  1559. init (x, y, width, height);
  1560. }
  1561. }
  1562. EOF
  1563. cat >testcase02 <<\EOF
  1564. a
  1565. a
  1566. a
  1567. a
  1568. m
  1569. EOF
  1570. cat >testcase03 <<\EOF
  1571. x
  1572. s
  1573. c
  1574. s
  1575. b
  1576. s
  1577. y
  1578. EOF
  1579. cat >testcase04 <<\EOF
  1580. v
  1581. s
  1582. x
  1583. m
  1584. m
  1585. x
  1586. s
  1587. v
  1588. s
  1589. x
  1590. m
  1591. m
  1592. x
  1593. s
  1594. v
  1595. EOF
  1596. # Note that in test case 5, there are no changes in the "mine"
  1597. # section, which explains why there is no command here which writes to
  1598. # file testcase05.
  1599. # no changes for testcase06
  1600. # The two branches make the same changes:
  1601. cp ../yours/testcase07 .
  1602. cat >testcase08 <<\EOF
  1603. no
  1604. changes
  1605. here
  1606. First change will delete this line.
  1607. First change will also delete this line.
  1608. no
  1609. changes
  1610. here
  1611. Second change has now changed it here.
  1612. no
  1613. changes
  1614. here
  1615. Both changes move this line to the end of the file.
  1616. EOF
  1617. cat >testcase09 <<\EOF
  1618. m
  1619. a
  1620. {
  1621. }
  1622. b
  1623. {
  1624. }
  1625. c
  1626. {
  1627. }
  1628. EOF
  1629. cat >testcase10 <<\EOF
  1630. petRpY ( MtatRk );
  1631. fV ( MtatRk != Zy ) UDTXUK_DUUZU ( BGKT_ZFDK_qjT_HGTG );
  1632. MtatRk = MQfr_GttpfIRte_MtpeaL ( &acI, jfle_Uecopd_KRLIep * jfle_Uecopd_MfJe_fY_nEtek );
  1633. OjZy MtatRk = Uead_GttpfIRte_MtpeaL ( &acI, jfle_Uecopd_MfJe_fY_nEtek, nRVVep );
  1634. Bloke_GttpfIRte_MtpeaL ( &acI );
  1635. MTGTXM Uead_Ktz_qjT_jfle_Uecopd ( fYt Y, uofd *nRVVep )
  1636. {
  1637. fV ( Y < 16 )
  1638. {
  1639. petRpY ( Uead_Mectopk ( noot_Uecopd.qVtHatabcY0 * noot_Uecopd.MectopkFepBlRktep +
  1640. Y * jfle_Uecopd_MfJe_fY_Mectopk,
  1641. jfle_Uecopd_MfJe_fY_Mectopk,
  1642. nRVVep ) );
  1643. }
  1644. elke
  1645. {
  1646. petRpY ( Uead_Mectopk ( noot_Uecopd.qVtqfppHatabcY0 * noot_Uecopd.MectopkFepBlRktep +
  1647. ( Y - 16 ) * jfle_Uecopd_MfJe_fY_Mectopk,
  1648. jfle_Uecopd_MfJe_fY_Mectopk,
  1649. nRVVep ) );
  1650. }
  1651. }
  1652. /****************************************************************************
  1653. * *
  1654. * Uead Mectopk ( Uelatfue to tze cRppeYt raptftfoY ) *
  1655. * *
  1656. ****************************************************************************/
  1657. MTGTXM Uead_Mectopk ( RfYt64 Mtapt_Mectop, RfYt64 KRL_Mectopk, uofd *nRVVep )
  1658. {
  1659. MTGTXM MtatRk = Zy;
  1660. MtatRk = Uead_HfkQ ( FaptftfoY_TaIle.Uelatfue_Mectop + Mtapt_Mectop, KRL_Mectopk, nRVVep );
  1661. petRpY ( MtatRk );
  1662. }
  1663. HfkQipfte ( waYdle, /* waYdle