github.com/ccccaoqing/test@v0.0.0-20220510085219-3985d23445c0/lib/codereview/test.sh (about)

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