test.sh 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. #!/bin/bash
  2. # Copyright 2011 The Go Authors. All rights reserved.
  3. # Use of this source code is governed by a BSD-style
  4. # license that can be found in the LICENSE file.
  5. # Test the code review plugin.
  6. # Assumes a local Rietveld is running using the App Engine SDK
  7. # at http://localhost:7777/
  8. #
  9. # dev_appserver.py -p 7777 $HOME/pub/rietveld
  10. codereview_script=$(pwd)/codereview.py
  11. server=localhost:7777
  12. master=/tmp/go.test
  13. clone1=/tmp/go.test1
  14. clone2=/tmp/go.test2
  15. export HGEDITOR=true
  16. must() {
  17. if ! "$@"; then
  18. echo "$@" failed >&2
  19. exit 1
  20. fi
  21. }
  22. not() {
  23. if "$@"; then
  24. false
  25. else
  26. true
  27. fi
  28. }
  29. status() {
  30. echo '+++' "$@" >&2
  31. }
  32. firstcl() {
  33. hg pending | sed 1q | tr -d ':'
  34. }
  35. # Initial setup.
  36. status Create repositories.
  37. rm -rf $master $clone1 $clone2
  38. mkdir $master
  39. cd $master
  40. must hg init .
  41. echo Initial state >file
  42. must hg add file
  43. must hg ci -m 'first commit' file
  44. must hg clone $master $clone1
  45. must hg clone $master $clone2
  46. echo "
  47. [ui]
  48. username=Grace R Emlin <gre@golang.org>
  49. [extensions]
  50. codereview=$codereview_script
  51. [codereview]
  52. server=$server
  53. " >>$clone1/.hg/hgrc
  54. cp $clone1/.hg/hgrc $clone2/.hg/hgrc
  55. status Codereview should be disabled.
  56. cd $clone1
  57. must hg status
  58. must not hg pending
  59. status Enabling code review.
  60. must mkdir lib lib/codereview
  61. must touch lib/codereview/codereview.cfg
  62. status Code review should work even without CONTRIBUTORS.
  63. must hg pending
  64. status Add CONTRIBUTORS.
  65. echo 'Grace R Emlin <gre@golang.org>' >CONTRIBUTORS
  66. must hg add lib/codereview/codereview.cfg CONTRIBUTORS
  67. status First submit.
  68. must hg submit -r gre@golang.org -m codereview \
  69. lib/codereview/codereview.cfg CONTRIBUTORS
  70. status Should see change in other client.
  71. cd $clone2
  72. must hg pull -u
  73. must test -f lib/codereview/codereview.cfg
  74. must test -f CONTRIBUTORS
  75. test_clpatch() {
  76. # The email address must be test@example.com to match
  77. # the test code review server's default user.
  78. # Clpatch will check.
  79. cd $clone1
  80. # Tried to use UTF-8 here to test that, but dev_appserver.py crashes. Ha ha.
  81. if false; then
  82. status Using UTF-8.
  83. name="Grácè T Emlïn <test@example.com>"
  84. else
  85. status Using ASCII.
  86. name="Grace T Emlin <test@example.com>"
  87. fi
  88. echo "$name" >>CONTRIBUTORS
  89. cat .hg/hgrc | sed "s/Grace.*/$name/" >/tmp/x && mv /tmp/x .hg/hgrc
  90. echo '
  91. Reviewer: gre@golang.org
  92. Description:
  93. CONTRIBUTORS: add $name
  94. Files:
  95. CONTRIBUTORS
  96. ' | must hg change -i
  97. num=$(hg pending | sed 1q | tr -d :)
  98. status Patch CL.
  99. cd $clone2
  100. must hg clpatch $num
  101. must [ "$num" = "$(firstcl)" ]
  102. must hg submit $num
  103. status Issue should be open with no reviewers.
  104. must curl http://$server/api/$num >/tmp/x
  105. must not grep '"closed":true' /tmp/x
  106. must grep '"reviewers":\[\]' /tmp/x
  107. status Sync should close issue.
  108. cd $clone1
  109. must hg sync
  110. must curl http://$server/api/$num >/tmp/x
  111. must grep '"closed":true' /tmp/x
  112. must grep '"reviewers":\[\]' /tmp/x
  113. must [ "$(firstcl)" = "" ]
  114. }
  115. test_reviewer() {
  116. status Submit without reviewer should fail.
  117. cd $clone1
  118. echo dummy >dummy
  119. must hg add dummy
  120. echo '
  121. Description:
  122. no reviewer
  123. Files:
  124. dummy
  125. ' | must hg change -i
  126. num=$(firstcl)
  127. must not hg submit $num
  128. must hg revert dummy
  129. must rm dummy
  130. must hg change -d $num
  131. }
  132. test_linearity() {
  133. status Linearity of changes.
  134. cd $clone1
  135. echo file1 >file1
  136. must hg add file1
  137. echo '
  138. Reviewer: gre@golang.org
  139. Description: file1
  140. Files: file1
  141. ' | must hg change -i
  142. must hg submit $(firstcl)
  143. cd $clone2
  144. echo file2 >file2
  145. must hg add file2
  146. echo '
  147. Reviewer: gre@golang.org
  148. Description: file2
  149. Files: file2
  150. ' | must hg change -i
  151. must not hg submit $(firstcl)
  152. must hg sync
  153. must hg submit $(firstcl)
  154. }
  155. test_restrict() {
  156. status Cannot use hg ci.
  157. cd $clone1
  158. echo file1a >file1a
  159. hg add file1a
  160. must not hg ci -m commit file1a
  161. must rm file1a
  162. must hg revert file1a
  163. status Cannot use hg rollback.
  164. must not hg rollback
  165. status Cannot use hg backout
  166. must not hg backout -r -1
  167. }
  168. test_reviewer
  169. test_clpatch
  170. test_linearity
  171. test_restrict
  172. status ALL TESTS PASSED.