OLD | NEW |
| (Empty) |
1 # Copyright (C) 2011 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 '''Unit tests for watchlist.py.''' | |
30 | |
31 import unittest2 as unittest | |
32 | |
33 from webkitpy.common.checkout.diff_test_data import DIFF_TEST_DATA | |
34 from webkitpy.common.watchlist.watchlistparser import WatchListParser | |
35 | |
36 | |
37 class WatchListTest(unittest.TestCase): | |
38 def setUp(self): | |
39 self._watch_list_parser = WatchListParser() | |
40 | |
41 def test_filename_definition_no_matches(self): | |
42 watch_list = self._watch_list_parser.parse( | |
43 '{' | |
44 ' "DEFINITIONS": {' | |
45 ' "WatchList1": {' | |
46 ' "filename": r".*\\MyFileName\\.cpp",' | |
47 ' },' | |
48 ' },' | |
49 ' "CC_RULES": {' | |
50 ' "WatchList1": [' | |
51 ' "levin@chromium.org",' | |
52 ' ],' | |
53 ' },' | |
54 '}') | |
55 self.assertEqual(set([]), watch_list.find_matching_definitions(DIFF_TEST
_DATA)) | |
56 | |
57 def test_filename_definition(self): | |
58 watch_list = self._watch_list_parser.parse( | |
59 '{' | |
60 ' "DEFINITIONS": {' | |
61 ' "WatchList1": {' | |
62 ' "filename": r"WebCore/rendering/style/StyleFlexibleBoxD
ata\.h",' | |
63 ' },' | |
64 ' },' | |
65 ' "CC_RULES": {' | |
66 ' "WatchList1": [' | |
67 ' "levin@chromium.org",' | |
68 ' ],' | |
69 ' },' | |
70 '}') | |
71 self.assertEqual(set(['WatchList1']), watch_list.find_matching_definitio
ns(DIFF_TEST_DATA)) | |
72 | |
73 def test_cc_rules_simple(self): | |
74 watch_list = self._watch_list_parser.parse( | |
75 '{' | |
76 ' "DEFINITIONS": {' | |
77 ' "WatchList1": {' | |
78 ' "filename": r"WebCore/rendering/style/StyleFlexibleBoxD
ata\.h",' | |
79 ' },' | |
80 ' },' | |
81 ' "CC_RULES": {' | |
82 ' "WatchList1": [' | |
83 ' "levin@chromium.org",' | |
84 ' ],' | |
85 ' },' | |
86 '}') | |
87 cc_and_messages = watch_list.determine_cc_and_messages(DIFF_TEST_DATA) | |
88 self.assertEqual({ | |
89 'cc_list': ['levin@chromium.org'], | |
90 'messages': [], | |
91 }, cc_and_messages) | |
92 | |
93 def test_cc_rules_complex(self): | |
94 watch_list = self._watch_list_parser.parse( | |
95 '{' | |
96 ' "DEFINITIONS": {' | |
97 ' "WatchList1": {' | |
98 ' "filename": r"WebCore/rendering/style/StyleFlexibleBoxD
ata\.h",' | |
99 ' },' | |
100 ' "WatchList2": {' | |
101 ' "filename": r"WillNotMatch",' | |
102 ' },' | |
103 ' "WatchList3": {' | |
104 ' "filename": r"WillNotMatch",' | |
105 ' },' | |
106 ' },' | |
107 ' "CC_RULES": {' | |
108 ' "WatchList2|WatchList1|WatchList3": [ "levin@chromium.org",
],' | |
109 ' },' | |
110 '}') | |
111 cc_and_messages = watch_list.determine_cc_and_messages(DIFF_TEST_DATA) | |
112 self.assertEqual({ | |
113 'cc_list': ['levin@chromium.org'], | |
114 'messages': [], | |
115 }, cc_and_messages) | |
116 | |
117 def test_cc_and_message_rules_complex(self): | |
118 watch_list = self._watch_list_parser.parse( | |
119 '{' | |
120 ' "DEFINITIONS": {' | |
121 ' "WatchList1": {' | |
122 ' "filename": r"WebCore/rendering/style/StyleFlexibleBoxD
ata\.h",' | |
123 ' },' | |
124 ' "WatchList2": {' | |
125 ' "filename": r"WillNotMatch",' | |
126 ' },' | |
127 ' "WatchList3": {' | |
128 ' "filename": r"WillNotMatch",' | |
129 ' },' | |
130 ' },' | |
131 ' "CC_RULES": {' | |
132 ' "WatchList2|WatchList1|WatchList3": [ "levin@chromium.org",
],' | |
133 ' },' | |
134 ' "MESSAGE_RULES": {' | |
135 ' "WatchList2|WatchList1|WatchList3": [ "msg1", "msg2", ],' | |
136 ' },' | |
137 '}') | |
138 cc_and_messages = watch_list.determine_cc_and_messages(DIFF_TEST_DATA) | |
139 self.assertEqual({ | |
140 'cc_list': ['levin@chromium.org'], | |
141 'messages': ['msg1', 'msg2'], | |
142 }, cc_and_messages) | |
143 | |
144 def test_cc_and_message_rules_no_matches(self): | |
145 watch_list = self._watch_list_parser.parse( | |
146 '{' | |
147 ' "DEFINITIONS": {' | |
148 ' "WatchList1": {' | |
149 ' "filename": r"WebCore/rendering/style/ThisFileDoesNotEx
ist\.h",' | |
150 ' },' | |
151 ' "WatchList2": {' | |
152 ' "filename": r"WillNotMatch",' | |
153 ' },' | |
154 ' "WatchList3": {' | |
155 ' "filename": r"WillNotMatch",' | |
156 ' },' | |
157 ' },' | |
158 ' "CC_RULES": {' | |
159 ' "WatchList2|WatchList1|WatchList3": [ "levin@chromium.org",
],' | |
160 ' },' | |
161 ' "MESSAGE_RULES": {' | |
162 ' "WatchList2|WatchList1|WatchList3": [ "msg1", "msg2", ],' | |
163 ' },' | |
164 '}') | |
165 cc_and_messages = watch_list.determine_cc_and_messages(DIFF_TEST_DATA) | |
166 self.assertEqual({ | |
167 'cc_list': [], | |
168 'messages': [], | |
169 }, cc_and_messages) | |
170 | |
171 def test_added_match(self): | |
172 watch_list = self._watch_list_parser.parse( | |
173 '{' | |
174 ' "DEFINITIONS": {' | |
175 ' "WatchList1": {' | |
176 ' "in_added_lines": r"RenderStyle::initialBoxOrient",' | |
177 ' },' | |
178 ' "WatchList2": {' | |
179 ' "in_deleted_lines": r"RenderStyle::initialBoxOrient",' | |
180 ' },' | |
181 ' },' | |
182 ' "CC_RULES": {' | |
183 ' "WatchList1": [ "eric@webkit.org", ],' | |
184 ' "WatchList2": [ "abarth@webkit.org", ],' | |
185 ' },' | |
186 '}') | |
187 cc_and_messages = watch_list.determine_cc_and_messages(DIFF_TEST_DATA) | |
188 self.assertEqual({ | |
189 'cc_list': ['eric@webkit.org'], | |
190 'messages': [], | |
191 }, cc_and_messages) | |
192 | |
193 def test_deleted_match(self): | |
194 watch_list = self._watch_list_parser.parse( | |
195 '{' | |
196 ' "DEFINITIONS": {' | |
197 ' "WatchList1": {' | |
198 ' "in_added_lines": r"unsigned orient: 1;",' | |
199 ' },' | |
200 ' "WatchList2": {' | |
201 ' "in_deleted_lines": r"unsigned orient: 1;",' | |
202 ' },' | |
203 ' },' | |
204 ' "CC_RULES": {' | |
205 ' "WatchList1": [ "eric@webkit.org", ],' | |
206 ' "WatchList2": [ "abarth@webkit.org", ],' | |
207 ' },' | |
208 '}') | |
209 cc_and_messages = watch_list.determine_cc_and_messages(DIFF_TEST_DATA) | |
210 self.assertEqual({ | |
211 'cc_list': ['abarth@webkit.org'], | |
212 'messages': [], | |
213 }, cc_and_messages) | |
214 | |
215 def test_more_and_less_match(self): | |
216 watch_list = self._watch_list_parser.parse( | |
217 '{' | |
218 ' "DEFINITIONS": {' | |
219 ' "WatchList1": {' | |
220 # This pattern is in both added and deleted lines, so no match. | |
221 ' "more": r"userSelect == o\.userSelect",' | |
222 ' },' | |
223 ' "WatchList2": {' | |
224 ' "more": r"boxOrient\(o\.boxOrient\)",' | |
225 ' },' | |
226 ' "WatchList3": {' | |
227 ' "less": r"unsigned orient"' | |
228 ' },' | |
229 ' },' | |
230 ' "CC_RULES": {' | |
231 ' "WatchList1": [ "eric@webkit.org", ],' | |
232 ' "WatchList2": [ "levin@chromium.org", ],' | |
233 ' },' | |
234 ' "MESSAGE_RULES": {' | |
235 ' "WatchList3": ["Test message."],' | |
236 ' },' | |
237 '}') | |
238 cc_and_messages = watch_list.determine_cc_and_messages(DIFF_TEST_DATA) | |
239 self.assertEqual({ | |
240 'cc_list': ['levin@chromium.org'], | |
241 'messages': ["Test message."], | |
242 }, cc_and_messages) | |
243 | |
244 def test_complex_match(self): | |
245 watch_list = self._watch_list_parser.parse( | |
246 '{' | |
247 ' "DEFINITIONS": {' | |
248 ' "WatchList1": {' | |
249 ' "filename": r"WebCore/rendering/style/StyleRareInherite
dData\.cpp",' | |
250 ' "in_added_lines": r"\&\& boxOrient == o\.boxOrient;",' | |
251 ' "in_deleted_lines": r"\&\& userSelect == o\.userSelect;
",' | |
252 ' "more": r"boxOrient\(o\.boxOrient\)",' | |
253 ' },' | |
254 ' "WatchList2": {' | |
255 ' "filename": r"WebCore/rendering/style/StyleRareInherite
dData\.cpp",' | |
256 ' "in_added_lines": r"RenderStyle::initialBoxOrient",' | |
257 ' "less": r"userSelect;"' | |
258 ' },' | |
259 # WatchList3 won't match because these two patterns aren't in the sa
me file. | |
260 ' "WatchList3": {' | |
261 ' "in_added_lines": r"RenderStyle::initialBoxOrient",' | |
262 ' "in_deleted_lines": r"unsigned orient: 1;",' | |
263 ' },' | |
264 ' },' | |
265 ' "CC_RULES": {' | |
266 ' "WatchList1": [ "eric@webkit.org", ],' | |
267 ' "WatchList3": [ "abarth@webkit.org", ],' | |
268 ' },' | |
269 ' "MESSAGE_RULES": {' | |
270 ' "WatchList2": ["This is a test message."],' | |
271 ' },' | |
272 '}') | |
273 cc_and_messages = watch_list.determine_cc_and_messages(DIFF_TEST_DATA) | |
274 self.assertEqual({ | |
275 'cc_list': ['eric@webkit.org'], | |
276 'messages': ["This is a test message."], | |
277 }, cc_and_messages) | |
OLD | NEW |