Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: third_party/WebKit/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py

Issue 2667423006: blink: Remove include ordering checks, clang-format does this now. (Closed)
Patch Set: feedback Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Tools/Scripts/webkitpy/style/checkers/cpp.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 2253 matching lines...) Expand 10 before | Expand all | Expand 10 after
2264 def test_check_next_include_order__other_then_config(self): 2264 def test_check_next_include_order__other_then_config(self):
2265 self.assertEqual('Found other header before a header this file implement s.', 2265 self.assertEqual('Found other header before a header this file implement s.',
2266 self.include_state.check_next_include_order(cpp_style._ OTHER_HEADER, False, True)) 2266 self.include_state.check_next_include_order(cpp_style._ OTHER_HEADER, False, True))
2267 2267
2268 def test_check_next_include_order__config_then_other_then_likely(self): 2268 def test_check_next_include_order__config_then_other_then_likely(self):
2269 self.assertEqual('Found other header before a header this file implement s.', 2269 self.assertEqual('Found other header before a header this file implement s.',
2270 self.include_state.check_next_include_order(cpp_style._ OTHER_HEADER, False, True)) 2270 self.include_state.check_next_include_order(cpp_style._ OTHER_HEADER, False, True))
2271 self.assertEqual('Found header this file implements after other header.' , 2271 self.assertEqual('Found header this file implements after other header.' ,
2272 self.include_state.check_next_include_order(cpp_style._ PRIMARY_HEADER, False, True)) 2272 self.include_state.check_next_include_order(cpp_style._ PRIMARY_HEADER, False, True))
2273 2273
2274 def test_check_alphabetical_include_order(self):
2275 self.assert_language_rules_check('foo.h',
2276 '#include "a.h"\n'
2277 '#include "c.h"\n'
2278 '#include "b.h"\n',
2279 'Alphabetical sorting problem. [build/ include_order] [4]')
2280
2281 self.assert_language_rules_check('foo.h',
2282 '#include "a.h"\n'
2283 '#include "b.h"\n'
2284 '#include "c.h"\n',
2285 '')
2286
2287 self.assert_language_rules_check('foo.h',
2288 '#include <assert.h>\n'
2289 '#include "bar.h"\n',
2290 'Alphabetical sorting problem. [build/ include_order] [4]')
2291
2292 self.assert_language_rules_check('foo.h',
2293 '#include "bar.h"\n'
2294 '#include <assert.h>\n',
2295 '')
2296
2297 def test_check_alphabetical_include_order_errors_reported_for_both_lines(sel f):
2298 # If one of the two lines of out of order headers are filtered, the erro r should be
2299 # reported on the other line.
2300 self.assert_language_rules_check('foo.h',
2301 '#include "a.h"\n'
2302 '#include "c.h"\n'
2303 '#include "b.h"\n',
2304 'Alphabetical sorting problem. [build/ include_order] [4]',
2305 lines_to_check=[2])
2306
2307 self.assert_language_rules_check('foo.h',
2308 '#include "a.h"\n'
2309 '#include "c.h"\n'
2310 '#include "b.h"\n',
2311 'Alphabetical sorting problem. [build/ include_order] [4]',
2312 lines_to_check=[3])
2313
2314 # If no lines are filtered, the error should be reported only once.
2315 self.assert_language_rules_check('foo.h',
2316 '#include "a.h"\n'
2317 '#include "c.h"\n'
2318 '#include "b.h"\n',
2319 'Alphabetical sorting problem. [build/ include_order] [4]')
2320
2321 def test_check_line_break_after_own_header(self): 2274 def test_check_line_break_after_own_header(self):
2322 self.assert_language_rules_check('foo.cpp', 2275 self.assert_language_rules_check('foo.cpp',
2323 '#include "foo.h"\n' 2276 '#include "foo.h"\n'
2324 '#include "bar.h"\n', 2277 '#include "bar.h"\n',
2325 ('You should add a blank line after imp lementation file\'s own header.' 2278 ('You should add a blank line after imp lementation file\'s own header.'
2326 ' [build/include_order] [4]')) 2279 ' [build/include_order] [4]'))
2327 2280
2328 self.assert_language_rules_check('foo.cpp', 2281 self.assert_language_rules_check('foo.cpp',
2329 '#include "foo.h"\n' 2282 '#include "foo.h"\n'
2330 '\n' 2283 '\n'
2331 '#include "bar.h"\n', 2284 '#include "bar.h"\n',
2332 '') 2285 '')
2333 2286
2334 def test_check_preprocessor_in_include_section(self): 2287 def test_check_preprocessor_in_include_section(self):
2335 self.assert_language_rules_check('foo.cpp', 2288 self.assert_language_rules_check('foo.cpp',
2336 '#include "foo.h"\n' 2289 '#include "foo.h"\n'
2337 '\n' 2290 '\n'
2338 '#ifdef BAZ\n' 2291 '#ifdef BAZ\n'
2339 '#include "baz.h"\n' 2292 '#include "baz.h"\n'
2340 '#else\n' 2293 '#else\n'
2341 '#include "foobar.h"\n' 2294 '#include "foobar.h"\n'
2342 '#endif"\n' 2295 '#endif"\n'
2343 '#include "bar.h"\n', # No flag becaus e previous is in preprocessor section 2296 '#include "bar.h"\n', # No flag becaus e previous is in preprocessor section
2344 '') 2297 '')
2345 2298
2346 self.assert_language_rules_check('foo.cpp',
2347 '#include "foo.h"\n'
2348 '\n'
2349 '#ifdef BAZ\n'
2350 '#include "baz.h"\n'
2351 '#endif"\n'
2352 '#include "bar.h"\n'
2353 '#include "a.h"\n', # Should still fla g this.
2354 'Alphabetical sorting problem. [build/ include_order] [4]')
2355
2356 self.assert_language_rules_check('foo.cpp',
2357 '#include "foo.h"\n'
2358 '\n'
2359 '#ifdef BAZ\n'
2360 '#include "baz.h"\n'
2361 '#include "bar.h"\n' # Should still fl ag this
2362 '#endif"\n',
2363 'Alphabetical sorting problem. [build/ include_order] [4]')
2364
2365 self.assert_language_rules_check('foo.cpp',
2366 '#include "foo.h"\n'
2367 '\n'
2368 '#ifdef BAZ\n'
2369 '#include "baz.h"\n'
2370 '#endif"\n'
2371 '#ifdef FOOBAR\n'
2372 '#include "foobar.h"\n'
2373 '#endif"\n'
2374 '#include "bar.h"\n'
2375 '#include "a.h"\n', # Should still fla g this.
2376 'Alphabetical sorting problem. [build/ include_order] [4]')
2377
2378 # Check that after an already included error, the sorting rules still wo rk. 2299 # Check that after an already included error, the sorting rules still wo rk.
2379 self.assert_language_rules_check('foo.cpp', 2300 self.assert_language_rules_check('foo.cpp',
2380 '#include "foo.h"\n' 2301 '#include "foo.h"\n'
2381 '\n' 2302 '\n'
2382 '#include "foo.h"\n' 2303 '#include "foo.h"\n'
2383 '#include "g.h"\n', 2304 '#include "g.h"\n',
2384 '"foo.h" already included at foo.cpp:1 [build/include] [4]') 2305 '"foo.h" already included at foo.cpp:1 [build/include] [4]')
2385 2306
2386 def test_primary_header(self): 2307 def test_primary_header(self):
2387 # File with non-existing primary header should not produce errors. 2308 # File with non-existing primary header should not produce errors.
(...skipping 23 matching lines...) Expand all
2411 'alphabetically sorted. [build/includ e_order] [4]']) 2332 'alphabetically sorted. [build/includ e_order] [4]'])
2412 # Having include for existing primary header -> no error. 2333 # Having include for existing primary header -> no error.
2413 self.assert_language_rules_check('foo.cpp', 2334 self.assert_language_rules_check('foo.cpp',
2414 '#include "foo.h"\n' 2335 '#include "foo.h"\n'
2415 '\n' 2336 '\n'
2416 '#include "bar.h"\n', 2337 '#include "bar.h"\n',
2417 '') 2338 '')
2418 2339
2419 os.path.isfile = self.os_path_isfile_orig 2340 os.path.isfile = self.os_path_isfile_orig
2420 2341
2421 def test_public_primary_header(self):
2422 # System header is not considered a primary header.
2423 self.assert_language_rules_check('foo.cpp',
2424 '#include "config.h"\n'
2425 '#include <other/foo.h>\n'
2426 '\n'
2427 '#include "a.h"\n',
2428 'Alphabetical sorting problem. [build/ include_order] [4]')
2429
2430 # ...except that it starts with public/.
2431 self.assert_language_rules_check('foo.cpp',
2432 '#include <public/foo.h>\n'
2433 '\n'
2434 '#include "a.h"\n',
2435 '')
2436
2437 # Even if it starts with public/ its base part must match with the sourc e file name.
2438 self.assert_language_rules_check('foo.cpp',
2439 '#include "config.h"\n'
2440 '#include <public/foop.h>\n'
2441 '\n'
2442 '#include "a.h"\n',
2443 'Alphabetical sorting problem. [build/ include_order] [4]')
2444
2445 def test_check_wtf_includes(self): 2342 def test_check_wtf_includes(self):
2446 self.assert_language_rules_check('foo.cpp', 2343 self.assert_language_rules_check('foo.cpp',
2447 '#include "foo.h"\n' 2344 '#include "foo.h"\n'
2448 '\n' 2345 '\n'
2449 '#include <wtf/Assertions.h>\n', 2346 '#include <wtf/Assertions.h>\n',
2450 'wtf includes should be "wtf/file.h" in stead of <wtf/file.h>.' 2347 'wtf includes should be "wtf/file.h" in stead of <wtf/file.h>.'
2451 ' [build/include] [4]') 2348 ' [build/include] [4]')
2452 self.assert_language_rules_check('foo.cpp', 2349 self.assert_language_rules_check('foo.cpp',
2453 '#include "foo.h"\n' 2350 '#include "foo.h"\n'
2454 '\n' 2351 '\n'
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
2487 'string', 2384 'string',
2488 True, include_state)) 2385 True, include_state))
2489 self.assertEqual(cpp_style._PRIMARY_HEADER, 2386 self.assertEqual(cpp_style._PRIMARY_HEADER,
2490 classify_include('fooCustom.cpp', 2387 classify_include('fooCustom.cpp',
2491 'foo.h', 2388 'foo.h',
2492 False, include_state)) 2389 False, include_state))
2493 self.assertEqual(cpp_style._PRIMARY_HEADER, 2390 self.assertEqual(cpp_style._PRIMARY_HEADER,
2494 classify_include('PrefixFooCustom.cpp', 2391 classify_include('PrefixFooCustom.cpp',
2495 'Foo.h', 2392 'Foo.h',
2496 False, include_state)) 2393 False, include_state))
2497 self.assertEqual(cpp_style._MOC_HEADER,
2498 classify_include('foo.cpp',
2499 'foo.moc',
2500 False, include_state))
2501 self.assertEqual(cpp_style._MOC_HEADER,
2502 classify_include('foo.cpp',
2503 'moc_foo.cpp',
2504 False, include_state))
2505 # <public/foo.h> must be considered as primary even if is_system is True . 2394 # <public/foo.h> must be considered as primary even if is_system is True .
2506 self.assertEqual(cpp_style._PRIMARY_HEADER, 2395 self.assertEqual(cpp_style._PRIMARY_HEADER,
2507 classify_include('foo/foo.cpp', 2396 classify_include('foo/foo.cpp',
2508 'public/foo.h', 2397 'public/foo.h',
2509 True, include_state)) 2398 True, include_state))
2510 self.assertEqual(cpp_style._OTHER_HEADER, 2399 self.assertEqual(cpp_style._OTHER_HEADER,
2511 classify_include('foo.cpp', 2400 classify_include('foo.cpp',
2512 'foo.h', 2401 'foo.h',
2513 True, include_state)) 2402 True, include_state))
2514 self.assertEqual(cpp_style._OTHER_HEADER, 2403 self.assertEqual(cpp_style._OTHER_HEADER,
2515 classify_include('foo.cpp', 2404 classify_include('foo.cpp',
2516 'public/foop.h', 2405 'public/foop.h',
2517 True, include_state)) 2406 True, include_state))
2518 # Qt private APIs use _p.h suffix.
2519 self.assertEqual(cpp_style._PRIMARY_HEADER,
2520 classify_include('foo.cpp',
2521 'foo_p.h',
2522 False, include_state))
2523 # Tricky example where both includes might be classified as primary. 2407 # Tricky example where both includes might be classified as primary.
2524 self.assert_language_rules_check('ScrollbarThemeWince.cpp', 2408 self.assert_language_rules_check('ScrollbarThemeWince.cpp',
2525 '#include "ScrollbarThemeWince.h"\n' 2409 '#include "ScrollbarThemeWince.h"\n'
2526 '\n' 2410 '\n'
2527 '#include "Scrollbar.h"\n', 2411 '#include "Scrollbar.h"\n',
2528 '') 2412 '')
2529 self.assert_language_rules_check('ScrollbarThemeWince.cpp', 2413 self.assert_language_rules_check('ScrollbarThemeWince.cpp',
2530 '#include "Scrollbar.h"\n' 2414 '#include "Scrollbar.h"\n'
2531 '\n' 2415 '\n'
2532 '#include "ScrollbarThemeWince.h"\n', 2416 '#include "ScrollbarThemeWince.h"\n',
2533 'Found header this file implements afte r a header this file implements.' 2417 'Found header this file implements afte r a header this file implements.'
2534 ' Should be: primary header, blank line , and then alphabetically sorted.' 2418 ' Should be: primary header, blank line , and then alphabetically sorted.'
2535 ' [build/include_order] [4]') 2419 ' [build/include_order] [4]')
2536 self.assert_language_rules_check('ResourceHandleWin.cpp',
2537 '#include "ResourceHandle.h"\n'
2538 '\n'
2539 '#include "ResourceHandleWin.h"\n',
2540 '')
2541 2420
2542 def test_try_drop_common_suffixes(self): 2421 def test_try_drop_common_suffixes(self):
2543 self.assertEqual('foo/foo', cpp_style._drop_common_suffixes('foo/foo-inl .h')) 2422 self.assertEqual('foo/foo', cpp_style._drop_common_suffixes('foo/foo-inl .h'))
2544 self.assertEqual('foo/bar/foo', 2423 self.assertEqual('foo/bar/foo',
2545 cpp_style._drop_common_suffixes('foo/bar/foo_inl.h')) 2424 cpp_style._drop_common_suffixes('foo/bar/foo_inl.h'))
2546 self.assertEqual('foo/foo', cpp_style._drop_common_suffixes('foo/foo.cpp ')) 2425 self.assertEqual('foo/foo', cpp_style._drop_common_suffixes('foo/foo.cpp '))
2547 self.assertEqual('foo/foo_unusualinternal', 2426 self.assertEqual('foo/foo_unusualinternal',
2548 cpp_style._drop_common_suffixes('foo/foo_unusualinterna l.h')) 2427 cpp_style._drop_common_suffixes('foo/foo_unusualinterna l.h'))
2549 self.assertEqual('', 2428 self.assertEqual('',
2550 cpp_style._drop_common_suffixes('_test.cpp')) 2429 cpp_style._drop_common_suffixes('_test.cpp'))
(...skipping 1705 matching lines...) Expand 10 before | Expand all | Expand 10 after
4256 def test_ne(self): 4135 def test_ne(self):
4257 """Test __ne__ inequality function.""" 4136 """Test __ne__ inequality function."""
4258 checker1 = self._checker() 4137 checker1 = self._checker()
4259 checker2 = self._checker() 4138 checker2 = self._checker()
4260 4139
4261 # != calls __ne__. 4140 # != calls __ne__.
4262 # By default, __ne__ always returns true on different objects. 4141 # By default, __ne__ always returns true on different objects.
4263 # Thus, just check the distinguishing case to verify that the 4142 # Thus, just check the distinguishing case to verify that the
4264 # code defines __ne__. 4143 # code defines __ne__.
4265 self.assertFalse(checker1 != checker2) 4144 self.assertFalse(checker1 != checker2)
OLDNEW
« no previous file with comments | « third_party/WebKit/Tools/Scripts/webkitpy/style/checkers/cpp.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698