OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/env python | |
2 # Copyright 2015 the V8 project authors. All rights reserved. | |
3 # Use of this source code is governed by a BSD-style license that can be | |
4 # found in the LICENSE file. | |
5 | |
6 import mergeinfo | |
7 import shutil | |
8 import unittest | |
9 | |
10 from collections import namedtuple | |
11 from os import path | |
12 from subprocess import Popen, PIPE, check_call | |
13 | |
14 TEST_CONFIG = { | |
15 "GIT_REPO": "/tmp/test-v8-search-related-commits", | |
16 } | |
17 | |
18 class TestMergeInfo(unittest.TestCase): | |
19 | |
20 base_dir = TEST_CONFIG["GIT_REPO"] | |
21 | |
22 def _execute_git(self, git_args): | |
23 | |
24 fullCommand = ["git", "-C", self.base_dir] + git_args | |
25 p = Popen(args=fullCommand, stdin=PIPE, | |
26 stdout=PIPE, stderr=PIPE) | |
27 output, err = p.communicate() | |
28 rc = p.returncode | |
29 if rc != 0: | |
30 raise Exception(err) | |
31 return output | |
32 | |
33 def setUp(self): | |
34 if path.exists(self.base_dir): | |
35 shutil.rmtree(self.base_dir) | |
36 | |
37 check_call(["git", "init", self.base_dir]) | |
38 | |
39 # Initial commit | |
40 message = '''Initial commit''' | |
41 | |
42 self._make_empty_commit(message) | |
43 | |
44 def tearDown(self): | |
45 if path.exists(self.base_dir): | |
46 shutil.rmtree(self.base_dir) | |
47 | |
48 def _assert_correct_standard_result( | |
49 self, result, all_commits, hash_of_first_commit): | |
50 self.assertEqual(len(result), 1, "Master commit not found") | |
51 self.assertTrue( | |
52 result.get(hash_of_first_commit), | |
53 "Master commit is wrong") | |
54 | |
55 self.assertEqual( | |
56 len(result[hash_of_first_commit]), | |
57 1, | |
58 "Child commit not found") | |
59 self.assertEqual( | |
60 all_commits[2], | |
61 result[hash_of_first_commit][0], | |
62 "Child commit wrong") | |
63 | |
64 def _get_commits(self): | |
65 commits = self._execute_git( | |
66 ["log", "--format=%H", "--reverse"]).splitlines() | |
67 return commits | |
68 | |
69 def _make_empty_commit(self, message): | |
70 self._execute_git(["commit", "--allow-empty", "-m", message]) | |
71 | |
72 def testCanDescribeCommit(self): | |
73 commits = self._get_commits() | |
74 hash_of_first_commit = commits[0] | |
75 | |
76 result = mergeinfo.describe_commit( | |
77 self.base_dir, | |
78 hash_of_first_commit).splitlines() | |
79 | |
80 self.assertEqual( | |
81 result[0], | |
82 'commit ' + hash_of_first_commit) | |
83 | |
84 def testCanDescribeCommitSingleLine(self): | |
85 commits = self._get_commits() | |
86 hash_of_first_commit = commits[0] | |
87 | |
88 result = mergeinfo.describe_commit( | |
89 self.base_dir, | |
90 hash_of_first_commit, True).splitlines() | |
91 | |
92 self.assertEqual( | |
93 str(result[0]), | |
94 str(hash_of_first_commit[0:7]) + ' Initial commit') | |
95 | |
96 def testSearchFollowUpCommits(self): | |
97 commits = self._get_commits() | |
98 hash_of_first_commit = commits[0] | |
99 | |
100 message = 'Follow-up commit of ' + hash_of_first_commit | |
101 self._make_empty_commit(message) | |
102 self._make_empty_commit(message) | |
103 self._make_empty_commit(message) | |
104 commits = self._get_commits() | |
105 message = 'Not related commit' | |
106 self._make_empty_commit(message) | |
107 | |
108 followups = mergeinfo.get_followup_commits( | |
109 self.base_dir, | |
110 hash_of_first_commit) | |
111 self.assertEqual(set(followups), set(commits[1:])) | |
112 | |
113 def testSearchMerges(self): | |
114 self._execute_git(['branch', 'test']) | |
115 self._execute_git(['checkout', 'master']) | |
116 message = 'real initial commit' | |
117 self._make_empty_commit(message) | |
118 commits = self._get_commits() | |
119 hash_of_first_commit = commits[0] | |
120 | |
121 self._execute_git(['checkout', 'test']) | |
122 message = 'Not related commit' | |
123 self._make_empty_commit(message) | |
124 | |
125 #This should be found | |
Michael Achenbach
2015/10/01 08:24:18
nit: space after #
also everywhere below
Michael Hablich
2015/10/01 10:33:25
Done.
| |
126 message = 'Merge ' + hash_of_first_commit | |
127 self._make_empty_commit(message) | |
128 hash_of_hit = self._get_commits()[-1] | |
129 | |
130 #This should be ignored | |
131 message = 'Cr-Branched-From: ' + hash_of_first_commit | |
132 self._make_empty_commit(message) | |
Michael Achenbach
2015/10/01 08:24:18
Suggestion: You could let _make_empty_commit retur
Michael Hablich
2015/10/01 10:33:26
I like it.
| |
133 hash_of_ignored = self._get_commits()[-1] | |
134 | |
135 self._execute_git(['checkout', 'master']) | |
136 | |
137 followups = mergeinfo.get_followup_commits( | |
138 self.base_dir, | |
139 hash_of_first_commit) | |
140 | |
141 #Check if follow ups and merges are not overlapping | |
142 self.assertEqual(len(followups), 0) | |
Michael Achenbach
2015/10/01 08:24:18
I assume if you'd checked out a branch where a mer
Michael Hablich
2015/10/01 10:33:26
Do you mean what will happen if you are applying t
Michael Achenbach
2015/10/01 10:40:29
Right!
| |
143 | |
144 message = 'Follow-up commit of ' + hash_of_first_commit | |
145 self._make_empty_commit(message) | |
146 hash_of_followup = self._get_commits()[-1] | |
147 | |
148 merges = mergeinfo.get_merge_commits(self.base_dir, hash_of_first_commit) | |
149 #Check if follow up is ignored | |
150 self.assertTrue(hash_of_followup not in merges) | |
151 | |
152 #Check for proper return of merges | |
153 self.assertTrue(hash_of_hit in merges) | |
154 self.assertTrue(hash_of_ignored not in merges) | |
155 | |
156 def testIsRolled(self): | |
157 commits = self._get_commits() | |
158 hash_of_first_commit = commits[0] | |
Michael Achenbach
2015/10/01 08:24:18
The test (also for lkgr) would be more covering if
Michael Hablich
2015/10/01 10:33:26
Ack.
Also added another assert.
| |
159 self._execute_git(['branch', 'remotes/origin/roll']) | |
Michael Achenbach
2015/10/01 08:24:18
Remember that the roll ref is just storing what sh
Michael Hablich
2015/10/01 10:33:26
You are right. I changed the wording.
| |
160 | |
161 self.assertTrue(mergeinfo.is_rolled( | |
162 self.base_dir, hash_of_first_commit)) | |
163 | |
164 def testIsLkgr(self): | |
165 commits = self._get_commits() | |
166 hash_of_first_commit = commits[0] | |
167 self._execute_git(['branch', 'remotes/origin/lkgr']) | |
168 | |
169 self.assertTrue(mergeinfo.is_lkgr( | |
170 self.base_dir, hash_of_first_commit)) | |
171 | |
172 def testShowFirstCanary(self): | |
173 commits = self._get_commits() | |
174 hash_of_first_commit = commits[0] | |
175 | |
176 self.assertEqual(mergeinfo.get_first_canary( | |
177 self.base_dir, hash_of_first_commit), 'No Canary coverage') | |
178 | |
179 self._execute_git(['branch', 'remotes/origin/chromium/2345']) | |
180 self._execute_git(['branch', 'remotes/origin/chromium/2346']) | |
181 | |
182 self.assertEqual(mergeinfo.get_first_canary( | |
183 self.base_dir, hash_of_first_commit), '2345') | |
184 | |
185 if __name__ == "__main__": | |
186 #import sys;sys.argv = ['', 'Test.testName'] | |
Michael Achenbach
2015/10/01 08:24:18
nit: remove?
Michael Hablich
2015/10/01 10:33:25
Done.
| |
187 unittest.main() | |
OLD | NEW |