Ensure autorelease pool is drained between tests
The testing::Test fixture (used by TEST macro) does not drain the
autorelease pool after a test. PlatformTest should be used.
Add a PRESUBMIT check that neither TEST nor testing::Test is used
in iOS Objective-C++ test files. Files are assumed to be iOS if
either their base name match '\bios\b' or one of the component in
the path is 'ios'.
Expand MockInputApi to filter files in mocks of AffectedFiles and
AffectedSourceFiles function, adding missing mocked functions too.
Fix unit tests that were failing after the filtering is correctly
implemented.
Bug: none
Change-Id: I0af99b6658b8e15888dfcfb94345eb879ab9fd37
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Reviewed-on: https://chromium-review.googlesource.com/937204
Reviewed-by: Jochen Eisinger <[email protected]>
Reviewed-by: Rohit Rao <[email protected]>
Commit-Queue: Sylvain Defresne <[email protected]>
Cr-Commit-Position: refs/heads/master@{#539829}
diff --git a/PRESUBMIT.py b/PRESUBMIT.py
index 48493fc..b5f115db 100644
--- a/PRESUBMIT.py
+++ b/PRESUBMIT.py
@@ -179,6 +179,28 @@
),
)
+_BANNED_IOS_OBJC_FUNCTIONS = (
+ (
+ r'/\bTEST[(]',
+ (
+ 'TEST() macro should not be used in Objective-C++ code as it does not ',
+ 'drain the autorelease pool at the end of the test. Use TEST_F() ',
+ 'macro instead with a fixture inheriting from PlatformTest (or a ',
+ 'typedef).'
+ ),
+ True,
+ ),
+ (
+ r'/\btesting::Test\b',
+ (
+ 'testing::Test should not be used in Objective-C++ code as it does ',
+ 'not drain the autorelease pool at the end of the test. Use ',
+ 'PlatformTest instead.'
+ ),
+ True,
+ ),
+)
+
_BANNED_CPP_FUNCTIONS = (
# Make sure that gtest's FRIEND_TEST() macro is not used; the
@@ -786,6 +808,18 @@
return True
return False
+ def IsIosObcjFile(affected_file):
+ local_path = affected_file.LocalPath()
+ if input_api.os_path.splitext(local_path)[-1] not in ('.mm', '.m', '.h'):
+ return False
+ basename = input_api.os_path.basename(local_path)
+ if 'ios' in basename.split('_'):
+ return True
+ for sep in (input_api.os_path.sep, input_api.os_path.altsep):
+ if sep and 'ios' in local_path.split(sep):
+ return True
+ return False
+
def CheckForMatch(affected_file, line_num, line, func_name, message, error):
matched = False
if func_name[0:1] == '/':
@@ -814,6 +848,11 @@
for func_name, message, error in _BANNED_OBJC_FUNCTIONS:
CheckForMatch(f, line_num, line, func_name, message, error)
+ for f in input_api.AffectedFiles(file_filter=IsIosObcjFile):
+ for line_num, line in f.ChangedContents():
+ for func_name, message, error in _BANNED_IOS_OBJC_FUNCTIONS:
+ CheckForMatch(f, line_num, line, func_name, message, error)
+
file_filter = lambda f: f.LocalPath().endswith(('.cc', '.mm', '.h'))
for f in input_api.AffectedFiles(file_filter=file_filter):
for line_num, line in f.ChangedContents():