|
1 # Copyright (C) 2010 Google Inc. All rights reserved. |
|
2 # |
|
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 disclaimer |
|
11 # in the documentation and/or other materials provided with the |
|
12 # distribution. |
|
13 # * Neither the name of Google Inc. nor the names of its |
|
14 # contributors may be used to endorse or promote products derived from |
|
15 # 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 from __future__ import with_statement |
|
30 |
|
31 import codecs |
|
32 import os |
|
33 import shutil |
|
34 import tempfile |
|
35 import unittest |
|
36 |
|
37 from webkitpy.common.checkout.api import Checkout |
|
38 from webkitpy.common.checkout.changelog import ChangeLogEntry |
|
39 from webkitpy.common.checkout.scm import detect_scm_system, CommitMessage |
|
40 from webkitpy.common.system.outputcapture import OutputCapture |
|
41 from webkitpy.thirdparty.mock import Mock |
|
42 |
|
43 |
|
44 # FIXME: Copied from scm_unittest.py |
|
45 def write_into_file_at_path(file_path, contents, encoding="utf-8"): |
|
46 with codecs.open(file_path, "w", encoding) as file: |
|
47 file.write(contents) |
|
48 |
|
49 |
|
50 _changelog1entry1 = u"""2010-03-25 Tor Arne Vestb\u00f8 <vestbo@webkit.org> |
|
51 |
|
52 Unreviewed build fix to un-break webkit-patch land. |
|
53 |
|
54 Move commit_message_for_this_commit from scm to checkout |
|
55 https://bugs.webkit.org/show_bug.cgi?id=36629 |
|
56 |
|
57 * Scripts/webkitpy/common/checkout/api.py: import scm.CommitMessage |
|
58 """ |
|
59 _changelog1entry2 = u"""2010-03-25 Adam Barth <abarth@webkit.org> |
|
60 |
|
61 Reviewed by Eric Seidel. |
|
62 |
|
63 Move commit_message_for_this_commit from scm to checkout |
|
64 https://bugs.webkit.org/show_bug.cgi?id=36629 |
|
65 |
|
66 * Scripts/webkitpy/common/checkout/api.py: |
|
67 """ |
|
68 _changelog1 = u"\n".join([_changelog1entry1, _changelog1entry2]) |
|
69 _changelog2 = u"""2010-03-25 Tor Arne Vestb\u00f8 <vestbo@webkit.org> |
|
70 |
|
71 Unreviewed build fix to un-break webkit-patch land. |
|
72 |
|
73 Second part of this complicated change. |
|
74 |
|
75 * Path/To/Complicated/File: Added. |
|
76 |
|
77 2010-03-25 Adam Barth <abarth@webkit.org> |
|
78 |
|
79 Reviewed by Eric Seidel. |
|
80 |
|
81 Filler change. |
|
82 """ |
|
83 |
|
84 class CommitMessageForThisCommitTest(unittest.TestCase): |
|
85 expected_commit_message = u"""2010-03-25 Tor Arne Vestb\u00f8 <vestbo@webkit.org> |
|
86 |
|
87 Unreviewed build fix to un-break webkit-patch land. |
|
88 |
|
89 Move commit_message_for_this_commit from scm to checkout |
|
90 https://bugs.webkit.org/show_bug.cgi?id=36629 |
|
91 |
|
92 * Scripts/webkitpy/common/checkout/api.py: import scm.CommitMessage |
|
93 2010-03-25 Tor Arne Vestb\u00f8 <vestbo@webkit.org> |
|
94 |
|
95 Unreviewed build fix to un-break webkit-patch land. |
|
96 |
|
97 Second part of this complicated change. |
|
98 |
|
99 * Path/To/Complicated/File: Added. |
|
100 """ |
|
101 |
|
102 def setUp(self): |
|
103 self.temp_dir = tempfile.mkdtemp(suffix="changelogs") |
|
104 self.old_cwd = os.getcwd() |
|
105 os.chdir(self.temp_dir) |
|
106 write_into_file_at_path("ChangeLog1", _changelog1) |
|
107 write_into_file_at_path("ChangeLog2", _changelog2) |
|
108 |
|
109 def tearDown(self): |
|
110 shutil.rmtree(self.temp_dir, ignore_errors=True) |
|
111 os.chdir(self.old_cwd) |
|
112 |
|
113 # FIXME: This should not need to touch the file system, however |
|
114 # ChangeLog is difficult to mock at current. |
|
115 def test_commit_message_for_this_commit(self): |
|
116 checkout = Checkout(None) |
|
117 checkout.modified_changelogs = lambda git_commit: ["ChangeLog1", "ChangeLog2"] |
|
118 output = OutputCapture() |
|
119 expected_stderr = "Parsing ChangeLog: ChangeLog1\nParsing ChangeLog: ChangeLog2\n" |
|
120 commit_message = output.assert_outputs(self, checkout.commit_message_for_this_commit, |
|
121 kwargs={"git_commit": None}, expected_stderr=expected_stderr) |
|
122 self.assertEqual(commit_message.message(), self.expected_commit_message) |
|
123 |
|
124 |
|
125 class CheckoutTest(unittest.TestCase): |
|
126 def test_latest_entry_for_changelog_at_revision(self): |
|
127 scm = Mock() |
|
128 def mock_contents_at_revision(changelog_path, revision): |
|
129 self.assertEqual(changelog_path, "foo") |
|
130 self.assertEqual(revision, "bar") |
|
131 # contents_at_revision is expected to return a byte array (str) |
|
132 # so we encode our unicode ChangeLog down to a utf-8 stream. |
|
133 return _changelog1.encode("utf-8") |
|
134 scm.contents_at_revision = mock_contents_at_revision |
|
135 checkout = Checkout(scm) |
|
136 entry = checkout._latest_entry_for_changelog_at_revision("foo", "bar") |
|
137 self.assertEqual(entry.contents(), _changelog1entry1) |
|
138 |
|
139 def test_commit_info_for_revision(self): |
|
140 scm = Mock() |
|
141 scm.committer_email_for_revision = lambda revision: "committer@example.com" |
|
142 checkout = Checkout(scm) |
|
143 checkout.changelog_entries_for_revision = lambda revision: [ChangeLogEntry(_changelog1entry1)] |
|
144 commitinfo = checkout.commit_info_for_revision(4) |
|
145 self.assertEqual(commitinfo.bug_id(), 36629) |
|
146 self.assertEqual(commitinfo.author_name(), u"Tor Arne Vestb\u00f8") |
|
147 self.assertEqual(commitinfo.author_email(), "vestbo@webkit.org") |
|
148 self.assertEqual(commitinfo.reviewer_text(), None) |
|
149 self.assertEqual(commitinfo.reviewer(), None) |
|
150 self.assertEqual(commitinfo.committer_email(), "committer@example.com") |
|
151 self.assertEqual(commitinfo.committer(), None) |
|
152 |
|
153 checkout.changelog_entries_for_revision = lambda revision: [] |
|
154 self.assertEqual(checkout.commit_info_for_revision(1), None) |
|
155 |
|
156 def test_bug_id_for_revision(self): |
|
157 scm = Mock() |
|
158 scm.committer_email_for_revision = lambda revision: "committer@example.com" |
|
159 checkout = Checkout(scm) |
|
160 checkout.changelog_entries_for_revision = lambda revision: [ChangeLogEntry(_changelog1entry1)] |
|
161 self.assertEqual(checkout.bug_id_for_revision(4), 36629) |
|
162 |
|
163 def test_bug_id_for_this_commit(self): |
|
164 scm = Mock() |
|
165 checkout = Checkout(scm) |
|
166 checkout.commit_message_for_this_commit = lambda git_commit: CommitMessage(ChangeLogEntry(_changelog1entry1).contents().splitlines()) |
|
167 self.assertEqual(checkout.bug_id_for_this_commit(git_commit=None), 36629) |
|
168 |
|
169 def test_modified_changelogs(self): |
|
170 scm = Mock() |
|
171 scm.checkout_root = "/foo/bar" |
|
172 scm.changed_files = lambda git_commit: ["file1", "ChangeLog", "relative/path/ChangeLog"] |
|
173 checkout = Checkout(scm) |
|
174 expected_changlogs = ["/foo/bar/ChangeLog", "/foo/bar/relative/path/ChangeLog"] |
|
175 self.assertEqual(checkout.modified_changelogs(git_commit=None), expected_changlogs) |