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

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: 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
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[DOT_GIT_LOCATION] = self.MakeEmptyTempFile()
854 TEST_CONFIG[VERSION_FILE] = self.MakeTempVersionFile()
855 TEST_CONFIG[CHANGELOG_ENTRY_FILE] = self.MakeEmptyTempFile()
856 TEST_CONFIG[CHANGELOG_FILE] = self.MakeEmptyTempFile()
857 TextToFile("1999-04-05: Version 3.22.4", TEST_CONFIG[CHANGELOG_FILE])
Michael Achenbach 2014/02/18 12:39:32 Removed also some c/p relics.
858 os.environ["EDITOR"] = "vi"
859 extra_patch = self.MakeEmptyTempFile()
860
861 def VerifyPatch(patch):
862 return lambda: self.assertEquals(patch,
863 FileToText(TEST_CONFIG[TEMPORARY_PATCH_FILE]))
864
865 msg = """Merged r12345, r45678, r23456, r34567, r56789 into trunk branch.
866
867 Title4
868
869 Title1
870
871 Title2
872
873 Title3
874
875 Title5
876
877 BUG=123,234,345,456,567,v8:123
878 LOG=N
879 """
880
881 def VerifySVNCommit():
882 commit = FileToText(TEST_CONFIG[COMMITMSG_FILE])
883 self.assertEquals(msg, commit)
884 version = FileToText(TEST_CONFIG[VERSION_FILE])
885 self.assertTrue(re.search(r"#define MINOR_VERSION\s+22", version))
886 self.assertTrue(re.search(r"#define BUILD_NUMBER\s+5", version))
887 self.assertTrue(re.search(r"#define PATCH_LEVEL\s+1", version))
888 self.assertTrue(re.search(r"#define IS_CANDIDATE_VERSION\s+0", version))
889
890 review_suffix = ""
891 self.ExpectGit([
892 ["status -s -uno", ""],
893 ["status -s -b -uno", "## some_branch\n"],
894 ["svn fetch", ""],
895 ["branch", " branch1\n* branch2\n"],
896 ["checkout -b %s" % TEST_CONFIG[TEMP_BRANCH], ""],
897 ["branch", " branch1\n* branch2\n"],
898 ["checkout -b %s svn/trunk" % TEST_CONFIG[BRANCHNAME], ""],
899 ["log svn/bleeding_edge --reverse --format=%H --grep=\"Port r12345\"",
900 "hash1\nhash2"],
901 ["svn find-rev hash1 svn/bleeding_edge", "45678"],
902 ["log -1 --format=%s hash1", "Title1"],
903 ["svn find-rev hash2 svn/bleeding_edge", "23456"],
904 ["log -1 --format=%s hash2", "Title2"],
905 ["log svn/bleeding_edge --reverse --format=%H --grep=\"Port r23456\"",
906 ""],
907 ["log svn/bleeding_edge --reverse --format=%H --grep=\"Port r34567\"",
908 "hash3"],
909 ["svn find-rev hash3 svn/bleeding_edge", "56789"],
910 ["log -1 --format=%s hash3", "Title3"],
911 ["svn find-rev \"r12345\" svn/bleeding_edge", "hash4"],
912 ["svn find-rev \"r45678\" svn/bleeding_edge", "hash1"],
913 ["svn find-rev \"r23456\" svn/bleeding_edge", "hash2"],
914 ["svn find-rev \"r34567\" svn/bleeding_edge", "hash3"],
915 ["svn find-rev \"r56789\" svn/bleeding_edge", "hash5"],
916 ["log -1 --format=%s hash4", "Title4"],
917 ["log -1 --format=%s hash1", "Title1"],
918 ["log -1 --format=%s hash2", "Title2"],
919 ["log -1 --format=%s hash3", "Title3"],
920 ["log -1 --format=%s hash5", "Title5"],
921 ["log -1 hash4", "Title4\nBUG=123\nBUG=234"],
922 ["log -1 hash1", "Title1"],
923 ["log -1 hash2", "Title2\n BUG = v8:123,345"],
924 ["log -1 hash3", "Title3\nLOG=n\nBUG=567, 456"],
925 ["log -1 hash5", "Title5"],
926 ["log -1 -p hash4", "patch4"],
927 ["apply --index --reject \"%s\"" % TEST_CONFIG[TEMPORARY_PATCH_FILE],
928 "", VerifyPatch("patch4")],
929 ["log -1 -p hash1", "patch1"],
930 ["apply --index --reject \"%s\"" % TEST_CONFIG[TEMPORARY_PATCH_FILE],
931 "", VerifyPatch("patch1")],
932 ["log -1 -p hash2", "patch2"],
933 ["apply --index --reject \"%s\"" % TEST_CONFIG[TEMPORARY_PATCH_FILE],
934 "", VerifyPatch("patch2")],
935 ["log -1 -p hash3", "patch3"],
936 ["apply --index --reject \"%s\"" % TEST_CONFIG[TEMPORARY_PATCH_FILE],
937 "", VerifyPatch("patch3")],
938 ["log -1 -p hash5", "patch5"],
939 ["apply --index --reject \"%s\"" % TEST_CONFIG[TEMPORARY_PATCH_FILE],
940 "", VerifyPatch("patch5")],
941 ["apply --index --reject \"%s\"" % extra_patch, ""],
942 ["commit -a -F \"%s\"" % TEST_CONFIG[COMMITMSG_FILE], ""],
943 ["cl upload -r \"reviewer@chromium.org\" --send-mail", ""],
944 ["checkout %s" % TEST_CONFIG[BRANCHNAME], ""],
945 ["cl presubmit", "Presubmit successfull\n"],
946 ["cl dcommit -f --bypass-hooks", "Closing issue\n", VerifySVNCommit],
947 ["svn fetch", ""],
948 ["log -1 --format=%%H --grep=\"%s\" svn/trunk" % msg, "hash6"],
949 ["svn find-rev hash6", "1324"],
950 [("copy -r 1324 https://v8.googlecode.com/svn/trunk "
951 "https://v8.googlecode.com/svn/tags/3.22.5.1 -m "
952 "\"Tagging version 3.22.5.1\""), ""],
953 ["checkout -f some_branch", ""],
954 ["branch -D %s" % TEST_CONFIG[TEMP_BRANCH], ""],
955 ["branch -D %s" % TEST_CONFIG[BRANCHNAME], ""],
956 ])
957
958 self.ExpectReadline([
959 "Y", # Automatically add corresponding ports (34567, 56789)?
960 "Y", # Automatically increment patch level?
961 "reviewer@chromium.org", # V8 reviewer.
962 "LGTM", # Enter LGTM for V8 CL.
963 ])
964
965 options = MakeOptions(p=extra_patch)
966 # r12345 and r34567 are patches. r23456 (included) and r45678 are the MIPS
967 # ports of r12345. r56789 is the MIPS port of r34567.
968 args = ["trunk", "12345", "23456", "34567"]
969 self.assertTrue(merge_to_branch.ProcessOptions(options, args))
970 RunMergeToBranch(TEST_CONFIG, MergeToBranchOptions(options, args), self)
971
972
840 class SystemTest(unittest.TestCase): 973 class SystemTest(unittest.TestCase):
841 def testReload(self): 974 def testReload(self):
842 step = MakeStep(step_class=PrepareChangeLog, number=0, state={}, config={}, 975 step = MakeStep(step_class=PrepareChangeLog, number=0, state={}, config={},
843 options=CommonOptions(MakeOptions()), 976 options=CommonOptions(MakeOptions()),
844 side_effect_handler=DEFAULT_SIDE_EFFECT_HANDLER) 977 side_effect_handler=DEFAULT_SIDE_EFFECT_HANDLER)
845 body = step.Reload( 978 body = step.Reload(
846 """------------------------------------------------------------------------ 979 """------------------------------------------------------------------------
847 r17997 | machenbach@chromium.org | 2013-11-22 11:04:04 +0100 (...) | 6 lines 980 r17997 | machenbach@chromium.org | 2013-11-22 11:04:04 +0100 (...) | 6 lines
848 981
849 Prepare push to trunk. Now working on version 3.23.11. 982 Prepare push to trunk. Now working on version 3.23.11.
850 983
851 R=danno@chromium.org 984 R=danno@chromium.org
852 985
853 Review URL: https://codereview.chromium.org/83173002 986 Review URL: https://codereview.chromium.org/83173002
854 987
855 ------------------------------------------------------------------------""") 988 ------------------------------------------------------------------------""")
856 self.assertEquals( 989 self.assertEquals(
857 """Prepare push to trunk. Now working on version 3.23.11. 990 """Prepare push to trunk. Now working on version 3.23.11.
858 991
859 R=danno@chromium.org 992 R=danno@chromium.org
860 993
861 Committed: https://code.google.com/p/v8/source/detail?r=17997""", body) 994 Committed: https://code.google.com/p/v8/source/detail?r=17997""", body)
OLDNEW
« tools/push-to-trunk/merge_to_branch.py ('K') | « 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