Chromium Code Reviews| 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 from collections import namedtuple | |
| 7 from os import path | |
| 8 import search_related_commits | |
| 9 import shutil | |
| 10 from subprocess import Popen, PIPE, check_call | |
| 11 import unittest | |
| 12 | |
| 13 | |
| 14 TEST_CONFIG = { | |
| 15 "GIT_REPO": "/tmp/test-v8-search-related-commits", | |
| 16 } | |
| 17 | |
| 18 class TestSearchRelatedCommits(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 = """[turbofan] Sanitize language mode for javascript operators. | |
| 41 | |
| 42 R=mstarzinger@chromium.org | |
| 43 | |
| 44 Review URL: https://codereview.chromium.org/1084243005 | |
| 45 | |
| 46 Cr-Commit-Position: refs/heads/master@{#28059}""" | |
| 47 #self._add_commit_new_file("first", message, "Content") | |
|
Michael Achenbach
2015/05/04 08:57:53
nit: remove?
Michael Hablich
2015/05/04 12:17:32
Acknowledged.
| |
| 48 self._execute_git(["commit", "--allow-empty", "-m", message]) | |
| 49 | |
| 50 message = """[crankshaft] Do some stuff | |
| 51 | |
| 52 R=hablich@chromium.org | |
| 53 | |
| 54 Review URL: https://codereview.chromium.org/1084243007 | |
| 55 | |
| 56 Cr-Commit-Position: refs/heads/master@{#28030}""" | |
| 57 | |
| 58 self._execute_git(["commit", "--allow-empty", "-m", message]) | |
| 59 | |
| 60 def tearDown(self): | |
| 61 if path.exists(self.base_dir): | |
| 62 shutil.rmtree(self.base_dir) | |
| 63 | |
| 64 def _assert_correct_standard_result( | |
| 65 self, result, all_commits, hash_of_first_commit): | |
| 66 self.assertEqual(len(result), 1, "Master commit not found") | |
| 67 self.assertEqual( | |
| 68 result.keys()[0], | |
|
Michael Achenbach
2015/05/04 08:57:53
Maybe better assertTrue(result.get(hash_of_first_c
Michael Hablich
2015/05/04 12:17:32
Good point. The dict is (and should be) order-agno
| |
| 69 hash_of_first_commit, | |
| 70 "Master commit is wrong") | |
| 71 | |
| 72 self.assertEqual( | |
| 73 len(result[hash_of_first_commit]), | |
| 74 1, | |
| 75 "Child commit not found") | |
| 76 self.assertEqual( | |
| 77 all_commits[2], | |
| 78 result[hash_of_first_commit][0], | |
| 79 "Child commit wrong") | |
| 80 | |
| 81 def _get_commits(self): | |
| 82 commits = self._execute_git( | |
| 83 ["log", "--format=%H", "--reverse"]).splitlines() | |
| 84 return commits | |
| 85 | |
| 86 def testSearchByCommitPosition(self): | |
|
Michael Achenbach
2015/05/04 08:57:53
How about one negative example where nothing is fo
Michael Hablich
2015/05/04 12:17:32
Done.
| |
| 87 message = """Revert of some stuff. | |
| 88 > Cr-Commit-Position: refs/heads/master@{#28059} | |
| 89 R=mstarzinger@chromium.org | |
| 90 | |
| 91 Review URL: https://codereview.chromium.org/1084243005 | |
| 92 | |
| 93 Cr-Commit-Position: refs/heads/master@{#28088}""" | |
| 94 | |
| 95 self._execute_git(["commit", "--allow-empty", "-m", message]) | |
| 96 | |
| 97 commits = self._get_commits() | |
| 98 hash_of_first_commit = commits[0] | |
| 99 | |
| 100 result = search_related_commits.search_all_related_commits( | |
|
Michael Achenbach
2015/05/04 08:57:53
Looks like the deadline=something case is not cove
Michael Hablich
2015/05/04 12:17:32
Done.
| |
| 101 self.base_dir, hash_of_first_commit, "HEAD",None) | |
| 102 | |
| 103 self._assert_correct_standard_result(result, commits, hash_of_first_commit) | |
| 104 | |
| 105 def testSearchByTitle(self): | |
| 106 message = """Revert of some stuff. | |
| 107 > [turbofan] Sanitize language mode for javascript operators. | |
| 108 > Cr-Commit-Position: refs/heads/master@{#289} | |
| 109 R=mstarzinger@chromium.org | |
| 110 | |
| 111 Review URL: https://codereview.chromium.org/1084243005 | |
| 112 | |
| 113 Cr-Commit-Position: refs/heads/master@{#28088}""" | |
| 114 | |
| 115 self._execute_git(["commit", "--allow-empty", "-m", message]) | |
| 116 | |
| 117 commits = self._get_commits() | |
| 118 hash_of_first_commit = commits[0] | |
| 119 | |
| 120 result = search_related_commits.search_all_related_commits( | |
| 121 self.base_dir, hash_of_first_commit, "HEAD",None) | |
|
Michael Achenbach
2015/05/04 08:57:53
nit: space after , - also rest of this file
Michael Hablich
2015/05/04 12:17:32
Done.
| |
| 122 | |
| 123 self._assert_correct_standard_result(result, commits, hash_of_first_commit) | |
| 124 | |
| 125 def testSearchByHash(self): | |
| 126 commits = self._get_commits() | |
| 127 hash_of_first_commit = commits[0] | |
| 128 | |
| 129 message = """Revert of some stuff. | |
| 130 > [turbofan] Sanitize language mode for javascript operators. | |
| 131 > Reverting """ + hash_of_first_commit + """ | |
| 132 > R=mstarzinger@chromium.org | |
| 133 | |
| 134 Review URL: https://codereview.chromium.org/1084243005 | |
| 135 | |
| 136 Cr-Commit-Position: refs/heads/master@{#28088}""" | |
| 137 | |
| 138 self._execute_git(["commit", "--allow-empty", "-m", message]) | |
| 139 | |
| 140 #Fetch again for an update | |
| 141 commits = self._get_commits() | |
| 142 hash_of_first_commit = commits[0] | |
| 143 | |
| 144 result = search_related_commits.search_all_related_commits( | |
| 145 self.base_dir, | |
| 146 hash_of_first_commit, | |
| 147 "HEAD", | |
| 148 None) | |
| 149 | |
| 150 self._assert_correct_standard_result(result, commits, hash_of_first_commit) | |
| 151 | |
| 152 def testPrettyPrint(self): | |
| 153 message = """Revert of some stuff. | |
| 154 > [turbofan] Sanitize language mode for javascript operators. | |
| 155 > Cr-Commit-Position: refs/heads/master@{#289} | |
| 156 R=mstarzinger@chromium.org | |
| 157 | |
| 158 Review URL: https://codereview.chromium.org/1084243005 | |
| 159 | |
| 160 Cr-Commit-Position: refs/heads/master@{#28088}""" | |
| 161 | |
| 162 self._execute_git(["commit", "--allow-empty", "-m", message]) | |
| 163 | |
| 164 commits = self._get_commits() | |
| 165 hash_of_first_commit = commits[0] | |
| 166 OptionsStruct = namedtuple( | |
| 167 "OptionsStruct", | |
| 168 "git_dir of until all prettyprint deadline verbose") | |
| 169 options = OptionsStruct( | |
| 170 git_dir= self.base_dir, | |
| 171 of= [hash_of_first_commit], | |
| 172 until= [commits[2]], | |
| 173 all= True, | |
| 174 prettyprint= True, | |
| 175 deadline = None, | |
| 176 verbose=False) | |
| 177 output = [] | |
| 178 for current_line in search_related_commits.main(options): | |
| 179 output.append(current_line) | |
| 180 | |
| 181 self.assertIs(len(output), 2, "Not exactly two entries written") | |
| 182 self.assertTrue(output[0].startswith("+"), "Master entry not marked with +") | |
| 183 self.assertTrue(output[1].startswith("| "), "Child entry not marked with |") | |
| 184 | |
| 185 if __name__ == "__main__": | |
| 186 #import sys;sys.argv = ['', 'Test.testName'] | |
| 187 unittest.main() | |
| OLD | NEW |