Skip to content

Commit

Permalink
Style checker has issue with test implementation files with no primar…
Browse files Browse the repository at this point in the history
…y headers

https://bugs.webkit.org/show_bug.cgi?id=185057
rdar://problem/101670878

Reviewed by Jonathan Bedard.

Fix the cpp style checker to account for test .cpp files. These
files do not have a primary header file. The style checker would
make many mistakes flagging a wrong include as primary include.
For file ConnectionTests.cpp:
  - It would think "Connection.h" would be a primary include.
  - It would think "Test.h" would be a primary include.

* Tools/Scripts/webkitpy/style/checkers/cpp.py:
(_classify_include):
* Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py:

Canonical link: https://commits.webkit.org/256128@main
  • Loading branch information
kkinnunen-apple committed Oct 29, 2022
1 parent 411c085 commit 2419e96
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Tools/Scripts/webkitpy/style/checkers/cpp.py
Expand Up @@ -3598,6 +3598,10 @@ def _classify_include(filename, include, is_system, include_state):
target_base = FileInfo(filename).base_name()
include_base = FileInfo(include).base_name()

# Test .cpp, .mm, .c files do not have primary header files.
if any(target_base.endswith(suffix) for suffix in ['Test', 'Tests']):
return _OTHER_HEADER

# If we haven't encountered a primary header, then be lenient in checking.
if not include_state.visited_primary_section():
if target_base.find(include_base) != -1:
Expand Down
14 changes: 14 additions & 0 deletions Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py
Expand Up @@ -3636,6 +3636,20 @@ def test_primary_header(self):
'#include "bar.h"\n',
'')

# .. for tests even if the base name of an include is the prefix of the includee base name.
self.assert_language_rules_check('FooTest.cpp',
'#include "config.h"\n'
'\n'
'#include "Foo.h"\n',
'')

# .. for tests even if the base name of an include is contained in the includee base name.
self.assert_language_rules_check('FooTests.cpp',
'#include "config.h"\n'
'\n'
'#include "Test.h"\n',
'')

# Pretend that header files exist.
os.path.isfile = lambda filename: True

Expand Down

0 comments on commit 2419e96

Please sign in to comment.