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
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.
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.
29 # Tests the push-to-trunk.sh script. Needs to be run in V8 base dir:
30 # ./tools/test-push-to-trunk.sh
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
39 ########## Stdin for push-to-trunk.sh
41 # Confirm push to trunk commit ID
45 # Confirm increment version number
48 INPUT[3]="reviewer@chromium.org"
49 # Enter LGTM for V8 CL
51 # Confirm checkout sanity
53 # Manually type in trunk revision
55 # Reviewer for Chromium CL
56 INPUT[7]="reviewer@chromium.org"
58 ########## Expected commands and mock output
60 EXP[0]="git status -s -uno"
62 EXP[1]="git status -s -b -uno"
63 OUT[1]="## some_branch"
64 EXP[2]="git svn fetch"
67 OUT[3]="not the temp branch"
68 EXP[4]="git checkout -b prepare-push-temporary-branch-created-by-script"
71 OUT[5]="not the branch"
73 OUT[6]="not the trunk branch"
74 EXP[7]="git checkout -b prepare-push svn/bleeding_edge"
76 EXP[8]="git log -1 --format=%H ChangeLog"
78 EXP[9]="git log -1 hash1"
80 EXP[10]="git log hash1..HEAD --format=%H"
82 EXP[11]="git log -1 hash2 --format=\"%w(80,8,8)%s\""
84 EXP[12]="git log -1 hash2 --format=\"%B\""
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.\""
90 EXP[15]="git cl upload -r reviewer@chromium.org --send-mail"
92 EXP[16]="git cl dcommit"
94 EXP[17]="git svn fetch"
96 EXP[18]="git checkout svn/bleeding_edge"
98 EXP[19]="git log -1 --format=%H --grep=Prepare push to trunk. Now working on version 3.4.5."
100 EXP[20]="git diff svn/trunk"
102 EXP[21]="git checkout -b trunk-push svn/trunk"
104 EXP[22]="git apply --index --reject /tmp/v8-push-to-trunk-tempfile-patch"
106 EXP[23]="git add src/version.cc"
108 EXP[24]="git commit -F /tmp/v8-push-to-trunk-tempfile-commitmsg"
110 EXP[25]="git svn dcommit"
112 EXP[26]="git svn tag 3.4.5 -m \"Tagging version 3.4.5\""
114 EXP[27]="git status -s -uno"
116 EXP[28]="git checkout master"
120 EXP[30]="git checkout -b v8-roll-12345"
122 EXP[31]="git commit -am Update V8 to version 3.4.5."
124 EXP[32]="git cl upload --send-mail"
126 EXP[33]="git checkout -f some_branch"
128 EXP[34]="git branch -D prepare-push-temporary-branch-created-by-script"
130 EXP[35]="git branch -D prepare-push"
132 EXP[36]="git branch -D trunk-push"
135 ########## Global temp files for test input/output
137 export TEST_OUTPUT=$(mktemp)
138 export INDEX=$(mktemp)
139 export MOCK_OUTPUT=$(mktemp)
140 export EXPECTED_COMMANDS=$(mktemp)
142 ########## Command index
145 local I="$(command cat $INDEX)"
154 ########## Mock output accessor
159 command sed "${I}q;d" $MOCK_OUTPUT
162 export -f get_mock_output
164 for E in "${OUT[@]}"; do
168 ########## Expected commands accessor
170 get_expected_command() {
173 command sed "${I}q;d" $EXPECTED_COMMANDS
176 export -f get_expected_command
178 for E in "${EXP[@]}"; do
180 done > $EXPECTED_COMMANDS
182 ########## Mock commands
185 # All calls to git are mocked out. Expected calls and mock output are stored
186 # in the EXP/OUT arrays above.
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
199 echo "#############################" >> $TEST_OUTPUT
200 echo "mv $@" >> $TEST_OUTPUT
204 # Only calls to sed * -i * are mocked out.
205 echo "#############################" >> $TEST_OUTPUT
207 if [[ "${arr[@]}" =~ "-i" || "${arr[${#arr[@]}-1]}" == "-i" ]]; then
208 echo "sed $@" >> $TEST_OUTPUT
210 echo "sed $@" >> $TEST_OUTPUT
216 echo "#############################" >> $TEST_OUTPUT
217 echo "editor $@" >> $TEST_OUTPUT
221 echo "#############################" >> $TEST_OUTPUT
222 echo "cd $@" >> $TEST_OUTPUT
232 ########## Invoke script with test stdin
234 for i in "${INPUT[@]}"; do
236 done | tools/push-to-trunk.sh -c "path/to/chromium"
238 echo "Collected output:"
239 command cat $TEST_OUTPUT
246 rm -rf $EXPECTED_COMMANDS