| OLD | NEW | 
|---|
| (Empty) |  | 
|  | 1 #!/bin/bash | 
|  | 2 # Copyright 2013 the V8 project authors. All rights reserved. | 
|  | 3 # Redistribution and use in source and binary forms, with or without | 
|  | 4 # modification, are permitted provided that the following conditions are | 
|  | 5 # met: | 
|  | 6 # | 
|  | 7 #     * Redistributions of source code must retain the above copyright | 
|  | 8 #       notice, this list of conditions and the following disclaimer. | 
|  | 9 #     * Redistributions in binary form must reproduce the above | 
|  | 10 #       copyright notice, this list of conditions and the following | 
|  | 11 #       disclaimer in the documentation and/or other materials provided | 
|  | 12 #       with the distribution. | 
|  | 13 #     * Neither the name of Google Inc. nor the names of its | 
|  | 14 #       contributors may be used to endorse or promote products derived | 
|  | 15 #       from this software without specific prior written permission. | 
|  | 16 # | 
|  | 17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 
|  | 18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 
|  | 19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 
|  | 20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 
|  | 21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 
|  | 22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 
|  | 23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 
|  | 24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 
|  | 25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 
|  | 26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 
|  | 27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 
|  | 28 | 
|  | 29 # Tests the push-to-trunk.sh script. Needs to be run in V8 base dir: | 
|  | 30 # ./tools/test-push-to-trunk.sh | 
|  | 31 | 
|  | 32 # TODO(machenbach): Check automatically if expectations match. | 
|  | 33 # TODO(machenbach): Mock out version number retrieval. | 
|  | 34 # TODO(machenbach): Allow multiple different test cases. | 
|  | 35 # TODO(machenbach): Allow multi line mock output. | 
|  | 36 # TODO(machenbach): Represent test expectations/mock output without an array | 
|  | 37 # index increment. | 
|  | 38 | 
|  | 39 ########## Stdin for push-to-trunk.sh | 
|  | 40 | 
|  | 41 # Confirm push to trunk commit ID | 
|  | 42 INPUT[0]="Y" | 
|  | 43 # Open editor | 
|  | 44 INPUT[1]="" | 
|  | 45 # Confirm increment version number | 
|  | 46 INPUT[2]="Y" | 
|  | 47 # Reviewer for V8 CL | 
|  | 48 INPUT[3]="reviewer@chromium.org" | 
|  | 49 # Enter LGTM for V8 CL | 
|  | 50 INPUT[4]="LGTM" | 
|  | 51 # Confirm checkout sanity | 
|  | 52 INPUT[5]="Y" | 
|  | 53 # Manually type in trunk revision | 
|  | 54 INPUT[6]="12345" | 
|  | 55 # Reviewer for Chromium CL | 
|  | 56 INPUT[7]="reviewer@chromium.org" | 
|  | 57 | 
|  | 58 ########## Expected commands and mock output | 
|  | 59 | 
|  | 60 EXP[0]="git status -s -uno" | 
|  | 61 OUT[0]="" | 
|  | 62 EXP[1]="git status -s -b -uno" | 
|  | 63 OUT[1]="## some_branch" | 
|  | 64 EXP[2]="git svn fetch" | 
|  | 65 OUT[2]="" | 
|  | 66 EXP[3]="git branch" | 
|  | 67 OUT[3]="not the temp branch" | 
|  | 68 EXP[4]="git checkout -b prepare-push-temporary-branch-created-by-script" | 
|  | 69 OUT[4]="" | 
|  | 70 EXP[5]="git branch" | 
|  | 71 OUT[5]="not the branch" | 
|  | 72 EXP[6]="git branch" | 
|  | 73 OUT[6]="not the trunk branch" | 
|  | 74 EXP[7]="git checkout -b prepare-push svn/bleeding_edge" | 
|  | 75 OUT[7]="" | 
|  | 76 EXP[8]="git log -1 --format=%H ChangeLog" | 
|  | 77 OUT[8]="hash1" | 
|  | 78 EXP[9]="git log -1 hash1" | 
|  | 79 OUT[9]="" | 
|  | 80 EXP[10]="git log hash1..HEAD --format=%H" | 
|  | 81 OUT[10]="hash2" | 
|  | 82 EXP[11]="git log -1 hash2 --format=\"%w(80,8,8)%s\"" | 
|  | 83 OUT[11]="Log line..." | 
|  | 84 EXP[12]="git log -1 hash2 --format=\"%B\"" | 
|  | 85 OUT[12]="BUG=6789" | 
|  | 86 EXP[13]="git log -1 hash2 --format=\"%w(80,8,8)(%an)\"" | 
|  | 87 OUT[13]="   (author@chromium.org)" | 
|  | 88 EXP[14]="git commit -a -m \"Prepare push to trunk.  Now working on version 3.4.5
     .\"" | 
