OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2013 The Chromium Authors. All rights reserved. | 2 # Copyright 2013 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """Unit tests for git_common.py""" | 6 """Unit tests for git_common.py""" |
7 | 7 |
8 import binascii | 8 import binascii |
9 import collections | 9 import collections |
10 import os | 10 import os |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 self.assertIsNone(self.repo.run(cur_branch_out_of_git)) | 247 self.assertIsNone(self.repo.run(cur_branch_out_of_git)) |
248 | 248 |
249 self.repo.git('checkout', 'branch_D') | 249 self.repo.git('checkout', 'branch_D') |
250 self.assertEqual(self.repo.run(self.gc.current_branch), 'branch_D') | 250 self.assertEqual(self.repo.run(self.gc.current_branch), 'branch_D') |
251 | 251 |
252 def testBranches(self): | 252 def testBranches(self): |
253 # This check fails with git 2.4 (see crbug.com/487172) | 253 # This check fails with git 2.4 (see crbug.com/487172) |
254 self.assertEqual(self.repo.run(set, self.gc.branches()), | 254 self.assertEqual(self.repo.run(set, self.gc.branches()), |
255 {'master', 'branch_D', 'root_A'}) | 255 {'master', 'branch_D', 'root_A'}) |
256 | 256 |
| 257 def testDiff(self): |
| 258 # Get the names of the blobs being compared (to avoid hard-coding). |
| 259 c_blob_short = self.repo.git('rev-parse', '--short', |
| 260 'tag_C:some/files/file2').stdout.strip() |
| 261 d_blob_short = self.repo.git('rev-parse', '--short', |
| 262 'tag_D:some/files/file2').stdout.strip() |
| 263 expected_output = [ |
| 264 'diff --git a/some/files/file2 b/some/files/file2', |
| 265 'index %s..%s 100755' % (c_blob_short, d_blob_short), |
| 266 '--- a/some/files/file2', |
| 267 '+++ b/some/files/file2', |
| 268 '@@ -1 +1,2 @@', |
| 269 ' file2 - vanilla', |
| 270 '+file2 - merged'] |
| 271 self.assertEqual(expected_output, |
| 272 self.repo.run(self.gc.diff, 'tag_C', 'tag_D').split('\n')) |
| 273 |
257 def testDormant(self): | 274 def testDormant(self): |
258 self.assertFalse(self.repo.run(self.gc.is_dormant, 'master')) | 275 self.assertFalse(self.repo.run(self.gc.is_dormant, 'master')) |
259 self.repo.git('config', 'branch.master.dormant', 'true') | 276 self.repo.git('config', 'branch.master.dormant', 'true') |
260 self.assertTrue(self.repo.run(self.gc.is_dormant, 'master')) | 277 self.assertTrue(self.repo.run(self.gc.is_dormant, 'master')) |
261 | 278 |
262 def testBlame(self): | 279 def testBlame(self): |
263 def get_porcelain_for_commit(commit_name, lines): | 280 def get_porcelain_for_commit(commit_name, lines): |
264 format_string = ('%H {}\nauthor %an\nauthor-mail <%ae>\nauthor-time %at\n' | 281 format_string = ('%H {}\nauthor %an\nauthor-mail <%ae>\nauthor-time %at\n' |
265 'author-tz +0000\ncommitter %cn\ncommitter-mail <%ce>\n' | 282 'author-tz +0000\ncommitter %cn\ncommitter-mail <%ce>\n' |
266 'committer-time %ct\ncommitter-tz +0000\nsummary {}') | 283 'committer-time %ct\ncommitter-tz +0000\nsummary {}') |
(...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
841 self.repo.show_commit('A', format_string='%cn %ci')) | 858 self.repo.show_commit('A', format_string='%cn %ci')) |
842 self.assertEquals('Author McAuthorly 1970-01-03 00:00:00 +0000', | 859 self.assertEquals('Author McAuthorly 1970-01-03 00:00:00 +0000', |
843 self.repo.show_commit('B', format_string='%an %ai')) | 860 self.repo.show_commit('B', format_string='%an %ai')) |
844 self.assertEquals('Charles Committish 1970-01-04 00:00:00 +0000', | 861 self.assertEquals('Charles Committish 1970-01-04 00:00:00 +0000', |
845 self.repo.show_commit('B', format_string='%cn %ci')) | 862 self.repo.show_commit('B', format_string='%cn %ci')) |
846 | 863 |
847 | 864 |
848 if __name__ == '__main__': | 865 if __name__ == '__main__': |
849 sys.exit(coverage_utils.covered_main( | 866 sys.exit(coverage_utils.covered_main( |
850 os.path.join(DEPOT_TOOLS_ROOT, 'git_common.py'))) | 867 os.path.join(DEPOT_TOOLS_ROOT, 'git_common.py'))) |
OLD | NEW |