summaryrefslogtreecommitdiffstats
path: root/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py
diff options
context:
space:
mode:
Diffstat (limited to 'Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py')
-rw-r--r--Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py48
1 files changed, 39 insertions, 9 deletions
diff --git a/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py b/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py
index 2d2abbf..a98d0dd 100644
--- a/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py
+++ b/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py
@@ -2452,18 +2452,20 @@ class OrderOfIncludesTest(CppStyleTestBase):
# Cheat os.path.abspath called in FileInfo class.
self.os_path_abspath_orig = os.path.abspath
+ self.os_path_isfile_orig = os.path.isfile
os.path.abspath = lambda value: value
def tearDown(self):
os.path.abspath = self.os_path_abspath_orig
+ os.path.isfile = self.os_path_isfile_orig
def test_check_next_include_order__no_config(self):
self.assertEqual('Header file should not contain WebCore config.h.',
- self.include_state.check_next_include_order(cpp_style._CONFIG_HEADER, True))
+ self.include_state.check_next_include_order(cpp_style._CONFIG_HEADER, True, True))
def test_check_next_include_order__no_self(self):
self.assertEqual('Header file should not contain itself.',
- self.include_state.check_next_include_order(cpp_style._PRIMARY_HEADER, True))
+ self.include_state.check_next_include_order(cpp_style._PRIMARY_HEADER, True, True))
# Test actual code to make sure that header types are correctly assigned.
self.assert_language_rules_check('Foo.h',
'#include "Foo.h"\n',
@@ -2475,22 +2477,22 @@ class OrderOfIncludesTest(CppStyleTestBase):
def test_check_next_include_order__likely_then_config(self):
self.assertEqual('Found header this file implements before WebCore config.h.',
- self.include_state.check_next_include_order(cpp_style._PRIMARY_HEADER, False))
+ self.include_state.check_next_include_order(cpp_style._PRIMARY_HEADER, False, True))
self.assertEqual('Found WebCore config.h after a header this file implements.',
- self.include_state.check_next_include_order(cpp_style._CONFIG_HEADER, False))
+ self.include_state.check_next_include_order(cpp_style._CONFIG_HEADER, False, True))
def test_check_next_include_order__other_then_config(self):
self.assertEqual('Found other header before WebCore config.h.',
- self.include_state.check_next_include_order(cpp_style._OTHER_HEADER, False))
+ self.include_state.check_next_include_order(cpp_style._OTHER_HEADER, False, True))
self.assertEqual('Found WebCore config.h after other header.',
- self.include_state.check_next_include_order(cpp_style._CONFIG_HEADER, False))
+ self.include_state.check_next_include_order(cpp_style._CONFIG_HEADER, False, True))
def test_check_next_include_order__config_then_other_then_likely(self):
- self.assertEqual('', self.include_state.check_next_include_order(cpp_style._CONFIG_HEADER, False))
+ self.assertEqual('', self.include_state.check_next_include_order(cpp_style._CONFIG_HEADER, False, True))
self.assertEqual('Found other header before a header this file implements.',
- self.include_state.check_next_include_order(cpp_style._OTHER_HEADER, False))
+ self.include_state.check_next_include_order(cpp_style._OTHER_HEADER, False, True))
self.assertEqual('Found header this file implements after other header.',
- self.include_state.check_next_include_order(cpp_style._PRIMARY_HEADER, False))
+ self.include_state.check_next_include_order(cpp_style._PRIMARY_HEADER, False, True))
def test_check_alphabetical_include_order(self):
self.assert_language_rules_check('foo.h',
@@ -2586,6 +2588,34 @@ class OrderOfIncludesTest(CppStyleTestBase):
'#include "g.h"\n',
'"foo.h" already included at foo.cpp:2 [build/include] [4]')
+ def test_primary_header(self):
+ # File with non-existing primary header should not produce errors.
+ self.assert_language_rules_check('foo.cpp',
+ '#include "config.h"\n'
+ '\n'
+ '#include "bar.h"\n',
+ '')
+ # Pretend that header files exist.
+ os.path.isfile = lambda filename: True
+ # Missing include for existing primary header -> error.
+ self.assert_language_rules_check('foo.cpp',
+ '#include "config.h"\n'
+ '\n'
+ '#include "bar.h"\n',
+ 'Found other header before a header this file implements. '
+ 'Should be: config.h, primary header, blank line, and then '
+ 'alphabetically sorted. [build/include_order] [4]')
+ # Having include for existing primary header -> no error.
+ self.assert_language_rules_check('foo.cpp',
+ '#include "config.h"\n'
+ '#include "foo.h"\n'
+ '\n'
+ '#include "bar.h"\n',
+ '')
+
+ os.path.isfile = self.os_path_isfile_orig
+
+
def test_check_wtf_includes(self):
self.assert_language_rules_check('foo.cpp',
'#include "config.h"\n'