Add PRESUBMIT to enforce usage of new Googletest APIs.
Example of an error:
** Presubmit ERRORS **
Usage of legacy GoogleTest API detected!
Please use the new API: https://github.com/google/googletest/blob/master/googletest/docs/primer.md#beware-of-the-nomenclature.
Affected files:
rtc_base/ssl_stream_adapter_unittest.cc (line 1459)
Bug: None
No-Try: True
Change-Id: Ibe8fbbc6c3205a266fc75afb5b59721a6b69f240
Reviewed-on: https://webrtc-review.googlesource.com/c/120924
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Reviewed-by: Oleh Prypin <oprypin@webrtc.org>
Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#26562}
diff --git a/PRESUBMIT.py b/PRESUBMIT.py
index 4abcb26..8c75942 100755
--- a/PRESUBMIT.py
+++ b/PRESUBMIT.py
@@ -449,6 +449,26 @@
return [output_api.PresubmitError(msg, errors)]
return []
+
+def CheckNoTestCaseUsageIsAdded(input_api, output_api, source_file_filter,
+ error_formatter=_ReportFileAndLine):
+ error_msg = ('Usage of legacy GoogleTest API detected!\nPlease use the '
+ 'new API: https://github.com/google/googletest/blob/master/'
+ 'googletest/docs/primer.md#beware-of-the-nomenclature.\n'
+ 'Affected files:\n')
+ errors = [] # 2-element tuples with (file, line number)
+ test_case_re = input_api.re.compile(r'TEST_CASE')
+ file_filter = lambda f: (source_file_filter(f)
+ and f.LocalPath().endswith('.cc'))
+ for f in input_api.AffectedSourceFiles(file_filter):
+ for line_num, line in f.ChangedContents():
+ if test_case_re.search(line):
+ errors.append(error_formatter(f.LocalPath(), line_num))
+ if errors:
+ return [output_api.PresubmitError(error_msg, errors)]
+ return []
+
+
def CheckNoStreamUsageIsAdded(input_api, output_api,
source_file_filter,
error_formatter=_ReportFileAndLine):
@@ -860,6 +880,8 @@
input_api, output_api, source_file_filter=non_third_party_sources))
results.extend(CheckNoStreamUsageIsAdded(
input_api, output_api, non_third_party_sources))
+ results.extend(CheckNoTestCaseUsageIsAdded(
+ input_api, output_api, non_third_party_sources))
results.extend(CheckAddedDepsHaveTargetApprovals(input_api, output_api))
results.extend(CheckApiDepsFileIsUpToDate(input_api, output_api))
results.extend(CheckAbslMemoryInclude(