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

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

Issue 49653002: Add push-to-trunk python port. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Review. Created 7 years, 1 month 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
(Empty)
1 #!/usr/bin/env python
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 import os
30 import tempfile
31 import unittest
32
33 import common_includes
34 from common_includes import *
35 import push_to_trunk
36 from push_to_trunk import *
37
38
39 TEST_CONFIG = {
40 BRANCHNAME: "test-prepare-push",
41 TRUNKBRANCH: "test-trunk-push",
42 PERSISTFILE_BASENAME: "/tmp/test-v8-push-to-trunk-tempfile",
43 TEMP_BRANCH: "test-prepare-push-temporary-branch-created-by-script",
44 DOT_GIT_LOCATION: None,
45 VERSION_FILE: None,
46 CHANGELOG_FILE: None,
47 CHANGELOG_ENTRY_FILE: "/tmp/test-v8-push-to-trunk-tempfile-changelog-entry",
48 PATCH_FILE: "/tmp/test-v8-push-to-trunk-tempfile-patch",
49 COMMITMSG_FILE: "/tmp/test-v8-push-to-trunk-tempfile-commitmsg",
50 CHROMIUM: "/tmp/test-v8-push-to-trunk-tempfile-chromium",
51 DEPS_FILE: "/tmp/test-v8-push-to-trunk-tempfile-chromium/DEPS",
52 }
53
54
55 class ScriptTest(unittest.TestCase):
56 def MakeEmptyTempFile(self):
57 handle, name = tempfile.mkstemp()
58 os.close(handle)
59 self._tmp_files.append(name)
60 return name
61
62 def MakeTempVersionFile(self):
63 name = self.MakeEmptyTempFile()
64 with open(name, "w") as f:
65 f.write(" // Some line...\n")
66 f.write("\n")
67 f.write("#define MAJOR_VERSION 3\n")
68 f.write("#define MINOR_VERSION 22\n")
69 f.write("#define BUILD_NUMBER 5\n")
70 f.write("#define PATCH_LEVEL 0\n")
71 f.write(" // Some line...\n")
72 f.write("#define IS_CANDIDATE_VERSION 0\n")
73 return name
74
75 def MakeStep(self, step_class=Step, state=None):
76 state = state or {}
77 step = step_class()
78 step.SetConfig(TEST_CONFIG)
79 step.SetState(state)
80 step.SetNumber(0)
81 step.SetSideEffectHandler(self)
82 return step
83
84 def GitMock(self, cmd, args="", pipe=True):
85 self._git_index += 1
86 try:
87 git_invocation = self._git_recipe[self._git_index]
88 except IndexError:
89 raise Exception("Calling git %s" % args)
90 if git_invocation[0] != args:
91 raise Exception("Expected: %s - Actual: %s" % (git_invocation[0], args))
92 if len(git_invocation) == 3:
93 # Run optional function checking the context during this git command.
94 git_invocation[2]()
95 return git_invocation[1]
96
97 def LogMock(self, cmd, args=""):
98 print "Log: %s %s" % (cmd, args)
99
100 MOCKS = {
101 "git": GitMock,
102 "vi": LogMock,
103 }
104
105 def Command(self, cmd, args="", prefix="", pipe=True):
106 return ScriptTest.MOCKS[cmd](self, cmd, args)
107
108 def ReadLine(self):
109 self._rl_index += 1
110 try:
111 return self._rl_recipe[self._rl_index]
112 except IndexError:
113 raise Exception("Calling readline too often")
114
115 def setUp(self):
116 self._git_recipe = []
117 self._git_index = -1
118 self._rl_recipe = []
119 self._rl_index = -1
120 self._tmp_files = []
121
122 def tearDown(self):
123 Command("rm", "-rf %s*" % TEST_CONFIG[PERSISTFILE_BASENAME])
124
125 # Clean up temps. Doesn't work automatically.
126 for name in self._tmp_files:
127 if os.path.exists(name):
128 os.remove(name)
129
130 if self._git_index < len(self._git_recipe) -1:
131 raise Exception("Called git too seldom: %d vs. %d" %
132 (self._git_index, len(self._git_recipe)))
133 if self._rl_index < len(self._rl_recipe) -1:
134 raise Exception("Too little input: %d vs. %d" %
135 (self._rl_index, len(self._rl_recipe)))
136
137 def testPersistRestore(self):
138 self.MakeStep().Persist("test1", "")
139 self.assertEquals("", self.MakeStep().Restore("test1"))
140 self.MakeStep().Persist("test2", "AB123")
141 self.assertEquals("AB123", self.MakeStep().Restore("test2"))
142
143 def testGitOrig(self):
144 self.assertTrue(Command("git", "--version").startswith("git version"))
145
146 def testGitMock(self):
147 self._git_recipe = [["--version", "git version 1.2.3"], ["dummy", ""]]
148 self.assertEquals("git version 1.2.3", self.MakeStep().Git("--version"))
149 self.assertEquals("", self.MakeStep().Git("dummy"))
150
151 def testCommonPrepareDefault(self):
152 self._git_recipe = [
153 ["status -s -uno", ""],
154 ["status -s -b -uno", "## some_branch"],
155 ["svn fetch", ""],
156 ["branch", " branch1\n* %s" % TEST_CONFIG[TEMP_BRANCH]],
157 ["branch -D %s" % TEST_CONFIG[TEMP_BRANCH], ""],
158 ["checkout -b %s" % TEST_CONFIG[TEMP_BRANCH], ""],
159 ["branch", ""],
160 ]
161 self._rl_recipe = ["Y"]
162 self.MakeStep().CommonPrepare()
163 self.assertEquals("some_branch", self.MakeStep().Restore("current_branch"))
164
165 def testCommonPrepareNoConfirm(self):
166 self._git_recipe = [
167 ["status -s -uno", ""],
168 ["status -s -b -uno", "## some_branch"],
169 ["svn fetch", ""],
170 ["branch", " branch1\n* %s" % TEST_CONFIG[TEMP_BRANCH]],
171 ]
172 self._rl_recipe = ["n"]
173 self.assertRaises(Exception, self.MakeStep().CommonPrepare)
174 self.assertEquals("some_branch", self.MakeStep().Restore("current_branch"))
175
176 def testCommonPrepareDeleteBranchFailure(self):
177 self._git_recipe = [
178 ["status -s -uno", ""],
179 ["status -s -b -uno", "## some_branch"],
180 ["svn fetch", ""],
181 ["branch", " branch1\n* %s" % TEST_CONFIG[TEMP_BRANCH]],
182 ["branch -D %s" % TEST_CONFIG[TEMP_BRANCH], None],
183 ]
184 self._rl_recipe = ["Y"]
185 self.assertRaises(Exception, self.MakeStep().CommonPrepare)
186 self.assertEquals("some_branch", self.MakeStep().Restore("current_branch"))
187
188 def testInitialEnvironmentChecks(self):
189 TEST_CONFIG[DOT_GIT_LOCATION] = self.MakeEmptyTempFile()
190 os.environ["EDITOR"] = "vi"
191 self.MakeStep().InitialEnvironmentChecks()
192
193 def testReadAndPersistVersion(self):
194 TEST_CONFIG[VERSION_FILE] = self.MakeTempVersionFile()
195 step = self.MakeStep()
196 step.ReadAndPersistVersion()
197 self.assertEquals("3", self.MakeStep().Restore("major"))
198 self.assertEquals("22", self.MakeStep().Restore("minor"))
199 self.assertEquals("5", self.MakeStep().Restore("build"))
200 self.assertEquals("0", self.MakeStep().Restore("patch"))
201 self.assertEquals("3", step._state["major"])
202 self.assertEquals("22", step._state["minor"])
203 self.assertEquals("5", step._state["build"])
204 self.assertEquals("0", step._state["patch"])
205
206 def testRegex(self):
207 self.assertEqual("(issue 321)",
208 re.sub(r"BUG=v8:(.*)$", r"(issue \1)", "BUG=v8:321"))
209 self.assertEqual("(Chromium issue 321)",
210 re.sub(r"BUG=(.*)$", r"(Chromium issue \1)", "BUG=321"))
211
212 cl = " too little\n\ttab\ttab\n too much\n trailing "
213 cl = MSub(r"\t", r" ", cl)
214 cl = MSub(r"^ {1,7}([^ ])", r" \1", cl)
215 cl = MSub(r"^ {9,80}([^ ])", r" \1", cl)
216 cl = MSub(r" +$", r"", cl)
217 self.assertEqual(" too little\n"
218 " tab tab\n"
219 " too much\n"
220 " trailing", cl)
221
222 self.assertEqual("//\n#define BUILD_NUMBER 3\n",
223 MSub(r"(?<=#define BUILD_NUMBER)(?P<space>\s+)\d*$",
224 r"\g<space>3",
225 "//\n#define BUILD_NUMBER 321\n"))
226
227 def testPrepareChangeLog(self):
228 TEST_CONFIG[VERSION_FILE] = self.MakeTempVersionFile()
229 TEST_CONFIG[CHANGELOG_ENTRY_FILE] = self.MakeEmptyTempFile()
230
231 self._git_recipe = [
232 ["log 1234..HEAD --format=%H", "rev1\nrev2"],
233 ["log -1 rev1 --format=\"%w(80,8,8)%s\"", " Title text 1"],
234 ["log -1 rev1 --format=\"%B\"", "Title\n\nBUG=\n"],
235 ["log -1 rev1 --format=\"%w(80,8,8)(%an)\"",
236 " author1@chromium.org"],
237 ["log -1 rev2 --format=\"%w(80,8,8)%s\"", " Title text 2"],
238 ["log -1 rev2 --format=\"%B\"", "Title\n\nBUG=321\n"],
239 ["log -1 rev2 --format=\"%w(80,8,8)(%an)\"",
240 " author2@chromium.org"],
241 ]
242
243 self.MakeStep().Persist("last_push", "1234")
244 self.MakeStep(PrepareChangeLog).Run()
245
246 cl = FileToText(TEST_CONFIG[CHANGELOG_ENTRY_FILE])
247 self.assertTrue(re.search(r"\d+\-\d+\-\d+: Version 3\.22\.5", cl))
248 self.assertTrue(re.search(r" Title text 1", cl))
249 self.assertTrue(re.search(r" Title text 2", cl))
250 self.assertTrue(re.search(r" author1@chromium.org", cl))
251 self.assertTrue(re.search(r" author2@chromium.org", cl))
252 self.assertTrue(re.search(r" \(Chromium issue 321\)", cl))
253 self.assertFalse(re.search(r"BUG=", cl))
254 self.assertEquals("3", self.MakeStep().Restore("major"))
255 self.assertEquals("22", self.MakeStep().Restore("minor"))
256 self.assertEquals("5", self.MakeStep().Restore("build"))
257 self.assertEquals("0", self.MakeStep().Restore("patch"))
258
259 def testEditChangeLog(self):
260 TEST_CONFIG[CHANGELOG_ENTRY_FILE] = self.MakeEmptyTempFile()
261 TEST_CONFIG[CHANGELOG_FILE] = self.MakeEmptyTempFile()
262 TextToFile(" Original CL", TEST_CONFIG[CHANGELOG_FILE])
263 TextToFile(" New \n\tLines \n", TEST_CONFIG[CHANGELOG_ENTRY_FILE])
264 os.environ["EDITOR"] = "vi"
265
266 self._rl_recipe = [
267 "", # Open editor.
268 ]
269
270 self.MakeStep(EditChangeLog).Run()
271
272 self.assertEquals(" New\n Lines\n\n\n Original CL",
273 FileToText(TEST_CONFIG[CHANGELOG_FILE]))
274
275 def testIncrementVersion(self):
276 TEST_CONFIG[VERSION_FILE] = self.MakeTempVersionFile()
277 self.MakeStep().Persist("build", "5")
278
279 self._rl_recipe = [
280 "Y", # Increment build number.
281 ]
282
283 self.MakeStep(IncrementVersion).Run()
284
285 self.assertEquals("3", self.MakeStep().Restore("new_major"))
286 self.assertEquals("22", self.MakeStep().Restore("new_minor"))
287 self.assertEquals("6", self.MakeStep().Restore("new_build"))
288 self.assertEquals("0", self.MakeStep().Restore("new_patch"))
289
290 def testSquashCommits(self):
291 TEST_CONFIG[CHANGELOG_ENTRY_FILE] = self.MakeEmptyTempFile()
292 with open(TEST_CONFIG[CHANGELOG_ENTRY_FILE], "w") as f:
293 f.write("1999-11-11: Version 3.22.5\n")
294 f.write("\n")
295 f.write(" Log text 1.\n")
296 f.write(" Chromium issue 12345\n")
297 f.write("\n")
298 f.write(" Performance and stability improvements on all "
299 "platforms.\n")
300
301 self._git_recipe = [
302 ["diff svn/trunk hash1", "patch content"],
303 ]
304
305 self.MakeStep().Persist("prepare_commit_hash", "hash1")
306 self.MakeStep().Persist("date", "1999-11-11")
307
308 self.MakeStep(SquashCommits).Run()
309
310 msg = FileToText(TEST_CONFIG[COMMITMSG_FILE])
311 self.assertTrue(re.search(r"Version 3\.22\.5", msg))
312 self.assertTrue(re.search(r"Performance and stability", msg))
313 self.assertTrue(re.search(r"Log text 1\. Chromium issue 12345", msg))
314 self.assertFalse(re.search(r"\d+\-\d+\-\d+", msg))
315
316 patch = FileToText(TEST_CONFIG[ PATCH_FILE])
317 self.assertTrue(re.search(r"patch content", patch))
318
319 def testPushToTrunk(self):
320 TEST_CONFIG[DOT_GIT_LOCATION] = self.MakeEmptyTempFile()
321 TEST_CONFIG[VERSION_FILE] = self.MakeTempVersionFile()
322 TEST_CONFIG[CHANGELOG_ENTRY_FILE] = self.MakeEmptyTempFile()
323 TEST_CONFIG[CHANGELOG_FILE] = self.MakeEmptyTempFile()
324 if not os.path.exists(TEST_CONFIG[CHROMIUM]):
325 os.makedirs(TEST_CONFIG[CHROMIUM])
326 TextToFile("1999-04-05: Version 3.22.4", TEST_CONFIG[CHANGELOG_FILE])
327 TextToFile("Some line\n \"v8_revision\": \"123444\",\n some line",
328 TEST_CONFIG[DEPS_FILE])
329 os.environ["EDITOR"] = "vi"
330
331 def CheckPreparePush():
332 cl = FileToText(TEST_CONFIG[CHANGELOG_FILE])
333 self.assertTrue(re.search(r"Version 3.22.5", cl))
334 self.assertTrue(re.search(r" Log text 1", cl))
335 self.assertTrue(re.search(r" \(issue 321\)", cl))
336 version = FileToText(TEST_CONFIG[VERSION_FILE])
337 self.assertTrue(re.search(r"#define BUILD_NUMBER\s+6", version))
338
339 def CheckSVNCommit():
340 commit = FileToText(TEST_CONFIG[COMMITMSG_FILE])
341 self.assertTrue(re.search(r"Version 3.22.5", commit))
342 self.assertTrue(re.search(r"Log text 1. \(issue 321\)", commit))
343 version = FileToText(TEST_CONFIG[VERSION_FILE])
344 self.assertTrue(re.search(r"#define MINOR_VERSION\s+22", version))
345 self.assertTrue(re.search(r"#define BUILD_NUMBER\s+5", version))
346 self.assertFalse(re.search(r"#define BUILD_NUMBER\s+6", version))
347 self.assertTrue(re.search(r"#define PATCH_LEVEL\s+0", version))
348 self.assertTrue(re.search(r"#define IS_CANDIDATE_VERSION\s+0", version))
349
350 self._git_recipe = [
351 ["status -s -uno", ""],
352 ["status -s -b -uno", "## some_branch\n"],
353 ["svn fetch", ""],
354 ["branch", " branch1\n* branch2\n"],
355 ["checkout -b %s" % TEST_CONFIG[TEMP_BRANCH], ""],
356 ["branch", " branch1\n* branch2\n"],
357 ["branch", " branch1\n* branch2\n"],
358 ["checkout -b %s svn/bleeding_edge" % TEST_CONFIG[BRANCHNAME], ""],
359 ["log -1 --format=%H ChangeLog", "1234\n"],
360 ["log -1 1234", "Last push ouput\n"],
361 ["log 1234..HEAD --format=%H", "rev1\n"],
362 ["log -1 rev1 --format=\"%w(80,8,8)%s\"", " Log text 1.\n"],
363 ["log -1 rev1 --format=\"%B\"", "Text\nBUG=v8:321\nText\n"],
364 ["log -1 rev1 --format=\"%w(80,8,8)(%an)\"",
365 " author1@chromium.org\n"],
366 [("commit -a -m \"Prepare push to trunk. "
367 "Now working on version 3.22.6.\""),
368 " 2 files changed\n",
369 CheckPreparePush],
370 ["cl upload -r \"reviewer@chromium.org\" --send-mail", "done\n"],
371 ["cl dcommit", "Closing issue\n"],
372 ["svn fetch", "fetch result\n"],
373 ["checkout svn/bleeding_edge", ""],
374 [("log -1 --format=%H --grep=\"Prepare push to trunk. "
375 "Now working on version 3.22.6.\""),
376 "hash1\n"],
377 ["diff svn/trunk hash1", "patch content\n"],
378 ["checkout -b %s svn/trunk" % TEST_CONFIG[TRUNKBRANCH], ""],
379 ["apply --index --reject \"%s\"" % TEST_CONFIG[PATCH_FILE], ""],
380 ["add \"%s\"" % TEST_CONFIG[VERSION_FILE], ""],
381 ["commit -F \"%s\"" % TEST_CONFIG[COMMITMSG_FILE], "", CheckSVNCommit],
382 ["svn dcommit 2>&1", "Some output\nCommitted r123456\nSome output\n"],
383 ["svn tag 3.22.5 -m \"Tagging version 3.22.5\"", ""],
384 ["status -s -uno", ""],
385 ["checkout master", ""],
386 ["pull", ""],
387 ["checkout -b v8-roll-123456", ""],
388 [("commit -am \"Update V8 to version 3.22.5.\n\n"
389 "TBR=reviewer@chromium.org\""),
390 ""],
391 ["cl upload --send-mail", ""],
392 ["checkout -f some_branch", ""],
393 ["branch -D %s" % TEST_CONFIG[TEMP_BRANCH], ""],
394 ["branch -D %s" % TEST_CONFIG[BRANCHNAME], ""],
395 ["branch -D %s" % TEST_CONFIG[TRUNKBRANCH], ""],
396 ]
397 self._rl_recipe = [
398 "Y", # Confirm last push.
399 "", # Open editor.
400 "Y", # Increment build number.
401 "reviewer@chromium.org", # V8 reviewer.
402 "LGTX", # Enter LGTM for V8 CL (wrong).
403 "LGTM", # Enter LGTM for V8 CL.
404 "Y", # Sanity check.
405 "reviewer@chromium.org", # Chromium reviewer.
406 ]
407
408 class Options( object ):
409 pass
410
411 options = Options()
412 options.s = 0
413 options.l = None
414 options.c = TEST_CONFIG[CHROMIUM]
415 RunScript(TEST_CONFIG, options, self)
416
417 deps = FileToText(TEST_CONFIG[DEPS_FILE])
418 self.assertTrue(re.search("\"v8_revision\": \"123456\"", deps))
419
420 cl = FileToText(TEST_CONFIG[CHANGELOG_FILE])
421 self.assertTrue(re.search(r"\d\d\d\d\-\d+\-\d+: Version 3\.22\.5", cl))
422 self.assertTrue(re.search(r" Log text 1", cl))
423 self.assertTrue(re.search(r" \(issue 321\)", cl))
424 self.assertTrue(re.search(r"1999\-04\-05: Version 3\.22\.4", cl))
425
426 # Note: The version file is on build number 5 again in the end of this test
427 # since the git command that merges to the bleeding edge branch is mocked
428 # out.
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