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

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

Issue 2386353002: Teach check-webkit-py in one more place that indent is now 2 spaces (Closed)
Patch Set: Created 4 years, 2 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 492 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 'is_pure': True, 503 'is_pure': True,
504 'is_declaration': True}) 504 'is_declaration': True})
505 505
506 def test_ignore_macros(self): 506 def test_ignore_macros(self):
507 self.perform_function_detection(['void aFunctionName(int); \\'], None) 507 self.perform_function_detection(['void aFunctionName(int); \\'], None)
508 508
509 def test_non_functions(self): 509 def test_non_functions(self):
510 # This case exposed an error because the open brace was in quotes. 510 # This case exposed an error because the open brace was in quotes.
511 self.perform_function_detection( 511 self.perform_function_detection(
512 ['asm(', 512 ['asm(',
513 ' "stmdb sp!, {r1-r3}" "\n"', 513 ' "stmdb sp!, {r1-r3}" "\n"',
514 ');'], 514 ');'],
515 # This isn't a function but it looks like one to our simple 515 # This isn't a function but it looks like one to our simple
516 # algorithm and that is ok. 516 # algorithm and that is ok.
517 {'name': 'asm', 517 {'name': 'asm',
518 'modifiers_and_return_type': '', 518 'modifiers_and_return_type': '',
519 'function_name_start_position': (0, 0), 519 'function_name_start_position': (0, 0),
520 'parameter_start_position': (0, 3), 520 'parameter_start_position': (0, 3),
521 'parameter_end_position': (2, 1), 521 'parameter_end_position': (2, 1),
522 'body_start_position': (2, 1), 522 'body_start_position': (2, 1),
523 'end_position': (2, 2), 523 'end_position': (2, 2),
(...skipping 776 matching lines...) Expand 10 before | Expand all | Expand 10 after
1300 ' [readability/multiline_comment] [5]') 1300 ' [readability/multiline_comment] [5]')
1301 1301
1302 # Test suspicious usage of "if" like this: 1302 # Test suspicious usage of "if" like this:
1303 # if (a == b) { 1303 # if (a == b) {
1304 # DoSomething(); 1304 # DoSomething();
1305 # } if (a == c) { // Should be "else if". 1305 # } if (a == c) { // Should be "else if".
1306 # DoSomething(); // This gets called twice if a == b && a == c. 1306 # DoSomething(); // This gets called twice if a == b && a == c.
1307 # } 1307 # }
1308 def test_suspicious_usage_of_if(self): 1308 def test_suspicious_usage_of_if(self):
1309 self.assert_lint( 1309 self.assert_lint(
1310 ' if (a == b) {', 1310 ' if (a == b) {',
1311 '') 1311 '')
1312 self.assert_lint( 1312 self.assert_lint(
1313 ' } if (a == b) {', 1313 ' } if (a == b) {',
1314 'Did you mean "else if"? If not, start a new line for "if".' 1314 'Did you mean "else if"? If not, start a new line for "if".'
1315 ' [readability/braces] [4]') 1315 ' [readability/braces] [4]')
1316 1316
1317 # Test suspicious usage of memset. Specifically, a 0 1317 # Test suspicious usage of memset. Specifically, a 0
1318 # as the final argument is almost certainly an error. 1318 # as the final argument is almost certainly an error.
1319 def test_suspicious_usage_of_memset(self): 1319 def test_suspicious_usage_of_memset(self):
1320 # Normal use is okay. 1320 # Normal use is okay.
1321 self.assert_lint( 1321 self.assert_lint(
1322 ' memset(buf, 0, sizeof(buf))', 1322 ' memset(buf, 0, sizeof(buf))',
1323 '') 1323 '')
1324 1324
1325 # A 0 as the final argument is almost certainly an error. 1325 # A 0 as the final argument is almost certainly an error.
1326 self.assert_lint( 1326 self.assert_lint(
1327 ' memset(buf, sizeof(buf), 0)', 1327 ' memset(buf, sizeof(buf), 0)',
1328 'Did you mean "memset(buf, 0, sizeof(buf))"?' 1328 'Did you mean "memset(buf, 0, sizeof(buf))"?'
1329 ' [runtime/memset] [4]') 1329 ' [runtime/memset] [4]')
1330 self.assert_lint( 1330 self.assert_lint(
1331 ' memset(buf, xsize * ysize, 0)', 1331 ' memset(buf, xsize * ysize, 0)',
1332 'Did you mean "memset(buf, 0, xsize * ysize)"?' 1332 'Did you mean "memset(buf, 0, xsize * ysize)"?'
1333 ' [runtime/memset] [4]') 1333 ' [runtime/memset] [4]')
1334 1334
1335 # There is legitimate test code that uses this form. 1335 # There is legitimate test code that uses this form.
1336 # This is okay since the second argument is a literal. 1336 # This is okay since the second argument is a literal.
1337 self.assert_lint( 1337 self.assert_lint(
1338 " memset(buf, 'y', 0)", 1338 " memset(buf, 'y', 0)",
1339 '') 1339 '')
1340 self.assert_lint( 1340 self.assert_lint(
1341 ' memset(buf, 4, 0)', 1341 ' memset(buf, 4, 0)',
1342 '') 1342 '')
1343 self.assert_lint( 1343 self.assert_lint(
1344 ' memset(buf, -1, 0)', 1344 ' memset(buf, -1, 0)',
1345 '') 1345 '')
1346 self.assert_lint( 1346 self.assert_lint(
1347 ' memset(buf, 0xF1, 0)', 1347 ' memset(buf, 0xF1, 0)',
1348 '') 1348 '')
1349 self.assert_lint( 1349 self.assert_lint(
1350 ' memset(buf, 0xcd, 0)', 1350 ' memset(buf, 0xcd, 0)',
1351 '') 1351 '')
1352 1352
1353 def test_check_posix_threading(self): 1353 def test_check_posix_threading(self):
1354 self.assert_lint('sctime_r()', '') 1354 self.assert_lint('sctime_r()', '')
1355 self.assert_lint('strtok_r()', '') 1355 self.assert_lint('strtok_r()', '')
1356 self.assert_lint(' strtok_r(foo, ba, r)', '') 1356 self.assert_lint(' strtok_r(foo, ba, r)', '')
1357 self.assert_lint('brand()', '') 1357 self.assert_lint('brand()', '')
1358 self.assert_lint('_rand()', '') 1358 self.assert_lint('_rand()', '')
1359 self.assert_lint('.rand()', '') 1359 self.assert_lint('.rand()', '')
1360 self.assert_lint('>rand()', '') 1360 self.assert_lint('>rand()', '')
1361 self.assert_lint('rand()', 1361 self.assert_lint('rand()',
1362 'Consider using rand_r(...) instead of rand(...)' 1362 'Consider using rand_r(...) instead of rand(...)'
1363 ' for improved thread safety.' 1363 ' for improved thread safety.'
1364 ' [runtime/threadsafe_fn] [2]') 1364 ' [runtime/threadsafe_fn] [2]')
1365 self.assert_lint('strtok()', 1365 self.assert_lint('strtok()',
1366 'Consider using strtok_r(...) ' 1366 'Consider using strtok_r(...) '
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
1550 self.assert_lint('CHECK(CreateTestFile(dir, (1 >> 20)));', '') 1550 self.assert_lint('CHECK(CreateTestFile(dir, (1 >> 20)));', '')
1551 1551
1552 self.assert_lint('CHECK(x<42)', 1552 self.assert_lint('CHECK(x<42)',
1553 'Consider using CHECK_LT instead of CHECK(a < b)' 1553 'Consider using CHECK_LT instead of CHECK(a < b)'
1554 ' [readability/check] [2]') 1554 ' [readability/check] [2]')
1555 self.assert_lint('CHECK(x>42)', 1555 self.assert_lint('CHECK(x>42)',
1556 'Consider using CHECK_GT instead of CHECK(a > b)' 1556 'Consider using CHECK_GT instead of CHECK(a > b)'
1557 ' [readability/check] [2]') 1557 ' [readability/check] [2]')
1558 1558
1559 self.assert_lint( 1559 self.assert_lint(
1560 ' EXPECT_TRUE(42 < x) // Random comment.', 1560 ' EXPECT_TRUE(42 < x) // Random comment.',
1561 'Consider using EXPECT_LT instead of EXPECT_TRUE(a < b)' 1561 'Consider using EXPECT_LT instead of EXPECT_TRUE(a < b)'
1562 ' [readability/check] [2]') 1562 ' [readability/check] [2]')
1563 self.assert_lint( 1563 self.assert_lint(
1564 'EXPECT_TRUE( 42 < x )', 1564 'EXPECT_TRUE( 42 < x )',
1565 'Consider using EXPECT_LT instead of EXPECT_TRUE(a < b)' 1565 'Consider using EXPECT_LT instead of EXPECT_TRUE(a < b)'
1566 ' [readability/check] [2]') 1566 ' [readability/check] [2]')
1567 self.assert_lint( 1567 self.assert_lint(
1568 'CHECK("foo" == "foo")', 1568 'CHECK("foo" == "foo")',
1569 'Consider using CHECK_EQ instead of CHECK(a == b)' 1569 'Consider using CHECK_EQ instead of CHECK(a == b)'
1570 ' [readability/check] [2]') 1570 ' [readability/check] [2]')
1571 1571
1572 self.assert_lint('CHECK_EQ("foo", "foo")', '') 1572 self.assert_lint('CHECK_EQ("foo", "foo")', '')
1573 1573
1574 def test_check_deprecated_macros(self): 1574 def test_check_deprecated_macros(self):
1575 self.assert_lint('ASSERT(foo)', 'ASSERT is deprecated. Use DCHECK or ' 1575 self.assert_lint('ASSERT(foo)', 'ASSERT is deprecated. Use DCHECK or '
1576 'its variants instead. [build/deprecated] [5]') 1576 'its variants instead. [build/deprecated] [5]')
1577 self.assert_lint(' ASSERT_UNUSED(foo, foo)', 'ASSERT_UNUSED is ' 1577 self.assert_lint(' ASSERT_UNUSED(foo, foo)', 'ASSERT_UNUSED is '
1578 'deprecated. Use DCHECK or its variants instead. ' 1578 'deprecated. Use DCHECK or its variants instead. '
1579 '[build/deprecated] [5]') 1579 '[build/deprecated] [5]')
1580 self.assert_lint('ASSERT_NOT_REACHED()', 'ASSERT_NOT_REACHED is ' 1580 self.assert_lint('ASSERT_NOT_REACHED()', 'ASSERT_NOT_REACHED is '
1581 'deprecated. Use NOTREACHED instead. ' 1581 'deprecated. Use NOTREACHED instead. '
1582 '[build/deprecated] [5]') 1582 '[build/deprecated] [5]')
1583 self.assert_lint('ASSERT_WITH_SECURITY_IMPLICATION(foo)', 1583 self.assert_lint('ASSERT_WITH_SECURITY_IMPLICATION(foo)',
1584 'ASSERT_WITH_SECURITY_IMPLICATION is deprecated. Use ' 1584 'ASSERT_WITH_SECURITY_IMPLICATION is deprecated. Use '
1585 'SECURITY_DCHECK instead. [build/deprecated] [5]') 1585 'SECURITY_DCHECK instead. [build/deprecated] [5]')
1586 self.assert_lint('WTF_LOG(foo)', 'WTF_LOG is deprecated. Use DVLOG ' 1586 self.assert_lint('WTF_LOG(foo)', 'WTF_LOG is deprecated. Use DVLOG '
1587 'instead. [build/deprecated] [5]') 1587 'instead. [build/deprecated] [5]')
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1620 self.assert_lint('string Foo::bar;', 1620 self.assert_lint('string Foo::bar;',
1621 'For a static/global string constant, use a C style ' 1621 'For a static/global string constant, use a C style '
1622 'string instead: "char Foo::bar[]".' 1622 'string instead: "char Foo::bar[]".'
1623 ' [runtime/string] [4]') 1623 ' [runtime/string] [4]')
1624 # Rare case. 1624 # Rare case.
1625 self.assert_lint('string foo("foobar");', 1625 self.assert_lint('string foo("foobar");',
1626 'For a static/global string constant, use a C style ' 1626 'For a static/global string constant, use a C style '
1627 'string instead: "char foo[]".' 1627 'string instead: "char foo[]".'
1628 ' [runtime/string] [4]') 1628 ' [runtime/string] [4]')
1629 # Should not catch local or member variables. 1629 # Should not catch local or member variables.
1630 self.assert_lint(' string foo', '') 1630 self.assert_lint(' string foo', '')
1631 # Should not catch functions. 1631 # Should not catch functions.
1632 self.assert_lint('string EmptyString() { return ""; }', '') 1632 self.assert_lint('string EmptyString() { return ""; }', '')
1633 self.assert_lint('string EmptyString () { return ""; }', '') 1633 self.assert_lint('string EmptyString () { return ""; }', '')
1634 self.assert_lint('string VeryLongNameFunctionSometimesEndsWith(\n' 1634 self.assert_lint('string VeryLongNameFunctionSometimesEndsWith(\n'
1635 ' VeryLongNameType veryLongNameVariable) { }', '') 1635 ' VeryLongNameType veryLongNameVariable) { }', '')
1636 self.assert_lint('template<>\n' 1636 self.assert_lint('template<>\n'
1637 'string FunctionTemplateSpecialization<SomeType>(\n' 1637 'string FunctionTemplateSpecialization<SomeType>(\n'
1638 ' int x) { return ""; }', '') 1638 ' int x) { return ""; }', '')
1639 self.assert_lint('template<>\n' 1639 self.assert_lint('template<>\n'
1640 'string FunctionTemplateSpecialization<vector<A::B>* >( \n' 1640 'string FunctionTemplateSpecialization<vector<A::B>* >( \n'
1641 ' int x) { return ""; }', '') 1641 ' int x) { return ""; }', '')
1642 1642
1643 # should not catch methods of template classes. 1643 # should not catch methods of template classes.
1644 self.assert_lint('string Class<Type>::Method() const\n' 1644 self.assert_lint('string Class<Type>::Method() const\n'
1645 '{\n' 1645 '{\n'
1646 ' return "";\n' 1646 ' return "";\n'
1647 '}\n', '') 1647 '}\n', '')
1648 self.assert_lint('string Class<Type>::Method(\n' 1648 self.assert_lint('string Class<Type>::Method(\n'
1649 ' int arg) const\n' 1649 ' int arg) const\n'
1650 '{\n' 1650 '{\n'
1651 ' return "";\n' 1651 ' return "";\n'
1652 '}\n', '') 1652 '}\n', '')
1653 1653
1654 def test_no_spaces_in_function_calls(self): 1654 def test_no_spaces_in_function_calls(self):
1655 self.assert_lint('TellStory(1, 3);', 1655 self.assert_lint('TellStory(1, 3);',
1656 '') 1656 '')
1657 self.assert_lint('TellStory(1 /* wolf */, 3 /* pigs */);', 1657 self.assert_lint('TellStory(1 /* wolf */, 3 /* pigs */);',
1658 '') 1658 '')
1659 self.assert_multi_line_lint('#endif\n );', 1659 self.assert_multi_line_lint('#endif\n );',
1660 '') 1660 '')
1661 1661
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1719 self.assert_multi_line_lint( 1719 self.assert_multi_line_lint(
1720 '''\ 1720 '''\
1721 struct Foo* 1721 struct Foo*
1722 foo = NewFoo();''', 1722 foo = NewFoo();''',
1723 '') 1723 '')
1724 # Here is an example where the linter gets confused, even though 1724 # Here is an example where the linter gets confused, even though
1725 # the code doesn't violate the style guide. 1725 # the code doesn't violate the style guide.
1726 self.assert_multi_line_lint( 1726 self.assert_multi_line_lint(
1727 'class Foo\n' 1727 'class Foo\n'
1728 '#ifdef DERIVE_FROM_GOO\n' 1728 '#ifdef DERIVE_FROM_GOO\n'
1729 ' : public Goo {\n' 1729 ' : public Goo {\n'
1730 '#else\n' 1730 '#else\n'
1731 ' : public Hoo {\n' 1731 ' : public Hoo {\n'
1732 '#endif\n' 1732 '#endif\n'
1733 '};', 1733 '};',
1734 'Failed to find complete declaration of class Foo' 1734 'Failed to find complete declaration of class Foo'
1735 ' [build/class] [5]') 1735 ' [build/class] [5]')
1736 1736
1737 def test_build_end_comment(self): 1737 def test_build_end_comment(self):
1738 # The crosstool compiler we currently use will fail to compile the 1738 # The crosstool compiler we currently use will fail to compile the
1739 # code in this test, so we might consider removing the lint check. 1739 # code in this test, so we might consider removing the lint check.
1740 self.assert_lint('#endif Not a comment', 1740 self.assert_lint('#endif Not a comment',
1741 'Uncommented text after #endif is non-standard.' 1741 'Uncommented text after #endif is non-standard.'
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
2108 'MyClass', False) 2108 'MyClass', False)
2109 build_test_case([('unsigned', 'm_unsignedMember', 4), ('unsigned', 'm_an otherUnsigned', 3)], 2109 build_test_case([('unsigned', 'm_unsignedMember', 4), ('unsigned', 'm_an otherUnsigned', 3)],
2110 'MyClass', False) 2110 'MyClass', False)
2111 2111
2112 build_test_case([('bool', 'm_boolMember', 4), ('bool', 'm_anotherbool', 3), 2112 build_test_case([('bool', 'm_boolMember', 4), ('bool', 'm_anotherbool', 3),
2113 ('bool', 'm_moreBool', 1), ('bool', 'm_lastBool', 1), 2113 ('bool', 'm_moreBool', 1), ('bool', 'm_lastBool', 1),
2114 ('unsigned int', 'm_tokenUnsigned', 4)], 2114 ('unsigned int', 'm_tokenUnsigned', 4)],
2115 'MyClass', True, ['Omit int when using unsigned [runtim e/unsigned] [1]']) 2115 'MyClass', True, ['Omit int when using unsigned [runtim e/unsigned] [1]'])
2116 2116
2117 self.assert_multi_line_lint('class NoProblemsHere {\n' 2117 self.assert_multi_line_lint('class NoProblemsHere {\n'
2118 ' bool m_boolMember;\n' 2118 ' bool m_boolMember;\n'
2119 ' unsigned m_unsignedMember;\n' 2119 ' unsigned m_unsignedMember;\n'
2120 ' unsigned m_bitField1 : 1;\n' 2120 ' unsigned m_bitField1 : 1;\n'
2121 ' unsigned m_bitField4 : 4;\n' 2121 ' unsigned m_bitField4 : 4;\n'
2122 '}\n', '') 2122 '}\n', '')
2123 2123
2124 # Bitfields which are not declared unsigned or bool will generate a warning. 2124 # Bitfields which are not declared unsigned or bool will generate a warning.
2125 def test_unsigned_bool_bitfields(self): 2125 def test_unsigned_bool_bitfields(self):
2126 def errmsg(member, name, bit_type): 2126 def errmsg(member, name, bit_type):
2127 return ('Member %s of class %s defined as a bitfield of type %s. ' 2127 return ('Member %s of class %s defined as a bitfield of type %s. '
2128 'Please declare all bitfields as unsigned. [runtime/bitfiel ds] [4]' 2128 'Please declare all bitfields as unsigned. [runtime/bitfiel ds] [4]'
2129 % (member, name, bit_type)) 2129 % (member, name, bit_type))
2130 2130
2131 def warning_bitfield_test(member, name, bit_type, bits): 2131 def warning_bitfield_test(member, name, bit_type, bits):
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after
2657 def assert_function_length_check_above_error_level(self, error_level): 2657 def assert_function_length_check_above_error_level(self, error_level):
2658 """Generate and check function just above the trigger level for --v sett ing. 2658 """Generate and check function just above the trigger level for --v sett ing.
2659 2659
2660 Args: 2660 Args:
2661 error_level: --v setting for cpp_style. 2661 error_level: --v setting for cpp_style.
2662 """ 2662 """
2663 self.assert_function_length_check_definition(self.trigger_lines(error_le vel) + 1, 2663 self.assert_function_length_check_definition(self.trigger_lines(error_le vel) + 1,
2664 error_level) 2664 error_level)
2665 2665
2666 def function_body(self, number_of_lines): 2666 def function_body(self, number_of_lines):
2667 return ' {\n' + ' this_is_just_a_test();\n' * number_of_lines + '}' 2667 return ' {\n' + ' this_is_just_a_test();\n' * number_of_lines + '}'
2668 2668
2669 def function_body_with_blank_lines(self, number_of_lines): 2669 def function_body_with_blank_lines(self, number_of_lines):
2670 return ' {\n' + ' this_is_just_a_test();\n\n' * number_of_lines + '}' 2670 return ' {\n' + ' this_is_just_a_test();\n\n' * number_of_lines + '}'
2671 2671
2672 def function_body_with_no_lints(self, number_of_lines): 2672 def function_body_with_no_lints(self, number_of_lines):
2673 return ' {\n' + ' this_is_just_a_test(); // NOLINT\n' * number_of_li nes + '}' 2673 return ' {\n' + ' this_is_just_a_test(); // NOLINT\n' * number_of_line s + '}'
2674 2674
2675 # Test line length checks. 2675 # Test line length checks.
2676 def test_function_length_check_declaration(self): 2676 def test_function_length_check_declaration(self):
2677 self.assert_function_lengths_check( 2677 self.assert_function_lengths_check(
2678 'void test();', # Not a function definition 2678 'void test();', # Not a function definition
2679 '') 2679 '')
2680 2680
2681 def test_function_length_check_declaration_with_block_following(self): 2681 def test_function_length_check_declaration_with_block_following(self):
2682 self.assert_function_lengths_check( 2682 self.assert_function_lengths_check(
2683 ('void test();\n' 2683 ('void test();\n'
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
2730 def test_function_length_check_definition_at_severity1(self): 2730 def test_function_length_check_definition_at_severity1(self):
2731 self.assert_function_length_check_definition_ok(self.trigger_lines(1)) 2731 self.assert_function_length_check_definition_ok(self.trigger_lines(1))
2732 2732
2733 def test_function_length_check_definition_above_severity1(self): 2733 def test_function_length_check_definition_above_severity1(self):
2734 self.assert_function_length_check_above_error_level(1) 2734 self.assert_function_length_check_above_error_level(1)
2735 2735
2736 def test_function_length_check_definition_severity1_plus_indented(self): 2736 def test_function_length_check_definition_severity1_plus_indented(self):
2737 error_level = 1 2737 error_level = 1
2738 error_lines = self.trigger_lines(error_level) + 1 2738 error_lines = self.trigger_lines(error_level) + 1
2739 trigger_level = self.trigger_lines(self.min_confidence) 2739 trigger_level = self.trigger_lines(self.min_confidence)
2740 indent_spaces = ' ' 2740 indent_spaces = ' '
2741 self.assert_function_lengths_check( 2741 self.assert_function_lengths_check(
2742 re.sub(r'(?m)^(.)', indent_spaces + r'\1', 2742 re.sub(r'(?m)^(.)', indent_spaces + r'\1',
2743 'void test_indent(int x)\n' + self.function_body(error_lines) ), 2743 'void test_indent(int x)\n' + self.function_body(error_lines) ),
2744 ('Small and focused functions are preferred: ' 2744 ('Small and focused functions are preferred: '
2745 'test_indent() has %d non-comment lines ' 2745 'test_indent() has %d non-comment lines '
2746 '(error triggered by exceeding %d lines).' 2746 '(error triggered by exceeding %d lines).'
2747 ' [readability/fn_size] [%d]') 2747 ' [readability/fn_size] [%d]')
2748 % (error_lines, trigger_level, error_level)) 2748 % (error_lines, trigger_level, error_level))
2749 2749
2750 def test_function_length_check_definition_severity1_plus_blanks(self): 2750 def test_function_length_check_definition_severity1_plus_blanks(self):
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
2915 2915
2916 self.assert_multi_line_lint( 2916 self.assert_multi_line_lint(
2917 '''\ 2917 '''\
2918 class Foo::Goo { 2918 class Foo::Goo {
2919 virtual ~Goo(); 2919 virtual ~Goo();
2920 virtual void goo(); 2920 virtual void goo();
2921 };''', 2921 };''',
2922 '') 2922 '')
2923 self.assert_multi_line_lint( 2923 self.assert_multi_line_lint(
2924 'class MyClass {\n' 2924 'class MyClass {\n'
2925 ' int getIntValue() { DCHECK(m_ptr); return *m_ptr; }\n' 2925 ' int getIntValue() { DCHECK(m_ptr); return *m_ptr; }\n'
2926 '};\n', 2926 '};\n',
2927 '') 2927 '')
2928 2928
2929 self.assert_multi_line_lint( 2929 self.assert_multi_line_lint(
2930 '''\ 2930 '''\
2931 class Qualified::Goo : public Foo { 2931 class Qualified::Goo : public Foo {
2932 virtual void goo(); 2932 virtual void goo();
2933 };''', 2933 };''',
2934 '') 2934 '')
2935 2935
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
3065 code: C++ source code expected to generate a warning message. 3065 code: C++ source code expected to generate a warning message.
3066 expected_message: Message expected to be generated by the C++ code. 3066 expected_message: Message expected to be generated by the C++ code.
3067 """ 3067 """
3068 self.assertEqual(expected_message, 3068 self.assertEqual(expected_message,
3069 self.perform_pass_ptr_check(code)) 3069 self.perform_pass_ptr_check(code))
3070 3070
3071 def test_pass_ref_ptr_in_function(self): 3071 def test_pass_ref_ptr_in_function(self):
3072 self.assert_pass_ptr_check( 3072 self.assert_pass_ptr_check(
3073 'int myFunction()\n' 3073 'int myFunction()\n'
3074 '{\n' 3074 '{\n'
3075 ' PassRefPtr<Type1> variable = variable2;\n' 3075 ' PassRefPtr<Type1> variable = variable2;\n'
3076 '}', 3076 '}',
3077 'Local variables should never be PassRefPtr (see ' 3077 'Local variables should never be PassRefPtr (see '
3078 'http://webkit.org/coding/RefPtr.html). [readability/pass_ptr] [5]' ) 3078 'http://webkit.org/coding/RefPtr.html). [readability/pass_ptr] [5]' )
3079 3079
3080 def test_pass_own_ptr_in_function(self): 3080 def test_pass_own_ptr_in_function(self):
3081 self.assert_pass_ptr_check( 3081 self.assert_pass_ptr_check(
3082 'int myFunction()\n' 3082 'int myFunction()\n'
3083 '{\n' 3083 '{\n'
3084 ' PassOwnPtr<Type1> variable = variable2;\n' 3084 ' PassOwnPtr<Type1> variable = variable2;\n'
3085 '}', 3085 '}',
3086 'Local variables should never be PassOwnPtr (see ' 3086 'Local variables should never be PassOwnPtr (see '
3087 'http://webkit.org/coding/RefPtr.html). [readability/pass_ptr] [5]' ) 3087 'http://webkit.org/coding/RefPtr.html). [readability/pass_ptr] [5]' )
3088 3088
3089 def test_pass_other_type_ptr_in_function(self): 3089 def test_pass_other_type_ptr_in_function(self):
3090 self.assert_pass_ptr_check( 3090 self.assert_pass_ptr_check(
3091 'int myFunction()\n' 3091 'int myFunction()\n'
3092 '{\n' 3092 '{\n'
3093 ' PassOtherTypePtr<Type1> variable;\n' 3093 ' PassOtherTypePtr<Type1> variable;\n'
3094 '}', 3094 '}',
3095 'Local variables should never be PassOtherTypePtr (see ' 3095 'Local variables should never be PassOtherTypePtr (see '
3096 'http://webkit.org/coding/RefPtr.html). [readability/pass_ptr] [5]' ) 3096 'http://webkit.org/coding/RefPtr.html). [readability/pass_ptr] [5]' )
3097 3097
3098 def test_pass_ref_ptr_return_value(self): 3098 def test_pass_ref_ptr_return_value(self):
3099 self.assert_pass_ptr_check( 3099 self.assert_pass_ptr_check(
3100 'PassRefPtr<Type1>\n' 3100 'PassRefPtr<Type1>\n'
3101 'myFunction(int)\n' 3101 'myFunction(int)\n'
3102 '{\n' 3102 '{\n'
3103 '}', 3103 '}',
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
3159 '') 3159 '')
3160 self.assert_pass_ptr_check( 3160 self.assert_pass_ptr_check(
3161 'int myFunction(OwnPtr<Type1>& simple)\n' 3161 'int myFunction(OwnPtr<Type1>& simple)\n'
3162 '{\n' 3162 '{\n'
3163 '}', 3163 '}',
3164 '') 3164 '')
3165 3165
3166 def test_ref_ptr_member_variable(self): 3166 def test_ref_ptr_member_variable(self):
3167 self.assert_pass_ptr_check( 3167 self.assert_pass_ptr_check(
3168 'class Foo {' 3168 'class Foo {'
3169 ' RefPtr<Type1> m_other;\n' 3169 ' RefPtr<Type1> m_other;\n'
3170 '};\n', 3170 '};\n',
3171 '') 3171 '')
3172 3172
3173 3173
3174 class LeakyPatternTest(CppStyleTestBase): 3174 class LeakyPatternTest(CppStyleTestBase):
3175 3175
3176 def assert_leaky_pattern_check(self, code, expected_message): 3176 def assert_leaky_pattern_check(self, code, expected_message):
3177 """Check warnings for leaky patterns are as expected. 3177 """Check warnings for leaky patterns are as expected.
3178 3178
3179 Args: 3179 Args:
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
3223 class WebKitStyleTest(CppStyleTestBase): 3223 class WebKitStyleTest(CppStyleTestBase):
3224 3224
3225 # for https://www.chromium.org/blink/coding-style 3225 # for https://www.chromium.org/blink/coding-style
3226 3226
3227 def test_line_breaking(self): 3227 def test_line_breaking(self):
3228 # 2. An else statement should go on the same line as a preceding 3228 # 2. An else statement should go on the same line as a preceding
3229 # close brace if one is present, else it should line up with the 3229 # close brace if one is present, else it should line up with the
3230 # if statement. 3230 # if statement.
3231 self.assert_multi_line_lint( 3231 self.assert_multi_line_lint(
3232 'if (condition) {\n' 3232 'if (condition) {\n'
3233 ' doSomething();\n' 3233 ' doSomething();\n'
3234 ' doSomethingAgain();\n' 3234 ' doSomethingAgain();\n'
3235 '} else {\n' 3235 '} else {\n'
3236 ' doSomethingElse();\n' 3236 ' doSomethingElse();\n'
3237 ' doSomethingElseAgain();\n' 3237 ' doSomethingElseAgain();\n'
3238 '}\n', 3238 '}\n',
3239 '') 3239 '')
3240 self.assert_multi_line_lint( 3240 self.assert_multi_line_lint(
3241 'if (condition)\n' 3241 'if (condition)\n'
3242 ' doSomething();\n' 3242 ' doSomething();\n'
3243 'else\n' 3243 'else\n'
3244 ' doSomethingElse();\n', 3244 ' doSomethingElse();\n',
3245 '') 3245 '')
3246 self.assert_multi_line_lint( 3246 self.assert_multi_line_lint(
3247 'if (condition) {\n' 3247 'if (condition) {\n'
3248 ' doSomething();\n' 3248 ' doSomething();\n'
3249 '} else {\n' 3249 '} else {\n'
3250 ' doSomethingElse();\n' 3250 ' doSomethingElse();\n'
3251 ' doSomethingElseAgain();\n' 3251 ' doSomethingElseAgain();\n'
3252 '}\n', 3252 '}\n',
3253 '') 3253 '')
3254 self.assert_multi_line_lint( 3254 self.assert_multi_line_lint(
3255 '#define TEST_ASSERT(expression) do { if (!(expression)) { ' 3255 '#define TEST_ASSERT(expression) do { if (!(expression)) { '
3256 'TestsController::shared().testFailed(__FILE__, __LINE__, #expressio n); ' 3256 'TestsController::shared().testFailed(__FILE__, __LINE__, #expressio n); '
3257 'return; } } while (0)\n', 3257 'return; } } while (0)\n',
3258 '') 3258 '')
3259 # FIXME: currently we only check first conditional, so we cannot detect errors in next ones. 3259 # FIXME: currently we only check first conditional, so we cannot detect errors in next ones.
3260 self.assert_multi_line_lint( 3260 self.assert_multi_line_lint(
3261 'WTF_MAKE_NONCOPYABLE(ClassName); WTF_MAKE_FAST_ALLOCATED;\n', 3261 'WTF_MAKE_NONCOPYABLE(ClassName); WTF_MAKE_FAST_ALLOCATED;\n',
3262 '') 3262 '')
3263 self.assert_multi_line_lint( 3263 self.assert_multi_line_lint(
3264 'if (condition) doSomething(); else {\n' 3264 'if (condition) doSomething(); else {\n'
3265 ' doSomethingElse();\n' 3265 ' doSomethingElse();\n'
3266 '}\n', 3266 '}\n',
3267 'If one part of an if-else statement uses curly braces, the other pa rt must too. [whitespace/braces] [4]') 3267 'If one part of an if-else statement uses curly braces, the other pa rt must too. [whitespace/braces] [4]')
3268 self.assert_multi_line_lint( 3268 self.assert_multi_line_lint(
3269 'void func()\n' 3269 'void func()\n'
3270 '{\n' 3270 '{\n'
3271 ' while (condition) { }\n' 3271 ' while (condition) { }\n'
3272 ' return 0;\n' 3272 ' return 0;\n'
3273 '}\n', 3273 '}\n',
3274 '') 3274 '')
3275 3275
3276 # 3. An else if statement should be written as an if statement 3276 # 3. An else if statement should be written as an if statement
3277 # when the prior if concludes with a return statement. 3277 # when the prior if concludes with a return statement.
3278 self.assert_multi_line_lint( 3278 self.assert_multi_line_lint(
3279 'if (motivated) {\n' 3279 'if (motivated) {\n'
3280 ' if (liquid)\n' 3280 ' if (liquid)\n'
3281 ' return money;\n' 3281 ' return money;\n'
3282 '} else if (tired) {\n' 3282 '} else if (tired) {\n'
3283 ' break;\n' 3283 ' break;\n'
3284 '}', 3284 '}',
3285 '') 3285 '')
3286 self.assert_multi_line_lint( 3286 self.assert_multi_line_lint(
3287 'if (condition)\n' 3287 'if (condition)\n'
3288 ' doSomething();\n' 3288 ' doSomething();\n'
3289 'else if (otherCondition)\n' 3289 'else if (otherCondition)\n'
3290 ' doSomethingElse();\n', 3290 ' doSomethingElse();\n',
3291 '') 3291 '')
3292 self.assert_multi_line_lint( 3292 self.assert_multi_line_lint(
3293 'if (condition)\n' 3293 'if (condition)\n'
3294 ' doSomething();\n' 3294 ' doSomething();\n'
3295 'else\n' 3295 'else\n'
3296 ' doSomethingElse();\n', 3296 ' doSomethingElse();\n',
3297 '') 3297 '')
3298 self.assert_multi_line_lint( 3298 self.assert_multi_line_lint(
3299 'if (condition)\n' 3299 'if (condition)\n'
3300 ' returnValue = foo;\n' 3300 ' returnValue = foo;\n'
3301 'else if (otherCondition)\n' 3301 'else if (otherCondition)\n'
3302 ' returnValue = bar;\n', 3302 ' returnValue = bar;\n',
3303 '') 3303 '')
3304 self.assert_multi_line_lint( 3304 self.assert_multi_line_lint(
3305 'if (condition)\n' 3305 'if (condition)\n'
3306 ' returnValue = foo;\n' 3306 ' returnValue = foo;\n'
3307 'else\n' 3307 'else\n'
3308 ' returnValue = bar;\n', 3308 ' returnValue = bar;\n',
3309 '') 3309 '')
3310 self.assert_multi_line_lint( 3310 self.assert_multi_line_lint(
3311 'if (condition)\n' 3311 'if (condition)\n'
3312 ' doSomething();\n' 3312 ' doSomething();\n'
3313 'else if (liquid)\n' 3313 'else if (liquid)\n'
3314 ' return money;\n' 3314 ' return money;\n'
3315 'else if (broke)\n' 3315 'else if (broke)\n'
3316 ' return favor;\n' 3316 ' return favor;\n'
3317 'else\n' 3317 'else\n'
3318 ' sleep(28800);\n', 3318 ' sleep(28800);\n',
3319 '') 3319 '')
3320 self.assert_multi_line_lint( 3320 self.assert_multi_line_lint(
3321 'if (liquid) {\n' 3321 'if (liquid) {\n'
3322 ' prepare();\n' 3322 ' prepare();\n'
3323 ' return money;\n' 3323 ' return money;\n'
3324 '} else if (greedy) {\n' 3324 '} else if (greedy) {\n'
3325 ' keep();\n' 3325 ' keep();\n'
3326 ' return nothing;\n' 3326 ' return nothing;\n'
3327 '}\n', 3327 '}\n',
3328 'An else if statement should be written as an if statement when the ' 3328 'An else if statement should be written as an if statement when the '
3329 'prior "if" concludes with a return, break, continue or goto stateme nt.' 3329 'prior "if" concludes with a return, break, continue or goto stateme nt.'
3330 ' [readability/control_flow] [4]') 3330 ' [readability/control_flow] [4]')
3331 self.assert_multi_line_lint( 3331 self.assert_multi_line_lint(
3332 ' if (stupid) {\n' 3332 ' if (stupid) {\n'
3333 'infiniteLoop:\n' 3333 'infiniteLoop:\n'
3334 ' goto infiniteLoop;\n' 3334 ' goto infiniteLoop;\n'
3335 ' } else if (evil)\n' 3335 ' } else if (evil)\n'
3336 ' goto hell;\n', 3336 ' goto hell;\n',
3337 ['If one part of an if-else statement uses curly braces, the other p art must too. [whitespace/braces] [4]', 3337 ['If one part of an if-else statement uses curly braces, the other p art must too. [whitespace/braces] [4]',
3338 'An else if statement should be written as an if statement when the ' 3338 'An else if statement should be written as an if statement when the '
3339 'prior "if" concludes with a return, break, continue or goto statem ent.' 3339 'prior "if" concludes with a return, break, continue or goto statem ent.'
3340 ' [readability/control_flow] [4]']) 3340 ' [readability/control_flow] [4]'])
3341 self.assert_multi_line_lint( 3341 self.assert_multi_line_lint(
3342 'if (liquid)\n' 3342 'if (liquid)\n'
3343 '{\n' 3343 '{\n'
3344 ' prepare();\n' 3344 ' prepare();\n'
3345 ' return money;\n' 3345 ' return money;\n'
3346 '}\n' 3346 '}\n'
3347 'else if (greedy)\n' 3347 'else if (greedy)\n'
3348 ' keep();\n', 3348 ' keep();\n',
3349 ['If one part of an if-else statement uses curly braces, the other p art must too. [whitespace/braces] [4]', 3349 ['If one part of an if-else statement uses curly braces, the other p art must too. [whitespace/braces] [4]',
3350 'An else if statement should be written as an if statement when the ' 3350 'An else if statement should be written as an if statement when the '
3351 'prior "if" concludes with a return, break, continue or goto statem ent.' 3351 'prior "if" concludes with a return, break, continue or goto statem ent.'
3352 ' [readability/control_flow] [4]']) 3352 ' [readability/control_flow] [4]'])
3353 self.assert_multi_line_lint( 3353 self.assert_multi_line_lint(
3354 'if (gone)\n' 3354 'if (gone)\n'
3355 ' return;\n' 3355 ' return;\n'
3356 'else if (here)\n' 3356 'else if (here)\n'
3357 ' go();\n', 3357 ' go();\n',
3358 'An else if statement should be written as an if statement when the ' 3358 'An else if statement should be written as an if statement when the '
3359 'prior "if" concludes with a return, break, continue or goto stateme nt.' 3359 'prior "if" concludes with a return, break, continue or goto stateme nt.'
3360 ' [readability/control_flow] [4]') 3360 ' [readability/control_flow] [4]')
3361 self.assert_multi_line_lint( 3361 self.assert_multi_line_lint(
3362 'if (gone)\n' 3362 'if (gone)\n'
3363 ' return;\n' 3363 ' return;\n'
3364 'else\n' 3364 'else\n'
3365 ' go();\n', 3365 ' go();\n',
3366 'An else statement can be removed when the prior "if" concludes ' 3366 'An else statement can be removed when the prior "if" concludes '
3367 'with a return, break, continue or goto statement.' 3367 'with a return, break, continue or goto statement.'
3368 ' [readability/control_flow] [4]') 3368 ' [readability/control_flow] [4]')
3369 self.assert_multi_line_lint( 3369 self.assert_multi_line_lint(
3370 'if (motivated) {\n' 3370 'if (motivated) {\n'
3371 ' prepare();\n' 3371 ' prepare();\n'
3372 ' continue;\n' 3372 ' continue;\n'
3373 '} else {\n' 3373 '} else {\n'
3374 ' cleanUp();\n' 3374 ' cleanUp();\n'
3375 ' break;\n' 3375 ' break;\n'
3376 '}\n', 3376 '}\n',
3377 'An else statement can be removed when the prior "if" concludes ' 3377 'An else statement can be removed when the prior "if" concludes '
3378 'with a return, break, continue or goto statement.' 3378 'with a return, break, continue or goto statement.'
3379 ' [readability/control_flow] [4]') 3379 ' [readability/control_flow] [4]')
3380 self.assert_multi_line_lint( 3380 self.assert_multi_line_lint(
3381 'if (tired)\n' 3381 'if (tired)\n'
3382 ' break;\n' 3382 ' break;\n'
3383 'else {\n' 3383 'else {\n'
3384 ' prepare();\n' 3384 ' prepare();\n'
3385 ' continue;\n' 3385 ' continue;\n'
3386 '}\n', 3386 '}\n',
3387 ['If one part of an if-else statement uses curly braces, the other p art must too. [whitespace/braces] [4]', 3387 ['If one part of an if-else statement uses curly braces, the other p art must too. [whitespace/braces] [4]',
3388 'An else statement can be removed when the prior "if" concludes ' 3388 'An else statement can be removed when the prior "if" concludes '
3389 'with a return, break, continue or goto statement.' 3389 'with a return, break, continue or goto statement.'
3390 ' [readability/control_flow] [4]']) 3390 ' [readability/control_flow] [4]'])
3391 3391
3392 def test_braces(self): 3392 def test_braces(self):
3393 # 3. Curly braces are not required for single-line conditionals and 3393 # 3. Curly braces are not required for single-line conditionals and
3394 # loop bodies, but are required for single-statement bodies that 3394 # loop bodies, but are required for single-statement bodies that
3395 # span multiple lines. 3395 # span multiple lines.
3396 3396
3397 # 3397 #
3398 # Positive tests 3398 # Positive tests
3399 # 3399 #
3400 self.assert_multi_line_lint( 3400 self.assert_multi_line_lint(
3401 'if (condition1)\n' 3401 'if (condition1)\n'
3402 ' statement1();\n' 3402 ' statement1();\n'
3403 'else\n' 3403 'else\n'
3404 ' statement2();\n', 3404 ' statement2();\n',
3405 '') 3405 '')
3406 3406
3407 self.assert_multi_line_lint( 3407 self.assert_multi_line_lint(
3408 'if (condition1)\n' 3408 'if (condition1)\n'
3409 ' statement1();\n' 3409 ' statement1();\n'
3410 'else if (condition2)\n' 3410 'else if (condition2)\n'
3411 ' statement2();\n', 3411 ' statement2();\n',
3412 '') 3412 '')
3413 3413
3414 self.assert_multi_line_lint( 3414 self.assert_multi_line_lint(
3415 'if (condition1)\n' 3415 'if (condition1)\n'
3416 ' statement1();\n' 3416 ' statement1();\n'
3417 'else if (condition2)\n' 3417 'else if (condition2)\n'
3418 ' statement2();\n' 3418 ' statement2();\n'
3419 'else\n' 3419 'else\n'
3420 ' statement3();\n', 3420 ' statement3();\n',
3421 '') 3421 '')
3422 3422
3423 self.assert_multi_line_lint( 3423 self.assert_multi_line_lint(
3424 'for (; foo; bar)\n' 3424 'for (; foo; bar)\n'
3425 ' int foo;\n', 3425 ' int foo;\n',
3426 '') 3426 '')
3427 3427
3428 self.assert_multi_line_lint( 3428 self.assert_multi_line_lint(
3429 'for (; foo; bar) {\n' 3429 'for (; foo; bar) {\n'
3430 ' int foo;\n' 3430 ' int foo;\n'
3431 '}\n', 3431 '}\n',
3432 '') 3432 '')
3433 3433
3434 self.assert_multi_line_lint( 3434 self.assert_multi_line_lint(
3435 'foreach (foo, foos) {\n' 3435 'foreach (foo, foos) {\n'
3436 ' int bar;\n' 3436 ' int bar;\n'
3437 '}\n', 3437 '}\n',
3438 '') 3438 '')
3439 3439
3440 self.assert_multi_line_lint( 3440 self.assert_multi_line_lint(
3441 'foreach (foo, foos)\n' 3441 'foreach (foo, foos)\n'
3442 ' int bar;\n', 3442 ' int bar;\n',
3443 '') 3443 '')
3444 3444
3445 self.assert_multi_line_lint( 3445 self.assert_multi_line_lint(
3446 'while (true) {\n' 3446 'while (true) {\n'
3447 ' int foo;\n' 3447 ' int foo;\n'
3448 '}\n', 3448 '}\n',
3449 '') 3449 '')
3450 3450
3451 self.assert_multi_line_lint( 3451 self.assert_multi_line_lint(
3452 'while (true)\n' 3452 'while (true)\n'
3453 ' int foo;\n', 3453 ' int foo;\n',
3454 '') 3454 '')
3455 3455
3456 self.assert_multi_line_lint( 3456 self.assert_multi_line_lint(
3457 'if (condition1) {\n' 3457 'if (condition1) {\n'
3458 ' statement1();\n' 3458 ' statement1();\n'
3459 '} else {\n' 3459 '} else {\n'
3460 ' statement2();\n' 3460 ' statement2();\n'
3461 '}\n', 3461 '}\n',
3462 '') 3462 '')
3463 3463
3464 self.assert_multi_line_lint( 3464 self.assert_multi_line_lint(
3465 'if (condition1) {\n' 3465 'if (condition1) {\n'
3466 ' statement1();\n' 3466 ' statement1();\n'
3467 '} else if (condition2) {\n' 3467 '} else if (condition2) {\n'
3468 ' statement2();\n' 3468 ' statement2();\n'
3469 '}\n', 3469 '}\n',
3470 '') 3470 '')
3471 3471
3472 self.assert_multi_line_lint( 3472 self.assert_multi_line_lint(
3473 'if (condition1) {\n' 3473 'if (condition1) {\n'
3474 ' statement1();\n' 3474 ' statement1();\n'
3475 '} else if (condition2) {\n' 3475 '} else if (condition2) {\n'
3476 ' statement2();\n' 3476 ' statement2();\n'
3477 '} else {\n' 3477 '} else {\n'
3478 ' statement3();\n' 3478 ' statement3();\n'
3479 '}\n', 3479 '}\n',
3480 '') 3480 '')
3481 3481
3482 self.assert_multi_line_lint( 3482 self.assert_multi_line_lint(
3483 'if (condition1) {\n' 3483 'if (condition1) {\n'
3484 ' statement1();\n' 3484 ' statement1();\n'
3485 ' statement1_2();\n' 3485 ' statement1_2();\n'
3486 '} else if (condition2) {\n' 3486 '} else if (condition2) {\n'
3487 ' statement2();\n' 3487 ' statement2();\n'
3488 ' statement2_2();\n' 3488 ' statement2_2();\n'
3489 '}\n', 3489 '}\n',
3490 '') 3490 '')
3491 3491
3492 self.assert_multi_line_lint( 3492 self.assert_multi_line_lint(
3493 'if (condition1) {\n' 3493 'if (condition1) {\n'
3494 ' statement1();\n' 3494 ' statement1();\n'
3495 ' statement1_2();\n' 3495 ' statement1_2();\n'
3496 '} else if (condition2) {\n' 3496 '} else if (condition2) {\n'
3497 ' statement2();\n' 3497 ' statement2();\n'
3498 ' statement2_2();\n' 3498 ' statement2_2();\n'
3499 '} else {\n' 3499 '} else {\n'
3500 ' statement3();\n' 3500 ' statement3();\n'
3501 ' statement3_2();\n' 3501 ' statement3_2();\n'
3502 '}\n', 3502 '}\n',
3503 '') 3503 '')
3504 3504
3505 # 3505 #
3506 # Negative tests 3506 # Negative tests
3507 # 3507 #
3508 3508
3509 self.assert_multi_line_lint( 3509 self.assert_multi_line_lint(
3510 'if (condition)\n' 3510 'if (condition)\n'
3511 ' doSomething(\n' 3511 ' doSomething(\n'
3512 ' spanningMultipleLines);\n', 3512 ' spanningMultipleLines);\n',
3513 'A conditional or loop body must use braces if the statement is more than one line long. [whitespace/braces] [4]') 3513 'A conditional or loop body must use braces if the statement is more than one line long. [whitespace/braces] [4]')
3514 3514
3515 self.assert_multi_line_lint( 3515 self.assert_multi_line_lint(
3516 'if (condition)\n' 3516 'if (condition)\n'
3517 ' // Single-line comment\n' 3517 ' // Single-line comment\n'
3518 ' doSomething();\n', 3518 ' doSomething();\n',
3519 'A conditional or loop body must use braces if the statement is more than one line long. [whitespace/braces] [4]') 3519 'A conditional or loop body must use braces if the statement is more than one line long. [whitespace/braces] [4]')
3520 3520
3521 self.assert_multi_line_lint( 3521 self.assert_multi_line_lint(
3522 'if (condition1)\n' 3522 'if (condition1)\n'
3523 ' statement1();\n' 3523 ' statement1();\n'
3524 'else if (condition2)\n' 3524 'else if (condition2)\n'
3525 ' // Single-line comment\n' 3525 ' // Single-line comment\n'
3526 ' statement2();\n', 3526 ' statement2();\n',
3527 'A conditional or loop body must use braces if the statement is more than one line long. [whitespace/braces] [4]') 3527 'A conditional or loop body must use braces if the statement is more than one line long. [whitespace/braces] [4]')
3528 3528
3529 self.assert_multi_line_lint( 3529 self.assert_multi_line_lint(
3530 'if (condition1)\n' 3530 'if (condition1)\n'
3531 ' statement1();\n' 3531 ' statement1();\n'
3532 'else if (condition2)\n' 3532 'else if (condition2)\n'
3533 ' statement2();\n' 3533 ' statement2();\n'
3534 'else\n' 3534 'else\n'
3535 ' // Single-line comment\n' 3535 ' // Single-line comment\n'
3536 ' statement3();\n', 3536 ' statement3();\n',
3537 'A conditional or loop body must use braces if the statement is more than one line long. [whitespace/braces] [4]') 3537 'A conditional or loop body must use braces if the statement is more than one line long. [whitespace/braces] [4]')
3538 3538
3539 self.assert_multi_line_lint( 3539 self.assert_multi_line_lint(
3540 'for (; foo; bar)\n' 3540 'for (; foo; bar)\n'
3541 ' // Single-line comment\n' 3541 ' // Single-line comment\n'
3542 ' int foo;\n', 3542 ' int foo;\n',
3543 'A conditional or loop body must use braces if the statement is more than one line long. [whitespace/braces] [4]') 3543 'A conditional or loop body must use braces if the statement is more than one line long. [whitespace/braces] [4]')
3544 3544
3545 self.assert_multi_line_lint( 3545 self.assert_multi_line_lint(
3546 'foreach (foo, foos)\n' 3546 'foreach (foo, foos)\n'
3547 ' // Single-line comment\n' 3547 ' // Single-line comment\n'
3548 ' int bar;\n', 3548 ' int bar;\n',
3549 'A conditional or loop body must use braces if the statement is more than one line long. [whitespace/braces] [4]') 3549 'A conditional or loop body must use braces if the statement is more than one line long. [whitespace/braces] [4]')
3550 3550
3551 self.assert_multi_line_lint( 3551 self.assert_multi_line_lint(
3552 'while (true)\n' 3552 'while (true)\n'
3553 ' // Single-line comment\n' 3553 ' // Single-line comment\n'
3554 ' int foo;\n' 3554 ' int foo;\n'
3555 '\n', 3555 '\n',
3556 'A conditional or loop body must use braces if the statement is more than one line long. [whitespace/braces] [4]') 3556 'A conditional or loop body must use braces if the statement is more than one line long. [whitespace/braces] [4]')
3557 3557
3558 # 4. If one part of an if-else statement uses curly braces, the 3558 # 4. If one part of an if-else statement uses curly braces, the
3559 # other part must too. 3559 # other part must too.
3560 3560
3561 self.assert_multi_line_lint( 3561 self.assert_multi_line_lint(
3562 'if (condition1) {\n' 3562 'if (condition1) {\n'
3563 ' doSomething1();\n' 3563 ' doSomething1();\n'
3564 ' doSomething1_2();\n' 3564 ' doSomething1_2();\n'
3565 '} else if (condition2)\n' 3565 '} else if (condition2)\n'
3566 ' doSomething2();\n' 3566 ' doSomething2();\n'
3567 'else\n' 3567 'else\n'
3568 ' doSomething3();\n', 3568 ' doSomething3();\n',
3569 'If one part of an if-else statement uses curly braces, the other pa rt must too. [whitespace/braces] [4]') 3569 'If one part of an if-else statement uses curly braces, the other pa rt must too. [whitespace/braces] [4]')
3570 3570
3571 self.assert_multi_line_lint( 3571 self.assert_multi_line_lint(
3572 'if (condition1)\n' 3572 'if (condition1)\n'
3573 ' doSomething1();\n' 3573 ' doSomething1();\n'
3574 'else if (condition2) {\n' 3574 'else if (condition2) {\n'
3575 ' doSomething2();\n' 3575 ' doSomething2();\n'
3576 ' doSomething2_2();\n' 3576 ' doSomething2_2();\n'
3577 '} else\n' 3577 '} else\n'
3578 ' doSomething3();\n', 3578 ' doSomething3();\n',
3579 'If one part of an if-else statement uses curly braces, the other pa rt must too. [whitespace/braces] [4]') 3579 'If one part of an if-else statement uses curly braces, the other pa rt must too. [whitespace/braces] [4]')
3580 3580
3581 self.assert_multi_line_lint( 3581 self.assert_multi_line_lint(
3582 'if (condition1) {\n' 3582 'if (condition1) {\n'
3583 ' doSomething1();\n' 3583 ' doSomething1();\n'
3584 '} else if (condition2) {\n' 3584 '} else if (condition2) {\n'
3585 ' doSomething2();\n' 3585 ' doSomething2();\n'
3586 ' doSomething2_2();\n' 3586 ' doSomething2_2();\n'
3587 '} else\n' 3587 '} else\n'
3588 ' doSomething3();\n', 3588 ' doSomething3();\n',
3589 'If one part of an if-else statement uses curly braces, the other pa rt must too. [whitespace/braces] [4]') 3589 'If one part of an if-else statement uses curly braces, the other pa rt must too. [whitespace/braces] [4]')
3590 3590
3591 self.assert_multi_line_lint( 3591 self.assert_multi_line_lint(
3592 'if (condition1)\n' 3592 'if (condition1)\n'
3593 ' doSomething1();\n' 3593 ' doSomething1();\n'
3594 'else if (condition2)\n' 3594 'else if (condition2)\n'
3595 ' doSomething2();\n' 3595 ' doSomething2();\n'
3596 'else {\n' 3596 'else {\n'
3597 ' doSomething3();\n' 3597 ' doSomething3();\n'
3598 ' doSomething3_2();\n' 3598 ' doSomething3_2();\n'
3599 '}\n', 3599 '}\n',
3600 'If one part of an if-else statement uses curly braces, the other pa rt must too. [whitespace/braces] [4]') 3600 'If one part of an if-else statement uses curly braces, the other pa rt must too. [whitespace/braces] [4]')
3601 3601
3602 self.assert_multi_line_lint( 3602 self.assert_multi_line_lint(
3603 'if (condition1) {\n' 3603 'if (condition1) {\n'
3604 ' doSomething1();\n' 3604 ' doSomething1();\n'
3605 ' doSomething1_2();\n' 3605 ' doSomething1_2();\n'
3606 '} else if (condition2)\n' 3606 '} else if (condition2)\n'
3607 ' doSomething2();\n' 3607 ' doSomething2();\n'
3608 'else {\n' 3608 'else {\n'
3609 ' doSomething3();\n' 3609 ' doSomething3();\n'
3610 ' doSomething3_2();\n' 3610 ' doSomething3_2();\n'
3611 '}\n', 3611 '}\n',
3612 'If one part of an if-else statement uses curly braces, the other pa rt must too. [whitespace/braces] [4]') 3612 'If one part of an if-else statement uses curly braces, the other pa rt must too. [whitespace/braces] [4]')
3613 3613
3614 self.assert_multi_line_lint( 3614 self.assert_multi_line_lint(
3615 'if (condition1)\n' 3615 'if (condition1)\n'
3616 ' doSomething1();\n' 3616 ' doSomething1();\n'
3617 'else if (condition2) {\n' 3617 'else if (condition2) {\n'
3618 ' doSomething2();\n' 3618 ' doSomething2();\n'
3619 ' doSomething2_2();\n' 3619 ' doSomething2_2();\n'
3620 '} else {\n' 3620 '} else {\n'
3621 ' doSomething3();\n' 3621 ' doSomething3();\n'
3622 ' doSomething3_2();\n' 3622 ' doSomething3_2();\n'
3623 '}\n', 3623 '}\n',
3624 'If one part of an if-else statement uses curly braces, the other pa rt must too. [whitespace/braces] [4]') 3624 'If one part of an if-else statement uses curly braces, the other pa rt must too. [whitespace/braces] [4]')
3625 3625
3626 # 5. Control clauses without a body should use empty braces. 3626 # 5. Control clauses without a body should use empty braces.
3627 self.assert_multi_line_lint( 3627 self.assert_multi_line_lint(
3628 'for ( ; current; current = current->next) { }\n', 3628 'for ( ; current; current = current->next) { }\n',
3629 '') 3629 '')
3630 self.assert_multi_line_lint( 3630 self.assert_multi_line_lint(
3631 'for ( ; current; current = current->next);\n', 3631 'for ( ; current; current = current->next);\n',
3632 'Semicolon defining empty statement for this loop. Use { } instead. [whitespace/semicolon] [5]') 3632 'Semicolon defining empty statement for this loop. Use { } instead. [whitespace/semicolon] [5]')
(...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after
4259 def test_ne(self): 4259 def test_ne(self):
4260 """Test __ne__ inequality function.""" 4260 """Test __ne__ inequality function."""
4261 checker1 = self._checker() 4261 checker1 = self._checker()
4262 checker2 = self._checker() 4262 checker2 = self._checker()
4263 4263
4264 # != calls __ne__. 4264 # != calls __ne__.
4265 # By default, __ne__ always returns true on different objects. 4265 # By default, __ne__ always returns true on different objects.
4266 # Thus, just check the distinguishing case to verify that the 4266 # Thus, just check the distinguishing case to verify that the
4267 # code defines __ne__. 4267 # code defines __ne__.
4268 self.assertFalse(checker1 != checker2) 4268 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