OLD | NEW |
1 # -*- coding: utf-8; -*- | 1 # -*- coding: utf-8; -*- |
2 # | 2 # |
3 # Copyright (C) 2009 Google Inc. All rights reserved. | 3 # Copyright (C) 2009 Google Inc. All rights reserved. |
4 # Copyright (C) 2009 Torch Mobile Inc. | 4 # Copyright (C) 2009 Torch Mobile Inc. |
5 # Copyright (C) 2009 Apple Inc. All rights reserved. | 5 # Copyright (C) 2009 Apple Inc. All rights reserved. |
6 # Copyright (C) 2010 Chris Jerdonek (chris.jerdonek@gmail.com) | 6 # Copyright (C) 2010 Chris Jerdonek (chris.jerdonek@gmail.com) |
7 # | 7 # |
8 # Redistribution and use in source and binary forms, with or without | 8 # Redistribution and use in source and binary forms, with or without |
9 # modification, are permitted provided that the following conditions are | 9 # modification, are permitted provided that the following conditions are |
10 # met: | 10 # met: |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 """Tests validity of the global variables.""" | 155 """Tests validity of the global variables.""" |
156 | 156 |
157 def _all_categories(self): | 157 def _all_categories(self): |
158 return _all_categories() | 158 return _all_categories() |
159 | 159 |
160 def defaults(self): | 160 def defaults(self): |
161 return style._check_webkit_style_defaults() | 161 return style._check_webkit_style_defaults() |
162 | 162 |
163 def test_webkit_base_filter_rules(self): | 163 def test_webkit_base_filter_rules(self): |
164 base_filter_rules = _BASE_FILTER_RULES | 164 base_filter_rules = _BASE_FILTER_RULES |
165 defaults = self.defaults() | |
166 already_seen = [] | 165 already_seen = [] |
167 validate_filter_rules(base_filter_rules, self._all_categories()) | 166 validate_filter_rules(base_filter_rules, self._all_categories()) |
168 # Also do some additional checks. | 167 # Also do some additional checks. |
169 for rule in base_filter_rules: | 168 for rule in base_filter_rules: |
170 # Check no leading or trailing white space. | 169 # Check no leading or trailing white space. |
171 self.assertEqual(rule, rule.strip()) | 170 self.assertEqual(rule, rule.strip()) |
172 # All categories are on by default, so defaults should | 171 # All categories are on by default, so defaults should |
173 # begin with -. | 172 # begin with -. |
174 self.assertTrue(rule.startswith('-')) | 173 self.assertTrue(rule.startswith('-')) |
175 # Check no rule occurs twice. | 174 # Check no rule occurs twice. |
176 self.assertNotIn(rule, already_seen) | 175 self.assertNotIn(rule, already_seen) |
177 already_seen.append(rule) | 176 already_seen.append(rule) |
178 | 177 |
179 def test_defaults(self): | 178 def test_defaults(self): |
180 """Check that default arguments are valid.""" | 179 """Check that default arguments are valid.""" |
181 default_options = self.defaults() | 180 default_options = self.defaults() |
182 | 181 |
183 # FIXME: We should not need to call parse() to determine | 182 # FIXME: We should not need to call parse() to determine |
184 # whether the default arguments are valid. | 183 # whether the default arguments are valid. |
185 parser = ArgumentParser(all_categories=self._all_categories(), | 184 parser = ArgumentParser(all_categories=self._all_categories(), |
186 base_filter_rules=[], | 185 base_filter_rules=[], |
187 default_options=default_options) | 186 default_options=default_options) |
188 # No need to test the return value here since we test parse() | 187 # No need to test the return value here since we test parse() |
189 # on valid arguments elsewhere. | 188 # on valid arguments elsewhere. |
190 # | 189 # |
191 # The default options are valid: no error or SystemExit. | 190 # The default options are valid: no error or SystemExit. |
192 parser.parse(args=[]) | 191 parser.parse(args=[]) |
193 | 192 |
194 def test_path_rules_specifier(self): | 193 def test_path_rules_specifier(self): |
195 all_categories = self._all_categories() | 194 for _, path_rules in PATH_RULES_SPECIFIER: |
196 for (sub_paths, path_rules) in PATH_RULES_SPECIFIER: | |
197 validate_filter_rules(path_rules, self._all_categories()) | 195 validate_filter_rules(path_rules, self._all_categories()) |
198 | 196 |
199 config = FilterConfiguration(path_specific=PATH_RULES_SPECIFIER) | 197 config = FilterConfiguration(path_specific=PATH_RULES_SPECIFIER) |
200 | 198 |
201 def assertCheck(path, category): | 199 def assertCheck(path, category): |
202 """Assert that the given category should be checked.""" | 200 """Assert that the given category should be checked.""" |
203 message = ('Should check category "%s" for path "%s".' | |
204 % (category, path)) | |
205 self.assertTrue(config.should_check(category, path)) | 201 self.assertTrue(config.should_check(category, path)) |
206 | 202 |
207 def assertNoCheck(path, category): | 203 def assertNoCheck(path, category): |
208 """Assert that the given category should not be checked.""" | 204 """Assert that the given category should not be checked.""" |
209 message = ('Should not check category "%s" for path "%s".' | 205 message = ('Should not check category "%s" for path "%s".' |
210 % (category, path)) | 206 % (category, path)) |
211 self.assertFalse(config.should_check(category, path), message) | 207 self.assertFalse(config.should_check(category, path), message) |
212 | 208 |
213 assertCheck("random_path.cpp", | 209 assertCheck("random_path.cpp", |
214 "build/include") | 210 "build/include") |
(...skipping 18 matching lines...) Expand all Loading... |
233 'Key "%s" is not a category' % category) | 229 'Key "%s" is not a category' % category) |
234 | 230 |
235 | 231 |
236 class CheckWebKitStyleFunctionTest(unittest.TestCase): | 232 class CheckWebKitStyleFunctionTest(unittest.TestCase): |
237 | 233 |
238 """Tests the functions with names of the form check_webkit_style_*.""" | 234 """Tests the functions with names of the form check_webkit_style_*.""" |
239 | 235 |
240 def test_check_webkit_style_configuration(self): | 236 def test_check_webkit_style_configuration(self): |
241 # Exercise the code path to make sure the function does not error out. | 237 # Exercise the code path to make sure the function does not error out. |
242 option_values = CommandOptionValues() | 238 option_values = CommandOptionValues() |
243 configuration = check_webkit_style_configuration(option_values) | 239 check_webkit_style_configuration(option_values) |
244 | 240 |
245 def test_check_webkit_style_parser(self): | 241 def test_check_webkit_style_parser(self): |
246 # Exercise the code path to make sure the function does not error out. | 242 # Exercise the code path to make sure the function does not error out. |
247 parser = check_webkit_style_parser() | 243 check_webkit_style_parser() |
248 | 244 |
249 | 245 |
250 class CheckerDispatcherSkipTest(unittest.TestCase): | 246 class CheckerDispatcherSkipTest(unittest.TestCase): |
251 | 247 |
252 """Tests the "should skip" methods of the CheckerDispatcher class.""" | 248 """Tests the "should skip" methods of the CheckerDispatcher class.""" |
253 | 249 |
254 def setUp(self): | 250 def setUp(self): |
255 self._dispatcher = CheckerDispatcher() | 251 self._dispatcher = CheckerDispatcher() |
256 | 252 |
257 def test_should_skip_with_warning(self): | 253 def test_should_skip_with_warning(self): |
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
812 """Test that carriage returns aren't stripped from files that are allowe
d to contain them.""" | 808 """Test that carriage returns aren't stripped from files that are allowe
d to contain them.""" |
813 file_path = 'carriage_returns_allowed.txt' | 809 file_path = 'carriage_returns_allowed.txt' |
814 lines = ['line1\r', 'line2\r'] | 810 lines = ['line1\r', 'line2\r'] |
815 line_numbers = [100] | 811 line_numbers = [100] |
816 self._processor.process(lines=lines, | 812 self._processor.process(lines=lines, |
817 file_path=file_path, | 813 file_path=file_path, |
818 line_numbers=line_numbers) | 814 line_numbers=line_numbers) |
819 # The carriage return checker should never have been invoked, and so | 815 # The carriage return checker should never have been invoked, and so |
820 # should not have saved off any lines. | 816 # should not have saved off any lines. |
821 self.assertFalse(hasattr(self.carriage_checker, 'lines')) | 817 self.assertFalse(hasattr(self.carriage_checker, 'lines')) |
OLD | NEW |