| OLD | NEW |
| 1 # -*- coding: utf-8; -*- | 1 # -*- coding: utf-8; -*- |
| 2 # | 2 # |
| 3 # Copyright (C) 2011 Google Inc. All rights reserved. | 3 # Copyright (C) 2011 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 (cjerdonek@webkit.org) | 6 # Copyright (C) 2010 Chris Jerdonek (cjerdonek@webkit.org) |
| 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 2210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2221 | 2221 |
| 2222 # Cheat os.path.abspath called in FileInfo class. | 2222 # Cheat os.path.abspath called in FileInfo class. |
| 2223 self.os_path_abspath_orig = os.path.abspath | 2223 self.os_path_abspath_orig = os.path.abspath |
| 2224 self.os_path_isfile_orig = os.path.isfile | 2224 self.os_path_isfile_orig = os.path.isfile |
| 2225 os.path.abspath = lambda value: value | 2225 os.path.abspath = lambda value: value |
| 2226 | 2226 |
| 2227 def tearDown(self): | 2227 def tearDown(self): |
| 2228 os.path.abspath = self.os_path_abspath_orig | 2228 os.path.abspath = self.os_path_abspath_orig |
| 2229 os.path.isfile = self.os_path_isfile_orig | 2229 os.path.isfile = self.os_path_isfile_orig |
| 2230 | 2230 |
| 2231 def test_check_next_include_order__no_self(self): | |
| 2232 self.assertEqual('Header file should not contain itself.', | |
| 2233 self.include_state.check_next_include_order(cpp_style._
PRIMARY_HEADER, True, True)) | |
| 2234 # Test actual code to make sure that header types are correctly assigned
. | |
| 2235 self.assert_language_rules_check('Foo.h', | |
| 2236 '#include "Foo.h"\n', | |
| 2237 'Header file should not contain itself.
Should be: alphabetically sorted.' | |
| 2238 ' [build/include_order] [4]') | |
| 2239 self.assert_language_rules_check('FooBar.h', | |
| 2240 '#include "Foo.h"\n', | |
| 2241 '') | |
| 2242 | |
| 2243 def test_check_next_include_order__likely_then_config(self): | |
| 2244 self.assertEqual('', | |
| 2245 self.include_state.check_next_include_order(cpp_style._
PRIMARY_HEADER, False, True)) | |
| 2246 | |
| 2247 def test_check_next_include_order__other_then_config(self): | |
| 2248 self.assertEqual('Found other header before a header this file implement
s.', | |
| 2249 self.include_state.check_next_include_order(cpp_style._
OTHER_HEADER, False, True)) | |
| 2250 | |
| 2251 def test_check_next_include_order__config_then_other_then_likely(self): | |
| 2252 self.assertEqual('Found other header before a header this file implement
s.', | |
| 2253 self.include_state.check_next_include_order(cpp_style._
OTHER_HEADER, False, True)) | |
| 2254 self.assertEqual('Found header this file implements after other header.'
, | |
| 2255 self.include_state.check_next_include_order(cpp_style._
PRIMARY_HEADER, False, True)) | |
| 2256 | |
| 2257 def test_check_line_break_after_own_header(self): | |
| 2258 self.assert_language_rules_check('foo.cpp', | |
| 2259 '#include "foo.h"\n' | |
| 2260 '#include "bar.h"\n', | |
| 2261 ('You should add a blank line after imp
lementation file\'s own header.' | |
| 2262 ' [build/include_order] [4]')) | |
| 2263 | |
| 2264 self.assert_language_rules_check('foo.cpp', | |
| 2265 '#include "foo.h"\n' | |
| 2266 '\n' | |
| 2267 '#include "bar.h"\n', | |
| 2268 '') | |
| 2269 | |
| 2270 def test_check_preprocessor_in_include_section(self): | 2231 def test_check_preprocessor_in_include_section(self): |
| 2271 self.assert_language_rules_check('foo.cpp', | 2232 self.assert_language_rules_check('foo.cpp', |
| 2272 '#include "foo.h"\n' | 2233 '#include "foo.h"\n' |
| 2273 '\n' | 2234 '\n' |
| 2274 '#ifdef BAZ\n' | 2235 '#ifdef BAZ\n' |
| 2275 '#include "baz.h"\n' | 2236 '#include "baz.h"\n' |
| 2276 '#else\n' | 2237 '#else\n' |
| 2277 '#include "foobar.h"\n' | 2238 '#include "foobar.h"\n' |
| 2278 '#endif"\n' | 2239 '#endif"\n' |
| 2279 '#include "bar.h"\n', # No flag becaus
e previous is in preprocessor section | 2240 '#include "bar.h"\n', # No flag becaus
e previous is in preprocessor section |
| 2280 '') | 2241 '') |
| 2281 | 2242 |
| 2282 # Check that after an already included error, the sorting rules still wo
rk. | 2243 # Check that after an already included error, the sorting rules still wo
rk. |
| 2283 self.assert_language_rules_check('foo.cpp', | 2244 self.assert_language_rules_check('foo.cpp', |
| 2284 '#include "foo.h"\n' | 2245 '#include "foo.h"\n' |
| 2285 '\n' | 2246 '\n' |
| 2286 '#include "foo.h"\n' | 2247 '#include "foo.h"\n' |
| 2287 '#include "g.h"\n', | 2248 '#include "g.h"\n', |
| 2288 '"foo.h" already included at foo.cpp:1
[build/include] [4]') | 2249 '"foo.h" already included at foo.cpp:1
[build/include] [4]') |
| 2289 | 2250 |
| 2290 def test_primary_header(self): | |
| 2291 # File with non-existing primary header should not produce errors. | |
| 2292 self.assert_language_rules_check('foo.cpp', | |
| 2293 '\n' | |
| 2294 '#include "bar.h"\n', | |
| 2295 '') | |
| 2296 # Pretend that header files exist. | |
| 2297 os.path.isfile = lambda filename: True | |
| 2298 # Missing include for existing primary header -> error. | |
| 2299 self.assert_language_rules_check('foo.cpp', | |
| 2300 '\n' | |
| 2301 '#include "bar.h"\n', | |
| 2302 'Found other header before a header thi
s file implements. ' | |
| 2303 'Should be: primary header, blank line,
and then ' | |
| 2304 'alphabetically sorted. [build/include
_order] [4]') | |
| 2305 self.assert_language_rules_check('foo.cpp', | |
| 2306 '#include "config.h"\n' | |
| 2307 '#include "foo.h"\n' | |
| 2308 '\n' | |
| 2309 '#include "bar.h"\n', | |
| 2310 ['Found other header before a header th
is file implements. ' | |
| 2311 'Should be: primary header, blank line
, and then ' | |
| 2312 'alphabetically sorted. [build/includ
e_order] [4]', | |
| 2313 'Found header this file implements aft
er other header. ' | |
| 2314 'Should be: primary header, blank line
, and then ' | |
| 2315 'alphabetically sorted. [build/includ
e_order] [4]']) | |
| 2316 # Having include for existing primary header -> no error. | |
| 2317 self.assert_language_rules_check('foo.cpp', | |
| 2318 '#include "foo.h"\n' | |
| 2319 '\n' | |
| 2320 '#include "bar.h"\n', | |
| 2321 '') | |
| 2322 | |
| 2323 os.path.isfile = self.os_path_isfile_orig | |
| 2324 | |
| 2325 def test_check_wtf_includes(self): | 2251 def test_check_wtf_includes(self): |
| 2326 self.assert_language_rules_check('foo.cpp', | 2252 self.assert_language_rules_check('foo.cpp', |
| 2327 '#include "foo.h"\n' | 2253 '#include "foo.h"\n' |
| 2328 '\n' | 2254 '\n' |
| 2329 '#include <wtf/Assertions.h>\n', | 2255 '#include <wtf/Assertions.h>\n', |
| 2330 'wtf includes should be "wtf/file.h" in
stead of <wtf/file.h>.' | 2256 'wtf includes should be "wtf/file.h" in
stead of <wtf/file.h>.' |
| 2331 ' [build/include] [4]') | 2257 ' [build/include] [4]') |
| 2332 self.assert_language_rules_check('foo.cpp', | 2258 self.assert_language_rules_check('foo.cpp', |
| 2333 '#include "foo.h"\n' | 2259 '#include "foo.h"\n' |
| 2334 '\n' | 2260 '\n' |
| 2335 '#include "wtf/Assertions.h"\n', | 2261 '#include "wtf/Assertions.h"\n', |
| 2336 '') | 2262 '') |
| 2337 | 2263 |
| 2338 def test_check_cc_includes(self): | 2264 def test_check_cc_includes(self): |
| 2339 self.assert_language_rules_check('bar/chromium/foo.cpp', | 2265 self.assert_language_rules_check('bar/chromium/foo.cpp', |
| 2340 '#include "foo.h"\n' | 2266 '#include "foo.h"\n' |
| 2341 '\n' | 2267 '\n' |
| 2342 '#include "cc/CCProxy.h"\n', | 2268 '#include "cc/CCProxy.h"\n', |
| 2343 'cc includes should be "CCFoo.h" instea
d of "cc/CCFoo.h".' | 2269 'cc includes should be "CCFoo.h" instea
d of "cc/CCFoo.h".' |
| 2344 ' [build/include] [4]') | 2270 ' [build/include] [4]') |
| 2345 | 2271 |
| 2346 def test_classify_include(self): | |
| 2347 classify_include = cpp_style._classify_include | |
| 2348 include_state = cpp_style._IncludeState() | |
| 2349 self.assertEqual(cpp_style._OTHER_HEADER, | |
| 2350 classify_include('foo/foo.cpp', | |
| 2351 'config.h', | |
| 2352 False, include_state)) | |
| 2353 self.assertEqual(cpp_style._PRIMARY_HEADER, | |
| 2354 classify_include('foo/internal/foo.cpp', | |
| 2355 'foo/public/foo.h', | |
| 2356 False, include_state)) | |
| 2357 self.assertEqual(cpp_style._PRIMARY_HEADER, | |
| 2358 classify_include('foo/internal/foo.cpp', | |
| 2359 'foo/other/public/foo.h', | |
| 2360 False, include_state)) | |
| 2361 self.assertEqual(cpp_style._OTHER_HEADER, | |
| 2362 classify_include('foo/internal/foo.cpp', | |
| 2363 'foo/other/public/foop.h', | |
| 2364 False, include_state)) | |
| 2365 self.assertEqual(cpp_style._OTHER_HEADER, | |
| 2366 classify_include('foo/foo.cpp', | |
| 2367 'string', | |
| 2368 True, include_state)) | |
| 2369 self.assertEqual(cpp_style._PRIMARY_HEADER, | |
| 2370 classify_include('fooCustom.cpp', | |
| 2371 'foo.h', | |
| 2372 False, include_state)) | |
| 2373 self.assertEqual(cpp_style._PRIMARY_HEADER, | |
| 2374 classify_include('PrefixFooCustom.cpp', | |
| 2375 'Foo.h', | |
| 2376 False, include_state)) | |
| 2377 # <public/foo.h> must be considered as primary even if is_system is True
. | |
| 2378 self.assertEqual(cpp_style._PRIMARY_HEADER, | |
| 2379 classify_include('foo/foo.cpp', | |
| 2380 'public/foo.h', | |
| 2381 True, include_state)) | |
| 2382 self.assertEqual(cpp_style._OTHER_HEADER, | |
| 2383 classify_include('foo.cpp', | |
| 2384 'foo.h', | |
| 2385 True, include_state)) | |
| 2386 self.assertEqual(cpp_style._OTHER_HEADER, | |
| 2387 classify_include('foo.cpp', | |
| 2388 'public/foop.h', | |
| 2389 True, include_state)) | |
| 2390 # Tricky example where both includes might be classified as primary. | |
| 2391 self.assert_language_rules_check('ScrollbarThemeWince.cpp', | |
| 2392 '#include "ScrollbarThemeWince.h"\n' | |
| 2393 '\n' | |
| 2394 '#include "Scrollbar.h"\n', | |
| 2395 '') | |
| 2396 self.assert_language_rules_check('ScrollbarThemeWince.cpp', | |
| 2397 '#include "Scrollbar.h"\n' | |
| 2398 '\n' | |
| 2399 '#include "ScrollbarThemeWince.h"\n', | |
| 2400 'Found header this file implements afte
r a header this file implements.' | |
| 2401 ' Should be: primary header, blank line
, and then alphabetically sorted.' | |
| 2402 ' [build/include_order] [4]') | |
| 2403 | |
| 2404 def test_try_drop_common_suffixes(self): | |
| 2405 self.assertEqual('foo/foo', cpp_style._drop_common_suffixes('foo/foo-inl
.h')) | |
| 2406 self.assertEqual('foo/bar/foo', | |
| 2407 cpp_style._drop_common_suffixes('foo/bar/foo_inl.h')) | |
| 2408 self.assertEqual('foo/foo', cpp_style._drop_common_suffixes('foo/foo.cpp
')) | |
| 2409 self.assertEqual('foo/foo_unusualinternal', | |
| 2410 cpp_style._drop_common_suffixes('foo/foo_unusualinterna
l.h')) | |
| 2411 self.assertEqual('', | |
| 2412 cpp_style._drop_common_suffixes('_test.cpp')) | |
| 2413 self.assertEqual('test', | |
| 2414 cpp_style._drop_common_suffixes('test.cpp')) | |
| 2415 self.assertEqual('test', | |
| 2416 cpp_style._drop_common_suffixes('test.cpp')) | |
| 2417 | |
| 2418 | 2272 |
| 2419 class CheckForFunctionLengthsTest(CppStyleTestBase): | 2273 class CheckForFunctionLengthsTest(CppStyleTestBase): |
| 2420 | 2274 |
| 2421 def setUp(self): | 2275 def setUp(self): |
| 2422 # Reducing these thresholds for the tests speeds up tests significantly. | 2276 # Reducing these thresholds for the tests speeds up tests significantly. |
| 2423 self.old_normal_trigger = cpp_style._FunctionState._NORMAL_TRIGGER | 2277 self.old_normal_trigger = cpp_style._FunctionState._NORMAL_TRIGGER |
| 2424 self.old_test_trigger = cpp_style._FunctionState._TEST_TRIGGER | 2278 self.old_test_trigger = cpp_style._FunctionState._TEST_TRIGGER |
| 2425 | 2279 |
| 2426 cpp_style._FunctionState._NORMAL_TRIGGER = 10 | 2280 cpp_style._FunctionState._NORMAL_TRIGGER = 10 |
| 2427 cpp_style._FunctionState._TEST_TRIGGER = 25 | 2281 cpp_style._FunctionState._TEST_TRIGGER = 25 |
| (...skipping 1687 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4115 def test_ne(self): | 3969 def test_ne(self): |
| 4116 """Test __ne__ inequality function.""" | 3970 """Test __ne__ inequality function.""" |
| 4117 checker1 = self._checker() | 3971 checker1 = self._checker() |
| 4118 checker2 = self._checker() | 3972 checker2 = self._checker() |
| 4119 | 3973 |
| 4120 # != calls __ne__. | 3974 # != calls __ne__. |
| 4121 # By default, __ne__ always returns true on different objects. | 3975 # By default, __ne__ always returns true on different objects. |
| 4122 # Thus, just check the distinguishing case to verify that the | 3976 # Thus, just check the distinguishing case to verify that the |
| 4123 # code defines __ne__. | 3977 # code defines __ne__. |
| 4124 self.assertFalse(checker1 != checker2) | 3978 self.assertFalse(checker1 != checker2) |
| OLD | NEW |