Chromium Code Reviews| 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): | 2231 def test_check_next_include_order__likely_then_config(self): |
|
dcheng
2017/03/17 05:37:29
I think these three tests can be removed as well
alancutter (OOO until 2018)
2017/03/19 23:12:48
Done. Removed the function they tested as well as
| |
| 2244 self.assertEqual('', | 2232 self.assertEqual('', |
| 2245 self.include_state.check_next_include_order(cpp_style._ PRIMARY_HEADER, False, True)) | 2233 self.include_state.check_next_include_order(cpp_style._ PRIMARY_HEADER, False, True)) |
| 2246 | 2234 |
| 2247 def test_check_next_include_order__other_then_config(self): | 2235 def test_check_next_include_order__other_then_config(self): |
| 2248 self.assertEqual('Found other header before a header this file implement s.', | 2236 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)) | 2237 self.include_state.check_next_include_order(cpp_style._ OTHER_HEADER, False, True)) |
| 2250 | 2238 |
| 2251 def test_check_next_include_order__config_then_other_then_likely(self): | 2239 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.', | 2240 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)) | 2241 self.include_state.check_next_include_order(cpp_style._ OTHER_HEADER, False, True)) |
| 2254 self.assertEqual('Found header this file implements after other header.' , | 2242 self.assertEqual('Found header this file implements after other header.' , |
| 2255 self.include_state.check_next_include_order(cpp_style._ PRIMARY_HEADER, False, True)) | 2243 self.include_state.check_next_include_order(cpp_style._ PRIMARY_HEADER, False, True)) |
| 2256 | 2244 |
| 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): | 2245 def test_check_preprocessor_in_include_section(self): |
| 2271 self.assert_language_rules_check('foo.cpp', | 2246 self.assert_language_rules_check('foo.cpp', |
| 2272 '#include "foo.h"\n' | 2247 '#include "foo.h"\n' |
| 2273 '\n' | 2248 '\n' |
| 2274 '#ifdef BAZ\n' | 2249 '#ifdef BAZ\n' |
| 2275 '#include "baz.h"\n' | 2250 '#include "baz.h"\n' |
| 2276 '#else\n' | 2251 '#else\n' |
| 2277 '#include "foobar.h"\n' | 2252 '#include "foobar.h"\n' |
| 2278 '#endif"\n' | 2253 '#endif"\n' |
| 2279 '#include "bar.h"\n', # No flag becaus e previous is in preprocessor section | 2254 '#include "bar.h"\n', # No flag becaus e previous is in preprocessor section |
| 2280 '') | 2255 '') |
| 2281 | 2256 |
| 2282 # Check that after an already included error, the sorting rules still wo rk. | 2257 # Check that after an already included error, the sorting rules still wo rk. |
| 2283 self.assert_language_rules_check('foo.cpp', | 2258 self.assert_language_rules_check('foo.cpp', |
| 2284 '#include "foo.h"\n' | 2259 '#include "foo.h"\n' |
| 2285 '\n' | 2260 '\n' |
| 2286 '#include "foo.h"\n' | 2261 '#include "foo.h"\n' |
| 2287 '#include "g.h"\n', | 2262 '#include "g.h"\n', |
| 2288 '"foo.h" already included at foo.cpp:1 [build/include] [4]') | 2263 '"foo.h" already included at foo.cpp:1 [build/include] [4]') |
| 2289 | 2264 |
| 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): | 2265 def test_check_wtf_includes(self): |
| 2326 self.assert_language_rules_check('foo.cpp', | 2266 self.assert_language_rules_check('foo.cpp', |
| 2327 '#include "foo.h"\n' | 2267 '#include "foo.h"\n' |
| 2328 '\n' | 2268 '\n' |
| 2329 '#include <wtf/Assertions.h>\n', | 2269 '#include <wtf/Assertions.h>\n', |
| 2330 'wtf includes should be "wtf/file.h" in stead of <wtf/file.h>.' | 2270 'wtf includes should be "wtf/file.h" in stead of <wtf/file.h>.' |
| 2331 ' [build/include] [4]') | 2271 ' [build/include] [4]') |
| 2332 self.assert_language_rules_check('foo.cpp', | 2272 self.assert_language_rules_check('foo.cpp', |
| 2333 '#include "foo.h"\n' | 2273 '#include "foo.h"\n' |
| 2334 '\n' | 2274 '\n' |
| 2335 '#include "wtf/Assertions.h"\n', | 2275 '#include "wtf/Assertions.h"\n', |
| 2336 '') | 2276 '') |
| 2337 | 2277 |
| 2338 def test_check_cc_includes(self): | 2278 def test_check_cc_includes(self): |
| 2339 self.assert_language_rules_check('bar/chromium/foo.cpp', | 2279 self.assert_language_rules_check('bar/chromium/foo.cpp', |
| 2340 '#include "foo.h"\n' | 2280 '#include "foo.h"\n' |
| 2341 '\n' | 2281 '\n' |
| 2342 '#include "cc/CCProxy.h"\n', | 2282 '#include "cc/CCProxy.h"\n', |
| 2343 'cc includes should be "CCFoo.h" instea d of "cc/CCFoo.h".' | 2283 'cc includes should be "CCFoo.h" instea d of "cc/CCFoo.h".' |
| 2344 ' [build/include] [4]') | 2284 ' [build/include] [4]') |
| 2345 | 2285 |
| 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): | 2286 def test_try_drop_common_suffixes(self): |
|
dcheng
2017/03/17 05:37:30
Perhaps this one too.
alancutter (OOO until 2018)
2017/03/19 23:12:48
Done. Removed the function it tested as well as it
| |
| 2405 self.assertEqual('foo/foo', cpp_style._drop_common_suffixes('foo/foo-inl .h')) | 2287 self.assertEqual('foo/foo', cpp_style._drop_common_suffixes('foo/foo-inl .h')) |
| 2406 self.assertEqual('foo/bar/foo', | 2288 self.assertEqual('foo/bar/foo', |
| 2407 cpp_style._drop_common_suffixes('foo/bar/foo_inl.h')) | 2289 cpp_style._drop_common_suffixes('foo/bar/foo_inl.h')) |
| 2408 self.assertEqual('foo/foo', cpp_style._drop_common_suffixes('foo/foo.cpp ')) | 2290 self.assertEqual('foo/foo', cpp_style._drop_common_suffixes('foo/foo.cpp ')) |
| 2409 self.assertEqual('foo/foo_unusualinternal', | 2291 self.assertEqual('foo/foo_unusualinternal', |
| 2410 cpp_style._drop_common_suffixes('foo/foo_unusualinterna l.h')) | 2292 cpp_style._drop_common_suffixes('foo/foo_unusualinterna l.h')) |
| 2411 self.assertEqual('', | 2293 self.assertEqual('', |
| 2412 cpp_style._drop_common_suffixes('_test.cpp')) | 2294 cpp_style._drop_common_suffixes('_test.cpp')) |
| 2413 self.assertEqual('test', | 2295 self.assertEqual('test', |
| 2414 cpp_style._drop_common_suffixes('test.cpp')) | 2296 cpp_style._drop_common_suffixes('test.cpp')) |
| (...skipping 1700 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4115 def test_ne(self): | 3997 def test_ne(self): |
| 4116 """Test __ne__ inequality function.""" | 3998 """Test __ne__ inequality function.""" |
| 4117 checker1 = self._checker() | 3999 checker1 = self._checker() |
| 4118 checker2 = self._checker() | 4000 checker2 = self._checker() |
| 4119 | 4001 |
| 4120 # != calls __ne__. | 4002 # != calls __ne__. |
| 4121 # By default, __ne__ always returns true on different objects. | 4003 # By default, __ne__ always returns true on different objects. |
| 4122 # Thus, just check the distinguishing case to verify that the | 4004 # Thus, just check the distinguishing case to verify that the |
| 4123 # code defines __ne__. | 4005 # code defines __ne__. |
| 4124 self.assertFalse(checker1 != checker2) | 4006 self.assertFalse(checker1 != checker2) |
| OLD | NEW |