171f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org#!/bin/bash
271f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org# Copyright 2013 the V8 project authors. All rights reserved.
371f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org# Redistribution and use in source and binary forms, with or without
471f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org# modification, are permitted provided that the following conditions are
571f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org# met:
671f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org#
771f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org#     * Redistributions of source code must retain the above copyright
871f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org#       notice, this list of conditions and the following disclaimer.
971f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org#     * Redistributions in binary form must reproduce the above
1071f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org#       copyright notice, this list of conditions and the following
1171f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org#       disclaimer in the documentation and/or other materials provided
1271f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org#       with the distribution.
1371f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org#     * Neither the name of Google Inc. nor the names of its
1471f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org#       contributors may be used to endorse or promote products derived
1571f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org#       from this software without specific prior written permission.
1671f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org#
1771f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1871f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1971f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
2071f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2171f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2271f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2371f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2471f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2571f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2671f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2771f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2871f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org
2971f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org# Tests the push-to-trunk.sh script. Needs to be run in V8 base dir:
3071f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org# ./tools/test-push-to-trunk.sh
3171f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org
3271f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org# TODO(machenbach): Check automatically if expectations match.
3371f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org# TODO(machenbach): Mock out version number retrieval.
3471f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org# TODO(machenbach): Allow multiple different test cases.
3571f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org# TODO(machenbach): Allow multi line mock output.
3671f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org# TODO(machenbach): Represent test expectations/mock output without an array
3771f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org# index increment.
3871f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org
3971f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org########## Stdin for push-to-trunk.sh
4071f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org
4171f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org# Confirm push to trunk commit ID
4271f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgINPUT[0]="Y"
4371f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org# Open editor
4471f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgINPUT[1]=""
4571f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org# Confirm increment version number
4671f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgINPUT[2]="Y"
4771f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org# Reviewer for V8 CL
4871f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgINPUT[3]="reviewer@chromium.org"
4971f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org# Enter LGTM for V8 CL
5071f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgINPUT[4]="LGTM"
5171f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org# Confirm checkout sanity
5271f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgINPUT[5]="Y"
5371f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org# Manually type in trunk revision
5471f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgINPUT[6]="12345"
5571f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org# Reviewer for Chromium CL
5671f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgINPUT[7]="reviewer@chromium.org"
5771f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org
5871f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org########## Expected commands and mock output
5971f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org
6071f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgEXP[0]="git status -s -uno"
6171f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgOUT[0]=""
6271f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgEXP[1]="git status -s -b -uno"
6371f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgOUT[1]="## some_branch"
6471f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgEXP[2]="git svn fetch"
6571f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgOUT[2]=""
6671f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgEXP[3]="git branch"
6771f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgOUT[3]="not the temp branch"
6871f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgEXP[4]="git checkout -b prepare-push-temporary-branch-created-by-script"
6971f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgOUT[4]=""
7071f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgEXP[5]="git branch"
7171f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgOUT[5]="not the branch"
7271f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgEXP[6]="git branch"
7371f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgOUT[6]="not the trunk branch"
7471f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgEXP[7]="git checkout -b prepare-push svn/bleeding_edge"
7571f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgOUT[7]=""
7671f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgEXP[8]="git log -1 --format=%H ChangeLog"
7771f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgOUT[8]="hash1"
7871f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgEXP[9]="git log -1 hash1"
7971f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgOUT[9]=""
8071f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgEXP[10]="git log hash1..HEAD --format=%H"
8171f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgOUT[10]="hash2"
8271f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgEXP[11]="git log -1 hash2 --format=\"%w(80,8,8)%s\""
8371f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgOUT[11]="Log line..."
8471f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgEXP[12]="git log -1 hash2 --format=\"%B\""
8571f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgOUT[12]="BUG=6789"
8671f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgEXP[13]="git log -1 hash2 --format=\"%w(80,8,8)(%an)\""
8771f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgOUT[13]="   (author@chromium.org)"
8871f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgEXP[14]="git commit -a -m \"Prepare push to trunk.  Now working on version 3.4.5.\""
8971f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgOUT[14]=""
9071f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgEXP[15]="git cl upload -r reviewer@chromium.org --send-mail"
9171f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgOUT[15]=""
9271f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgEXP[16]="git cl dcommit"
9371f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgOUT[16]=""
9471f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgEXP[17]="git svn fetch"
9571f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgOUT[17]=""
9671f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgEXP[18]="git checkout svn/bleeding_edge"
9771f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgOUT[18]=""
9871f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgEXP[19]="git log -1 --format=%H --grep=Prepare push to trunk.  Now working on version 3.4.5."
9971f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgOUT[19]="hash3"
10071f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgEXP[20]="git diff svn/trunk"
10171f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgOUT[20]="patch1"
10271f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgEXP[21]="git checkout -b trunk-push svn/trunk"
10371f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgOUT[21]=""
10471f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgEXP[22]="git apply --index --reject /tmp/v8-push-to-trunk-tempfile-patch"
10571f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgOUT[22]=""
10671f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgEXP[23]="git add src/version.cc"
10771f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgOUT[23]=""
10871f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgEXP[24]="git commit -F /tmp/v8-push-to-trunk-tempfile-commitmsg"
10971f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgOUT[24]=""
11071f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgEXP[25]="git svn dcommit"
11171f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgOUT[25]="r1234"
11271f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgEXP[26]="git svn tag 3.4.5 -m \"Tagging version 3.4.5\""
11371f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgOUT[26]=""
11471f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgEXP[27]="git status -s -uno"
11571f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgOUT[27]=""
11671f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgEXP[28]="git checkout master"
11771f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgOUT[28]=""
11871f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgEXP[29]="git pull"
11971f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgOUT[29]=""
12071f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgEXP[30]="git checkout -b v8-roll-12345"
12171f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgOUT[30]=""
12271f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgEXP[31]="git commit -am Update V8 to version 3.4.5."
12371f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgOUT[31]=""
12471f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgEXP[32]="git cl upload --send-mail"
12571f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgOUT[32]=""
12671f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgEXP[33]="git checkout -f some_branch"
12771f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgOUT[33]=""
12871f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgEXP[34]="git branch -D prepare-push-temporary-branch-created-by-script"
12971f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgOUT[34]=""
13071f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgEXP[35]="git branch -D prepare-push"
13171f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgOUT[35]=""
13271f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgEXP[36]="git branch -D trunk-push"
13371f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgOUT[36]=""
13471f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org
13571f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org########## Global temp files for test input/output
13671f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org
13771f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgexport TEST_OUTPUT=$(mktemp)
13871f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgexport INDEX=$(mktemp)
13971f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgexport MOCK_OUTPUT=$(mktemp)
14071f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgexport EXPECTED_COMMANDS=$(mktemp)
14171f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org
14271f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org########## Command index
14371f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org
14471f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orginc_index() {
14571f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org  local I="$(command cat $INDEX)"
14671f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org  let "I+=1"
14771f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org  echo "$I" > $INDEX
14871f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org  echo $I
14971f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org}
15071f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org
15171f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgecho "-1" > $INDEX
15271f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgexport -f inc_index
15371f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org
15471f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org########## Mock output accessor
15571f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org
15671f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgget_mock_output() {
15771f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org  local I=$1
15871f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org  let "I+=1"
15971f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org  command sed "${I}q;d" $MOCK_OUTPUT
16071f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org}
16171f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org
16271f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgexport -f get_mock_output
16371f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org
16471f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgfor E in "${OUT[@]}"; do
16571f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org  echo $E
16671f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgdone > $MOCK_OUTPUT
16771f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org
16871f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org########## Expected commands accessor
16971f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org
17071f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgget_expected_command() {
17171f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org  local I=$1
17271f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org  let "I+=1"
17371f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org  command sed "${I}q;d" $EXPECTED_COMMANDS
17471f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org}
17571f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org
17671f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgexport -f get_expected_command
17771f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org
17871f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgfor E in "${EXP[@]}"; do
17971f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org  echo $E
18071f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgdone > $EXPECTED_COMMANDS
18171f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org
18271f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org########## Mock commands
18371f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org
18471f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orggit() {
18571f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org  # All calls to git are mocked out. Expected calls and mock output are stored
18671f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org  # in the EXP/OUT arrays above.
18771f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org  local I=$(inc_index)
18871f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org  local OUT=$(get_mock_output $I)
18971f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org  local EXP=$(get_expected_command $I)
19071f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org  echo "#############################" >> $TEST_OUTPUT
19171f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org  echo "Com. Index:  $I" >> $TEST_OUTPUT
19271f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org  echo "Expected:    ${EXP}" >> $TEST_OUTPUT
19371f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org  echo "Actual:      git $@" >> $TEST_OUTPUT
19471f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org  echo "Mock Output: ${OUT}" >> $TEST_OUTPUT
19571f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org  echo "${OUT}"
19671f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org}
19771f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org
19871f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgmv() {
19971f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org  echo "#############################" >> $TEST_OUTPUT
20071f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org  echo "mv $@" >> $TEST_OUTPUT
20171f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org}
20271f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org
20371f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgsed() {
20471f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org  # Only calls to sed * -i * are mocked out.
20571f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org  echo "#############################" >> $TEST_OUTPUT
20671f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org  local arr=$@
20771f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org  if [[ "${arr[@]}" =~ "-i" || "${arr[${#arr[@]}-1]}" == "-i" ]]; then
20871f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org    echo "sed $@" >> $TEST_OUTPUT
20971f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org  else
21071f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org    echo "sed $@" >> $TEST_OUTPUT
21171f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org    command sed "$@"
21271f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org  fi
21371f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org}
21471f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org
21571f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgeditor() {
21671f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org  echo "#############################" >> $TEST_OUTPUT
21771f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org  echo "editor $@" >> $TEST_OUTPUT
21871f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org}
21971f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org
22071f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgcd() {
22171f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org  echo "#############################" >> $TEST_OUTPUT
22271f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org  echo "cd $@" >> $TEST_OUTPUT
22371f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org}
22471f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org
22571f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgexport -f git
22671f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgexport -f mv
22771f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgexport -f sed
22871f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgexport -f cd
22971f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgexport -f editor
23071f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgexport EDITOR=editor
23171f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org
23271f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org########## Invoke script with test stdin
23371f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org
23471f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgfor i in "${INPUT[@]}"; do 
23571f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org    echo $i
23671f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgdone | tools/push-to-trunk.sh -c "path/to/chromium"
23771f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org
23871f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgecho "Collected output:"
23971f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgcommand cat $TEST_OUTPUT
24071f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org
24171f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org########## Clean up
24271f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.org
24371f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgrm -rf $TEST_OUTPUT
24471f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgrm -rf $INDEX
24571f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgrm -rf $MOCK_OUTPUT
24671f9fca5cfb606009211e0631f33b76cc2ddce3cbmeurer@chromium.orgrm -rf $EXPECTED_COMMANDS
247