import os
import random
import re
-import webkitpy.thirdparty.unittest2 as unittest
+import unittest
+
import cpp as cpp_style
from cpp import CppChecker
from ..filter import FilterConfiguration
'int foo() const {',
'Place brace on its own line for function definitions. [whitespace/braces] [4]')
self.assert_multi_line_lint(
- 'int foo() const OVERRIDE {',
+ 'int foo() override {',
'Place brace on its own line for function definitions. [whitespace/braces] [4]')
self.assert_multi_line_lint(
- 'int foo() OVERRIDE {',
+ 'int foo() final {',
'Place brace on its own line for function definitions. [whitespace/braces] [4]')
self.assert_multi_line_lint(
'int foo() const\n'
'}\n',
'')
self.assert_multi_line_lint(
- 'int foo() OVERRIDE\n'
+ 'int foo() override\n'
+ '{\n'
+ '}\n',
+ '')
+ self.assert_multi_line_lint(
+ 'int foo() final\n'
'{\n'
'}\n',
'')
self.assert_lint('a<Foo*> t <<= *b / &c; // Test', '')
self.assert_lint('if (a=b == 1)', 'Missing spaces around = [whitespace/operators] [4]')
self.assert_lint('a = 1<<20', 'Missing spaces around << [whitespace/operators] [3]')
+ self.assert_lint('a = 1>> 20', 'Missing spaces around >> [whitespace/operators] [3]')
+ self.assert_lint('a = 1 >>20', 'Missing spaces around >> [whitespace/operators] [3]')
+ self.assert_lint('a = 1>>20', 'Missing spaces around >> [whitespace/operators] [3]')
+ self.assert_lint('func(OwnPtr<Vector<Foo>>)', '')
+ self.assert_lint('func(OwnPtr<Vector<Foo>> foo)', '')
+ self.assert_lint('func(OwnPtr<HashMap<Foo, Member<Bar>>>)', '')
+ # FIXME: The following test should not show any error.
+ self.assert_lint('func(OwnPtr<HashMap<Foo, Member<Bar\n >>>)',
+ 'Missing spaces around < [whitespace/operators] [3]')
self.assert_lint('if (a = b == 1)', '')
self.assert_lint('a = 1 << 20', '')
self.assert_multi_line_lint('#include <sys/io.h>\n', '')
self.assert_lint('printf("\\"%s // In quotes.")', '')
self.assert_lint('printf("%s", "// In quotes.")', '')
- def test_one_spaces_after_punctuation_in_comments(self):
+ def test_line_ending_in_whitespace(self):
self.assert_lint('int a; // This is a sentence.',
'')
self.assert_lint('int a; // This is a sentence. ',
'Line ends in whitespace. Consider deleting these extra spaces. [whitespace/end_of_line] [4]')
- self.assert_lint('int a; // This is a sentence. This is a another sentence.',
- '')
- self.assert_lint('int a; // This is a sentence. This is a another sentence.',
- 'Should have only a single space after a punctuation in a comment. [whitespace/comments] [5]')
- self.assert_lint('int a; // This is a sentence! This is a another sentence.',
- 'Should have only a single space after a punctuation in a comment. [whitespace/comments] [5]')
- self.assert_lint('int a; // Why did I write this? This is a another sentence.',
- 'Should have only a single space after a punctuation in a comment. [whitespace/comments] [5]')
- self.assert_lint('int a; // Elementary, my dear.',
- 'Should have only a single space after a punctuation in a comment. [whitespace/comments] [5]')
- self.assert_lint('int a; // The following should be clear: Is it?',
- 'Should have only a single space after a punctuation in a comment. [whitespace/comments] [5]')
- self.assert_lint('int a; // Look at the follow semicolon; I hope this gives an error.',
- 'Should have only a single space after a punctuation in a comment. [whitespace/comments] [5]')
def test_space_after_comment_marker(self):
self.assert_lint('//', '')
' [build/header_guard] [5]'),
error_collector.result_list())
+ # Verify that the Chromium-style header guard is allowed as well.
+ error_collector = ErrorCollector(self.assertTrue, header_guard_filter)
+ self.process_file_data('Source/foo/testname.h', 'h',
+ ['#ifndef BLINK_FOO_TESTNAME_H_',
+ '#define BLINK_FOO_TESTNAME_H_'],
+ error_collector)
+ self.assertEqual(0, len(error_collector.result_list()),
+ error_collector.result_list())
+
def test_build_printf_format(self):
self.assert_lint(
r'printf("\%%d", value);',
# false. Objective-C BOOL values should be written as YES and NO.
# FIXME: Implement this.
- # 3. Tests for true/false, null/non-null, and zero/non-zero should
- # all be done without equality comparisons.
- self.assert_lint(
- 'if (count == 0)',
- 'Tests for true/false, null/non-null, and zero/non-zero should all be done without equality comparisons.'
- ' [readability/comparison_to_zero] [5]')
+ # 3. Tests for true/false and null/non-null should be done without
+ # equality comparisons.
self.assert_lint_one_of_many_errors_re(
'if (string != NULL)',
- r'Tests for true/false, null/non-null, and zero/non-zero should all be done without equality comparisons\.')
+ r'Tests for true/false and null/non-null should be done without equality comparisons\.')
+ self.assert_lint(
+ 'if (p == nullptr)',
+ 'Tests for true/false and null/non-null should be done without equality comparisons.'
+ ' [readability/comparison_to_boolean] [5]')
self.assert_lint(
'if (condition == true)',
- 'Tests for true/false, null/non-null, and zero/non-zero should all be done without equality comparisons.'
- ' [readability/comparison_to_zero] [5]')
+ 'Tests for true/false and null/non-null should be done without equality comparisons.'
+ ' [readability/comparison_to_boolean] [5]')
self.assert_lint(
'if (myVariable != /* Why would anyone put a comment here? */ false)',
- 'Tests for true/false, null/non-null, and zero/non-zero should all be done without equality comparisons.'
- ' [readability/comparison_to_zero] [5]')
+ 'Tests for true/false and null/non-null should be done without equality comparisons.'
+ ' [readability/comparison_to_boolean] [5]')
- self.assert_lint(
- 'if (0 /* This comment also looks odd to me. */ != aLongerVariableName)',
- 'Tests for true/false, null/non-null, and zero/non-zero should all be done without equality comparisons.'
- ' [readability/comparison_to_zero] [5]')
self.assert_lint_one_of_many_errors_re(
'if (NULL == thisMayBeNull)',
- r'Tests for true/false, null/non-null, and zero/non-zero should all be done without equality comparisons\.')
+ r'Tests for true/false and null/non-null should be done without equality comparisons\.')
+ self.assert_lint(
+ 'if (nullptr /* funny place for a comment */ == p)',
+ 'Tests for true/false and null/non-null should be done without equality comparisons.'
+ ' [readability/comparison_to_boolean] [5]')
self.assert_lint(
'if (true != anotherCondition)',
- 'Tests for true/false, null/non-null, and zero/non-zero should all be done without equality comparisons.'
- ' [readability/comparison_to_zero] [5]')
+ 'Tests for true/false and null/non-null should be done without equality comparisons.'
+ ' [readability/comparison_to_boolean] [5]')
self.assert_lint(
'if (false == myBoolValue)',
- 'Tests for true/false, null/non-null, and zero/non-zero should all be done without equality comparisons.'
- ' [readability/comparison_to_zero] [5]')
+ 'Tests for true/false and null/non-null should be done without equality comparisons.'
+ ' [readability/comparison_to_boolean] [5]')
self.assert_lint(
'if (fontType == trueType)',
" [build/using_std] [4]",
'foo.cpp')
+ def test_using_std_swap_ignored(self):
+ self.assert_lint(
+ 'using std::swap;',
+ '',
+ 'foo.cpp')
+
def test_max_macro(self):
self.assert_lint(
'int i = MAX(0, 1);',