|  | 89 OUT[14]="" | 
|  | 90 EXP[15]="git cl upload -r reviewer@chromium.org --send-mail" | 
|  | 91 OUT[15]="" | 
|  | 92 EXP[16]="git cl dcommit" | 
|  | 93 OUT[16]="" | 
|  | 94 EXP[17]="git svn fetch" | 
|  | 95 OUT[17]="" | 
|  | 96 EXP[18]="git checkout svn/bleeding_edge" | 
|  | 97 OUT[18]="" | 
|  | 98 EXP[19]="git log -1 --format=%H --grep=Prepare push to trunk.  Now working on ve
     rsion 3.4.5." | 
|  | 99 OUT[19]="hash3" | 
|  | 100 EXP[20]="git diff svn/trunk" | 
|  | 101 OUT[20]="patch1" | 
|  | 102 EXP[21]="git checkout -b trunk-push svn/trunk" | 
|  | 103 OUT[21]="" | 
|  | 104 EXP[22]="git apply --index --reject /tmp/v8-push-to-trunk-tempfile-patch" | 
|  | 105 OUT[22]="" | 
|  | 106 EXP[23]="git add src/version.cc" | 
|  | 107 OUT[23]="" | 
|  | 108 EXP[24]="git commit -F /tmp/v8-push-to-trunk-tempfile-commitmsg" | 
|  | 109 OUT[24]="" | 
|  | 110 EXP[25]="git svn dcommit" | 
|  | 111 OUT[25]="r1234" | 
|  | 112 EXP[26]="git svn tag 3.4.5 -m \"Tagging version 3.4.5\"" | 
|  | 113 OUT[26]="" | 
|  | 114 EXP[27]="git status -s -uno" | 
|  | 115 OUT[27]="" | 
|  | 116 EXP[28]="git checkout master" | 
|  | 117 OUT[28]="" | 
|  | 118 EXP[29]="git pull" | 
|  | 119 OUT[29]="" | 
|  | 120 EXP[30]="git checkout -b v8-roll-12345" | 
|  | 121 OUT[30]="" | 
|  | 122 EXP[31]="git commit -am Update V8 to version 3.4.5." | 
|  | 123 OUT[31]="" | 
|  | 124 EXP[32]="git cl upload --send-mail" | 
|  | 125 OUT[32]="" | 
|  | 126 EXP[33]="git checkout -f some_branch" | 
|  | 127 OUT[33]="" | 
|  | 128 EXP[34]="git branch -D prepare-push-temporary-branch-created-by-script" | 
|  | 129 OUT[34]="" | 
|  | 130 EXP[35]="git branch -D prepare-push" | 
|  | 131 OUT[35]="" | 
|  | 132 EXP[36]="git branch -D trunk-push" | 
|  | 133 OUT[36]="" | 
|  | 134 | 
|  | 135 ########## Global temp files for test input/output | 
|  | 136 | 
|  | 137 export TEST_OUTPUT=$(mktemp) | 
|  | 138 export INDEX=$(mktemp) | 
|  | 139 export MOCK_OUTPUT=$(mktemp) | 
|  | 140 export EXPECTED_COMMANDS=$(mktemp) | 
|  | 141 | 
|  | 142 ########## Command index | 
|  | 143 | 
|  | 144 inc_index() { | 
|  | 145   local I="$(command cat $INDEX)" | 
|  | 146   let "I+=1" | 
|  | 147   echo "$I" > $INDEX | 
|  | 148   echo $I | 
|  | 149 } | 
|  | 150 | 
|  | 151 echo "-1" > $INDEX | 
|  | 152 export -f inc_index | 
|  | 153 | 
|  | 154 ########## Mock output accessor | 
|  | 155 | 
|  | 156 get_mock_output() { | 
|  | 157   local I=$1 | 
|  | 158   let "I+=1" | 
|  | 159   command sed "${I}q;d" $MOCK_OUTPUT | 
|  | 160 } | 
|  | 161 | 
|  | 162 export -f get_mock_output | 
|  | 163 | 
|  | 164 for E in "${OUT[@]}"; do | 
|  | 165   echo $E | 
|  | 166 done > $MOCK_OUTPUT | 
|  | 167 | 
|  | 168 ########## Expected commands accessor | 
|  | 169 | 
|  | 170 get_expected_command() { | 
|  | 171   local I=$1 | 
|  | 172   let "I+=1" | 
|  | 173   command sed "${I}q;d" $EXPECTED_COMMANDS | 
|  | 174 } | 
|  | 175 | 
|  | 176 export -f get_expected_command | 
|  | 177 | 
|  | 178 for E in "${EXP[@]}"; do | 
|  | 179   echo $E | 
|  | 180 done > $EXPECTED_COMMANDS | 
|  | 181 | 
|  | 182 ########## Mock commands | 
|  | 183 | 
|  | 184 git() { | 
|  | 185   # All calls to git are mocked out. Expected calls and mock output are stored | 
|  | 186   # in the EXP/OUT arrays above. | 
|  | 187   local I=$(inc_index) | 
|  | 188   local OUT=$(get_mock_output $I) | 
|  | 189   local EXP=$(get_expected_command $I) | 
|  | 190   echo "#############################" >> $TEST_OUTPUT | 
|  | 191   echo "Com. Index:  $I" >> $TEST_OUTPUT | 
|  | 192   echo "Expected:    ${EXP}" >> $TEST_OUTPUT | 
|  | 193   echo "Actual:      git $@" >> $TEST_OUTPUT | 
|  | 194   echo "Mock Output: ${OUT}" >> $TEST_OUTPUT | 
|  | 195   echo "${OUT}" | 
|  | 196 } | 
|  | 197 | 
|  | 198 mv() { | 
|  | 199   echo "#############################" >> $TEST_OUTPUT | 
|  | 200   echo "mv $@" >> $TEST_OUTPUT | 
|  | 201 } | 
|  | 202 | 
|  | 203 sed() { | 
|  | 204   # Only calls to sed * -i * are mocked out. | 
|  | 205   echo "#############################" >> $TEST_OUTPUT | 
|  | 206   local arr=$@ | 
|  | 207   if [[ "${arr[@]}" =~ "-i" || "${arr[${#arr[@]}-1]}" == "-i" ]]; then | 
|  | 208     echo "sed $@" >> $TEST_OUTPUT | 
|  | 209   else | 
|  | 210     echo "sed $@" >> $TEST_OUTPUT | 
|  | 211     command sed "$@" | 
|  | 212   fi | 
|  | 213 } | 
|  | 214 | 
|  | 215 editor() { | 
|  | 216   echo "#############################" >> $TEST_OUTPUT | 
|  | 217   echo "editor $@" >> $TEST_OUTPUT | 
|  | 218 } | 
|  | 219 | 
|  | 220 cd() { | 
|  | 221   echo "#############################" >> $TEST_OUTPUT | 
|  | 222   echo "cd $@" >> $TEST_OUTPUT | 
|  | 223 } | 
|  | 224 | 
|  | 225 export -f git | 
|  | 226 export -f mv | 
|  | 227 export -f sed | 
|  | 228 export -f cd | 
|  | 229 export -f editor | 
|  | 230 export EDITOR=editor | 
|  | 231 | 
|  | 232 ########## Invoke script with test stdin | 
|  | 233 | 
|  | 234 for i in "${INPUT[@]}"; do | 
|  | 235     echo $i | 
|  | 236 done | tools/push-to-trunk.sh -c "path/to/chromium" | 
|  | 237 | 
|  | 238 echo "Collected output:" | 
|  | 239 command cat $TEST_OUTPUT | 
|  | 240 | 
|  | 241 ########## Clean up | 
|  | 242 | 
|  | 243 rm -rf $TEST_OUTPUT | 
|  | 244 rm -rf $INDEX | 
|  | 245 rm -rf $MOCK_OUTPUT | 
|  | 246 rm -rf $EXPECTED_COMMANDS | 
| OLD | NEW | 
|---|