Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(71)

Side by Side Diff: tools/push-to-trunk/test_scripts.py

Issue 163183004: Add merge-to-branch python port. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Remove duplicates in patch list. Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tools/push-to-trunk/push_to_trunk.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2013 the V8 project authors. All rights reserved. 2 # Copyright 2013 the V8 project authors. All rights reserved.
3 # Redistribution and use in source and binary forms, with or without 3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions are 4 # modification, are permitted provided that the following conditions are
5 # met: 5 # met:
6 # 6 #
7 # * Redistributions of source code must retain the above copyright 7 # * Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer. 8 # notice, this list of conditions and the following disclaimer.
9 # * Redistributions in binary form must reproduce the above 9 # * Redistributions in binary form must reproduce the above
10 # copyright notice, this list of conditions and the following 10 # copyright notice, this list of conditions and the following
(...skipping 13 matching lines...) Expand all
24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 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. 27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 28
29 import os 29 import os
30 import tempfile 30 import tempfile
31 import traceback 31 import traceback
32 import unittest 32 import unittest
33 33
34 import common_includes
35 from common_includes import *
36 import push_to_trunk
37 from push_to_trunk import *
38 import auto_roll 34 import auto_roll
39 from auto_roll import AutoRollOptions 35 from auto_roll import AutoRollOptions
40 from auto_roll import CheckLastPush 36 from auto_roll import CheckLastPush
41 from auto_roll import FetchLatestRevision 37 from auto_roll import FetchLatestRevision
42 from auto_roll import SETTINGS_LOCATION 38 from auto_roll import SETTINGS_LOCATION
39 import common_includes
40 from common_includes import *
41 import merge_to_branch
42 from merge_to_branch import *
43 import push_to_trunk
44 from push_to_trunk import *
43 45
44 46
45 TEST_CONFIG = { 47 TEST_CONFIG = {
46 BRANCHNAME: "test-prepare-push", 48 BRANCHNAME: "test-prepare-push",
47 TRUNKBRANCH: "test-trunk-push", 49 TRUNKBRANCH: "test-trunk-push",
48 PERSISTFILE_BASENAME: "/tmp/test-v8-push-to-trunk-tempfile", 50 PERSISTFILE_BASENAME: "/tmp/test-v8-push-to-trunk-tempfile",
49 TEMP_BRANCH: "test-prepare-push-temporary-branch-created-by-script", 51 TEMP_BRANCH: "test-prepare-push-temporary-branch-created-by-script",
50 DOT_GIT_LOCATION: None, 52 DOT_GIT_LOCATION: None,
51 VERSION_FILE: None, 53 VERSION_FILE: None,
52 CHANGELOG_FILE: None, 54 CHANGELOG_FILE: None,
53 CHANGELOG_ENTRY_FILE: "/tmp/test-v8-push-to-trunk-tempfile-changelog-entry", 55 CHANGELOG_ENTRY_FILE: "/tmp/test-v8-push-to-trunk-tempfile-changelog-entry",
54 PATCH_FILE: "/tmp/test-v8-push-to-trunk-tempfile-patch", 56 PATCH_FILE: "/tmp/test-v8-push-to-trunk-tempfile-patch",
55 COMMITMSG_FILE: "/tmp/test-v8-push-to-trunk-tempfile-commitmsg", 57 COMMITMSG_FILE: "/tmp/test-v8-push-to-trunk-tempfile-commitmsg",
56 CHROMIUM: "/tmp/test-v8-push-to-trunk-tempfile-chromium", 58 CHROMIUM: "/tmp/test-v8-push-to-trunk-tempfile-chromium",
57 DEPS_FILE: "/tmp/test-v8-push-to-trunk-tempfile-chromium/DEPS", 59 DEPS_FILE: "/tmp/test-v8-push-to-trunk-tempfile-chromium/DEPS",
58 SETTINGS_LOCATION: None, 60 SETTINGS_LOCATION: None,
61 ALREADY_MERGING_SENTINEL_FILE:
62 "/tmp/test-merge-to-branch-tempfile-already-merging",
63 COMMIT_HASHES_FILE: "/tmp/test-merge-to-branch-tempfile-PATCH_COMMIT_HASHES",
64 TEMPORARY_PATCH_FILE: "/tmp/test-merge-to-branch-tempfile-temporary-patch",
59 } 65 }
60 66
61 67
62 def MakeOptions(s=0, l=None, f=False, m=True, r=None, c=None, a=None, 68 def MakeOptions(s=0, l=None, f=False, m=True, r=None, c=None, a=None,
63 status_password=None): 69 status_password=None, revert_bleeding_edge=None, p=None):
64 """Convenience wrapper.""" 70 """Convenience wrapper."""
65 class Options(object): 71 class Options(object):
66 pass 72 pass
67 options = Options() 73 options = Options()
68 options.s = s 74 options.s = s
69 options.l = l 75 options.l = l
70 options.f = f 76 options.f = f
71 options.m = m 77 options.m = m
72 options.r = r 78 options.reviewer = r
73 options.c = c 79 options.c = c
74 options.a = a 80 options.a = a
81 options.p = p
75 options.status_password = status_password 82 options.status_password = status_password
83 options.revert_bleeding_edge = revert_bleeding_edge
76 return options 84 return options
77 85
78 86
79 class ToplevelTest(unittest.TestCase): 87 class ToplevelTest(unittest.TestCase):
80 def testMakeComment(self): 88 def testMakeComment(self):
81 self.assertEquals("# Line 1\n# Line 2\n#", 89 self.assertEquals("# Line 1\n# Line 2\n#",
82 MakeComment(" Line 1\n Line 2\n")) 90 MakeComment(" Line 1\n Line 2\n"))
83 self.assertEquals("#Line 1\n#Line 2", 91 self.assertEquals("#Line 1\n#Line 2",
84 MakeComment("Line 1\n Line 2")) 92 MakeComment("Line 1\n Line 2"))
85 93
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 self._index = -1 229 self._index = -1
222 230
223 def Expect(self, recipe): 231 def Expect(self, recipe):
224 self._recipe = recipe 232 self._recipe = recipe
225 233
226 def Call(self, *args): 234 def Call(self, *args):
227 self._index += 1 235 self._index += 1
228 try: 236 try:
229 expected_call = self._recipe[self._index] 237 expected_call = self._recipe[self._index]
230 except IndexError: 238 except IndexError:
231 raise Exception("Calling %s %s" % (self._name, " ".join(args))) 239 raise NoRetryException("Calling %s %s" % (self._name, " ".join(args)))
232 240
233 # Pack expectations without arguments into a list. 241 # Pack expectations without arguments into a list.
234 if not isinstance(expected_call, list): 242 if not isinstance(expected_call, list):
235 expected_call = [expected_call] 243 expected_call = [expected_call]
236 244
237 # The number of arguments in the expectation must match the actual 245 # The number of arguments in the expectation must match the actual
238 # arguments. 246 # arguments.
239 if len(args) > len(expected_call): 247 if len(args) > len(expected_call):
240 raise NoRetryException("When calling %s with arguments, the " 248 raise NoRetryException("When calling %s with arguments, the "
241 "expectations must consist of at least as many arguments.") 249 "expectations must consist of at least as many arguments.")
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 304
297 def GitMock(self, cmd, args="", pipe=True): 305 def GitMock(self, cmd, args="", pipe=True):
298 print "%s %s" % (cmd, args) 306 print "%s %s" % (cmd, args)
299 return self._git_mock.Call(args) 307 return self._git_mock.Call(args)
300 308
301 def LogMock(self, cmd, args=""): 309 def LogMock(self, cmd, args=""):
302 print "Log: %s %s" % (cmd, args) 310 print "Log: %s %s" % (cmd, args)
303 311
304 MOCKS = { 312 MOCKS = {
305 "git": GitMock, 313 "git": GitMock,
314 # TODO(machenbach): Little hack to reuse the git mock for the one svn call
315 # in merge-to-branch. The command should be made explicit in the test
316 # expectations.
317 "svn": GitMock,
306 "vi": LogMock, 318 "vi": LogMock,
307 } 319 }
308 320
309 def Call(self, fun, *args, **kwargs): 321 def Call(self, fun, *args, **kwargs):
310 print "Calling %s with %s and %s" % (str(fun), str(args), str(kwargs)) 322 print "Calling %s with %s and %s" % (str(fun), str(args), str(kwargs))
311 323
312 def Command(self, cmd, args="", prefix="", pipe=True): 324 def Command(self, cmd, args="", prefix="", pipe=True):
313 return ScriptTest.MOCKS[cmd](self, cmd, args) 325 return ScriptTest.MOCKS[cmd](self, cmd, args)
314 326
315 def ReadLine(self): 327 def ReadLine(self):
(...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after
830 self.ExpectGit([ 842 self.ExpectGit([
831 ["status -s -uno", ""], 843 ["status -s -uno", ""],
832 ["status -s -b -uno", "## some_branch\n"], 844 ["status -s -b -uno", "## some_branch\n"],
833 ["svn fetch", ""], 845 ["svn fetch", ""],
834 ]) 846 ])
835 847
836 def RunAutoRoll(): 848 def RunAutoRoll():
837 auto_roll.RunAutoRoll(TEST_CONFIG, AutoRollOptions(MakeOptions()), self) 849 auto_roll.RunAutoRoll(TEST_CONFIG, AutoRollOptions(MakeOptions()), self)
838 self.assertRaises(Exception, RunAutoRoll) 850 self.assertRaises(Exception, RunAutoRoll)
839 851
852 def testMergeToBranch(self):
853 TEST_CONFIG[ALREADY_MERGING_SENTINEL_FILE] = self.MakeEmptyTempFile()
854 TEST_CONFIG[DOT_GIT_LOCATION] = self.MakeEmptyTempFile()
855 TEST_CONFIG[VERSION_FILE] = self.MakeTempVersionFile()
856 os.environ["EDITOR"] = "vi"
857 extra_patch = self.MakeEmptyTempFile()
858
859 def VerifyPatch(patch):
860 return lambda: self.assertEquals(patch,
861 FileToText(TEST_CONFIG[TEMPORARY_PATCH_FILE]))
862
863 msg = """Merged r12345, r23456, r34567, r45678, r56789 into trunk branch.
864
865 Title4
866
867 Title2
868
869 Title3
870
871 Title1
872
873 Title5
874
875 BUG=123,234,345,456,567,v8:123
876 LOG=N
877 """
878
879 def VerifySVNCommit():
880 commit = FileToText(TEST_CONFIG[COMMITMSG_FILE])
881 self.assertEquals(msg, commit)
882 version = FileToText(TEST_CONFIG[VERSION_FILE])
883 self.assertTrue(re.search(r"#define MINOR_VERSION\s+22", version))
884 self.assertTrue(re.search(r"#define BUILD_NUMBER\s+5", version))
885 self.assertTrue(re.search(r"#define PATCH_LEVEL\s+1", version))
886 self.assertTrue(re.search(r"#define IS_CANDIDATE_VERSION\s+0", version))
887
888 self.ExpectGit([
889 ["status -s -uno", ""],
890 ["status -s -b -uno", "## some_branch\n"],
891 ["svn fetch", ""],
892 ["branch", " branch1\n* branch2\n"],
893 ["checkout -b %s" % TEST_CONFIG[TEMP_BRANCH], ""],
894 ["branch", " branch1\n* branch2\n"],
895 ["checkout -b %s svn/trunk" % TEST_CONFIG[BRANCHNAME], ""],
896 ["log svn/bleeding_edge --reverse --format=%H --grep=\"Port r12345\"",
897 "hash1\nhash2"],
898 ["svn find-rev hash1 svn/bleeding_edge", "45678"],
899 ["log -1 --format=%s hash1", "Title1"],
900 ["svn find-rev hash2 svn/bleeding_edge", "23456"],
901 ["log -1 --format=%s hash2", "Title2"],
902 ["log svn/bleeding_edge --reverse --format=%H --grep=\"Port r23456\"",
903 ""],
904 ["log svn/bleeding_edge --reverse --format=%H --grep=\"Port r34567\"",
905 "hash3"],
906 ["svn find-rev hash3 svn/bleeding_edge", "56789"],
907 ["log -1 --format=%s hash3", "Title3"],
908 ["svn find-rev \"r12345\" svn/bleeding_edge", "hash4"],
909 ["svn find-rev \"r23456\" svn/bleeding_edge", "hash2"],
910 ["svn find-rev \"r34567\" svn/bleeding_edge", "hash3"],
911 ["svn find-rev \"r45678\" svn/bleeding_edge", "hash1"],
912 ["svn find-rev \"r56789\" svn/bleeding_edge", "hash5"],
913 ["log -1 --format=%s hash4", "Title4"],
914 ["log -1 --format=%s hash2", "Title2"],
915 ["log -1 --format=%s hash3", "Title3"],
916 ["log -1 --format=%s hash1", "Title1"],
917 ["log -1 --format=%s hash5", "Title5"],
918 ["log -1 hash4", "Title4\nBUG=123\nBUG=234"],
919 ["log -1 hash2", "Title2\n BUG = v8:123,345"],
920 ["log -1 hash3", "Title3\nLOG=n\nBUG=567, 456"],
921 ["log -1 hash1", "Title1"],
922 ["log -1 hash5", "Title5"],
923 ["log -1 -p hash4", "patch4"],
924 ["apply --index --reject \"%s\"" % TEST_CONFIG[TEMPORARY_PATCH_FILE],
925 "", VerifyPatch("patch4")],
926 ["log -1 -p hash2", "patch2"],
927 ["apply --index --reject \"%s\"" % TEST_CONFIG[TEMPORARY_PATCH_FILE],
928 "", VerifyPatch("patch2")],
929 ["log -1 -p hash3", "patch3"],
930 ["apply --index --reject \"%s\"" % TEST_CONFIG[TEMPORARY_PATCH_FILE],
931 "", VerifyPatch("patch3")],
932 ["log -1 -p hash1", "patch1"],
933 ["apply --index --reject \"%s\"" % TEST_CONFIG[TEMPORARY_PATCH_FILE],
934 "", VerifyPatch("patch1")],
935 ["log -1 -p hash5", "patch5"],
936 ["apply --index --reject \"%s\"" % TEST_CONFIG[TEMPORARY_PATCH_FILE],
937 "", VerifyPatch("patch5")],
938 ["apply --index --reject \"%s\"" % extra_patch, ""],
939 ["commit -a -F \"%s\"" % TEST_CONFIG[COMMITMSG_FILE], ""],
940 ["cl upload -r \"reviewer@chromium.org\" --send-mail", ""],
941 ["checkout %s" % TEST_CONFIG[BRANCHNAME], ""],
942 ["cl presubmit", "Presubmit successfull\n"],
943 ["cl dcommit -f --bypass-hooks", "Closing issue\n", VerifySVNCommit],
944 ["svn fetch", ""],
945 ["log -1 --format=%%H --grep=\"%s\" svn/trunk" % msg, "hash6"],
946 ["svn find-rev hash6", "1324"],
947 [("copy -r 1324 https://v8.googlecode.com/svn/trunk "
948 "https://v8.googlecode.com/svn/tags/3.22.5.1 -m "
949 "\"Tagging version 3.22.5.1\""), ""],
950 ["checkout -f some_branch", ""],
951 ["branch -D %s" % TEST_CONFIG[TEMP_BRANCH], ""],
952 ["branch -D %s" % TEST_CONFIG[BRANCHNAME], ""],
953 ])
954
955 self.ExpectReadline([
956 "Y", # Automatically add corresponding ports (34567, 56789)?
957 "Y", # Automatically increment patch level?
958 "reviewer@chromium.org", # V8 reviewer.
959 "LGTM", # Enter LGTM for V8 CL.
960 ])
961
962 options = MakeOptions(p=extra_patch, f=True)
963 # r12345 and r34567 are patches. r23456 (included) and r45678 are the MIPS
964 # ports of r12345. r56789 is the MIPS port of r34567.
965 args = ["trunk", "12345", "23456", "34567"]
966 self.assertTrue(merge_to_branch.ProcessOptions(options, args))
967 RunMergeToBranch(TEST_CONFIG, MergeToBranchOptions(options, args), self)
968
969
840 class SystemTest(unittest.TestCase): 970 class SystemTest(unittest.TestCase):
841 def testReload(self): 971 def testReload(self):
842 step = MakeStep(step_class=PrepareChangeLog, number=0, state={}, config={}, 972 step = MakeStep(step_class=PrepareChangeLog, number=0, state={}, config={},
843 options=CommonOptions(MakeOptions()), 973 options=CommonOptions(MakeOptions()),
844 side_effect_handler=DEFAULT_SIDE_EFFECT_HANDLER) 974 side_effect_handler=DEFAULT_SIDE_EFFECT_HANDLER)
845 body = step.Reload( 975 body = step.Reload(
846 """------------------------------------------------------------------------ 976 """------------------------------------------------------------------------
847 r17997 | machenbach@chromium.org | 2013-11-22 11:04:04 +0100 (...) | 6 lines 977 r17997 | machenbach@chromium.org | 2013-11-22 11:04:04 +0100 (...) | 6 lines
848 978
849 Prepare push to trunk. Now working on version 3.23.11. 979 Prepare push to trunk. Now working on version 3.23.11.
850 980
851 R=danno@chromium.org 981 R=danno@chromium.org
852 982
853 Review URL: https://codereview.chromium.org/83173002 983 Review URL: https://codereview.chromium.org/83173002
854 984
855 ------------------------------------------------------------------------""") 985 ------------------------------------------------------------------------""")
856 self.assertEquals( 986 self.assertEquals(
857 """Prepare push to trunk. Now working on version 3.23.11. 987 """Prepare push to trunk. Now working on version 3.23.11.
858 988
859 R=danno@chromium.org 989 R=danno@chromium.org
860 990
861 Committed: https://code.google.com/p/v8/source/detail?r=17997""", body) 991 Committed: https://code.google.com/p/v8/source/detail?r=17997""", body)
OLDNEW
« no previous file with comments | « tools/push-to-trunk/push_to_trunk.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698