Commit ebea79d7 authored by Mario Bianucci's avatar Mario Bianucci Committed by Commit Bot

Improvements to autotest.py

This CL includes several improvements to autotest.py:
-Slightly expand the GTest regex.
  -Previously, it missed some tests due to them not explicitly including
    gtest via #include "...gtest.h". Variations included <...gtest.h>,
    gmock.h, or via *test_utils.h. Expand the regex to include these
    cases.
  -In my (limited) testing I didn't see any large regressions in terms
    of number of files added via the expanded regex, but its possible
    there is something I missed.
-Add utf-8 encoding when opening a file to read.
  -This avoids errors when opening files with non-English characters.
-Debugging lines to output all files that matched the regex.
-Added sys.executable to beginning of call to make-gtest-filter.py.
  -This enables it to work on Windows, which requires 'python3' before
    calling a python script.

Change-Id: Ic9e67658b7298867d997ba4cc396320bf5d61c8c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2517944Reviewed-by: default avatarMichael Thiessen <mthiesse@chromium.org>
Commit-Queue: Mario Bianucci <mabian@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#824031}
parent 05c22c79
...@@ -57,14 +57,17 @@ _OTHER_TEST_TARGETS = [ ...@@ -57,14 +57,17 @@ _OTHER_TEST_TARGETS = [
] ]
TEST_FILE_NAME_REGEX = re.compile(r'(.*Test\.java)|(.*_[a-z]*test\.cc)') TEST_FILE_NAME_REGEX = re.compile(r'(.*Test\.java)|(.*_[a-z]*test\.cc)')
GTEST_INCLUDE_REGEX = re.compile(r'#include.*gtest\.h"')
# Some tests don't directly include gtest.h and instead include it via gmock.h
# or a test_utils.h file, so make sure these cases are captured. Also include
# files that use <...> for #includes instead of quotes.
GTEST_INCLUDE_REGEX = re.compile(r'#include.*(gtest|gmock|_test_utils)\.h("|>)')
def ExitWithMessage(*args): def ExitWithMessage(*args):
print(*args, file=sys.stderr) print(*args, file=sys.stderr)
sys.exit(1) sys.exit(1)
def IsTestFile(file_path): def IsTestFile(file_path):
if not TEST_FILE_NAME_REGEX.match(file_path): if not TEST_FILE_NAME_REGEX.match(file_path):
return False return False
...@@ -72,7 +75,7 @@ def IsTestFile(file_path): ...@@ -72,7 +75,7 @@ def IsTestFile(file_path):
# Try a bit harder to remove non-test files for c++. Without this, # Try a bit harder to remove non-test files for c++. Without this,
# 'autotest.py base/' finds non-test files. # 'autotest.py base/' finds non-test files.
try: try:
with open(file_path, 'r') as f: with open(file_path, 'r', encoding='utf-8') as f:
if GTEST_INCLUDE_REGEX.search(f.read()) is not None: if GTEST_INCLUDE_REGEX.search(f.read()) is not None:
return True return True
except IOError: except IOError:
...@@ -160,10 +163,14 @@ def RecursiveMatchFilename(folder, filename): ...@@ -160,10 +163,14 @@ def RecursiveMatchFilename(folder, filename):
def FindTestFilesInDirectory(directory): def FindTestFilesInDirectory(directory):
test_files = [] test_files = []
if DEBUG:
print('Test files:')
for root, dirs, files in os.walk(directory): for root, dirs, files in os.walk(directory):
for f in files: for f in files:
path = os.path.join(root, f) path = os.path.join(root, f)
if IsTestFile(path): if IsTestFile(path):
if DEBUG:
print(path)
test_files.append(path) test_files.append(path)
return test_files return test_files
...@@ -321,7 +328,10 @@ def RunTestTargets(out_dir, targets, gtest_filter, extra_args, dry_run): ...@@ -321,7 +328,10 @@ def RunTestTargets(out_dir, targets, gtest_filter, extra_args, dry_run):
def BuildCppTestFilter(filenames, line): def BuildCppTestFilter(filenames, line):
make_filter_command = [os.path.join(SRC_DIR, 'tools', 'make-gtest-filter.py')] make_filter_command = [
sys.executable,
os.path.join(SRC_DIR, 'tools', 'make-gtest-filter.py')
]
if line: if line:
make_filter_command += ['--line', str(line)] make_filter_command += ['--line', str(line)]
else: else:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment