Commit b3fe7c5a authored by Ehsan Kia's avatar Ehsan Kia Committed by Commit Bot

Update extractor_test to not rely on pre-generated compile_commands.json

Bug: 1055514
Change-Id: Icb49beb89520cf49e1676f0ef9a301a91a703332
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2080672Reviewed-by: default avatarNicolas Ouellet-Payeur <nicolaso@chromium.org>
Commit-Queue: Ehsan Kia <ehsankia@google.com>
Cr-Commit-Position: refs/heads/master@{#745627}
parent a7a4b706
...@@ -16,16 +16,17 @@ import unittest ...@@ -16,16 +16,17 @@ import unittest
import re import re
import subprocess import subprocess
def run_extractor(file):
def run_extractor(file, *extra_args):
script_path = os.path.join('..', 'extractor.py') script_path = os.path.join('..', 'extractor.py')
cmd_line = ["python", script_path, '--no-filter', file] cmd_line = ("python", script_path, '--no-filter', file) + extra_args
return subprocess.Popen( return subprocess.Popen(
cmd_line, stdout=subprocess.PIPE, stderr=subprocess.PIPE) cmd_line, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
def get_expected_files(source_file): def get_expected_files(source_file):
stdout_file = re.sub('\.cc$', '-stdout.txt', source_file) stdout_file = re.sub(r'\.cc$', '-stdout.txt', source_file)
stderr_file = re.sub('\.cc$', '-stderr.txt', source_file) stderr_file = re.sub(r'\.cc$', '-stderr.txt', source_file)
return (stdout_file, stderr_file) return (stdout_file, stderr_file)
...@@ -48,7 +49,6 @@ def remove_tracebacks(str): ...@@ -48,7 +49,6 @@ def remove_tracebacks(str):
class ExtractorTest(unittest.TestCase): class ExtractorTest(unittest.TestCase):
def testExtractor(self): def testExtractor(self):
os.chdir(os.path.join(os.path.dirname(__file__), 'test_data'))
for source_file in glob.glob('*.cc'): for source_file in glob.glob('*.cc'):
print("Running test on %s..." % source_file) print("Running test on %s..." % source_file)
(stdout_file, stderr_file) = get_expected_files(source_file) (stdout_file, stderr_file) = get_expected_files(source_file)
...@@ -67,7 +67,6 @@ class ExtractorTest(unittest.TestCase): ...@@ -67,7 +67,6 @@ class ExtractorTest(unittest.TestCase):
def generate_expected_files(): def generate_expected_files():
os.chdir(os.path.join(os.path.dirname(__file__), 'test_data'))
for source_file in glob.glob('*.cc'): for source_file in glob.glob('*.cc'):
proc = run_extractor(source_file) proc = run_extractor(source_file)
(stdout, stderr) = proc.communicate() (stdout, stderr) = proc.communicate()
...@@ -87,6 +86,14 @@ if __name__ == '__main__': ...@@ -87,6 +86,14 @@ if __name__ == '__main__':
help='Generate "-stdout.txt" and "-stderr.txt" for file in test_data') help='Generate "-stdout.txt" and "-stderr.txt" for file in test_data')
args = parser.parse_args() args = parser.parse_args()
# Set directory for both test and gen command to the test_data folder.
os.chdir(os.path.join(os.path.dirname(__file__), 'test_data'))
# Run the extractor script with --generate-compdb to ensure the
# compile_commands.json file exists in the default output directory.
proc = run_extractor(os.devnull, '--generate-compdb')
proc.communicate() # Wait until extractor finishes running.
if args.generate_expected_files: if args.generate_expected_files:
generate_expected_files() generate_expected_files()
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