Commit 5171d853 authored by dcheng's avatar dcheng Committed by Commit bot

Remove test result whitespace stripping from blink_gc_plugin test script

To make things easier for future developers, the test script now parses
the options using argparse and provides a --reset-results flag to easily
update the baselines.

BUG=none

Review URL: https://codereview.chromium.org/1132293003

Cr-Commit-Position: refs/heads/master@{#329904}
parent 9bb374b6
...@@ -5,3 +5,4 @@ Found a potentially leaking cycle starting from a GC root: ...@@ -5,3 +5,4 @@ Found a potentially leaking cycle starting from a GC root:
./cycle_ptrs.h:34:5: blink::B (m_c) => blink::C ./cycle_ptrs.h:34:5: blink::B (m_c) => blink::C
./cycle_ptrs.h:39:5: blink::C (m_d) => blink::D ./cycle_ptrs.h:39:5: blink::C (m_d) => blink::D
./cycle_ptrs.h:44:5: blink::D (m_es) => blink::E ./cycle_ptrs.h:44:5: blink::D (m_es) => blink::E
...@@ -3,3 +3,4 @@ Found a potentially leaking cycle starting from a GC root: ...@@ -3,3 +3,4 @@ Found a potentially leaking cycle starting from a GC root:
./cycle_sub.h:31:5: blink::C (m_a) => blink::A ./cycle_sub.h:31:5: blink::C (m_a) => blink::A
./cycle_sub.h:22:11: blink::A (<subclass>) => blink::B ./cycle_sub.h:22:11: blink::A (<subclass>) => blink::B
./cycle_sub.h:26:5: blink::B (m_c) => blink::C ./cycle_sub.h:26:5: blink::B (m_c) => blink::C
...@@ -2,3 +2,4 @@ ...@@ -2,3 +2,4 @@
Found a potentially leaking cycle starting from a GC root: Found a potentially leaking cycle starting from a GC root:
./cycle_super.h:36:5: blink::D (m_c) => blink::C ./cycle_super.h:36:5: blink::D (m_c) => blink::C
./cycle_super.h:21:5: blink::C (blink::B <: blink::A <: m_d) => blink::D ./cycle_super.h:21:5: blink::C (blink::B <: blink::A <: m_d) => blink::D
...@@ -4,18 +4,20 @@ ...@@ -4,18 +4,20 @@
# found in the LICENSE file. # found in the LICENSE file.
import argparse
import glob import glob
import os import os
import subprocess import subprocess
import sys import sys
def run_test(test_base_name, cmd): def run_test(test_base_name, cmd, reset_results):
"""Run a test case. """Run a test case.
Args: Args:
test_base_name: The name for the test C++ source file without the extension. test_base_name: The name for the test C++ source file without the extension.
cmd: The actual command to run for the test. cmd: The actual command to run for the test.
reset_results: True if the results should be overwritten in place.
Returns: Returns:
None on pass, or a str with the description of the failure. None on pass, or a str with the description of the failure.
...@@ -47,31 +49,31 @@ def run_test(test_base_name, cmd): ...@@ -47,31 +49,31 @@ def run_test(test_base_name, cmd):
# from a previous run. # from a previous run.
os.remove('%s.graph.json' % test_base_name) os.remove('%s.graph.json' % test_base_name)
# TODO(dcheng): Remove the rstrip() and just rebaseline the tests to match.
actual = actual.rstrip()
# On Windows, clang emits CRLF as the end of line marker. Normalize it to LF # On Windows, clang emits CRLF as the end of line marker. Normalize it to LF
# to match posix systems. # to match posix systems.
actual = actual.replace('\r\n', '\n') actual = actual.replace('\r\n', '\n')
result_file = '%s.txt%s' % (
test_base_name, '' if reset_results else '.actual')
try: try:
expected = open('%s.txt' % test_base_name).read().rstrip() expected = open('%s.txt' % test_base_name).read()
except IOError: except IOError:
open('%s.txt.actual' % test_base_name, 'w').write(actual) open(result_file, 'w').write(actual)
return 'no expected file found' return 'no expected file found'
if expected != actual: if expected != actual:
open('%s.txt.actual' % test_base_name, 'w').write(actual) open(result_file, 'w').write(actual)
return 'expected and actual differed' return 'expected and actual differed'
def run_tests(clang_path, plugin_path): def run_tests(clang_path, plugin_path, reset_results):
"""Runs the tests. """Runs the tests.
Args: Args:
clang_path: The path to the clang binary to be tested. clang_path: The path to the clang binary to be tested.
plugin_path: An optional path to the plugin to test. This may be None, if plugin_path: An optional path to the plugin to test. This may be None, if
plugin is built directly into clang, like on Windows. plugin is built directly into clang, like on Windows.
reset_results: True if the results should be overwritten in place.
Returns: Returns:
(passing, failing): Two lists containing the base names of the passing and (passing, failing): Two lists containing the base names of the passing and
...@@ -101,7 +103,7 @@ def run_tests(clang_path, plugin_path): ...@@ -101,7 +103,7 @@ def run_tests(clang_path, plugin_path):
pass pass
cmd.append(test) cmd.append(test)
failure_message = run_test(test_base_name, cmd) failure_message = run_test(test_base_name, cmd, reset_results)
if failure_message: if failure_message:
print 'failed: %s' % failure_message print 'failed: %s' % failure_message
failing.append(test_base_name) failing.append(test_base_name)
...@@ -113,18 +115,23 @@ def run_tests(clang_path, plugin_path): ...@@ -113,18 +115,23 @@ def run_tests(clang_path, plugin_path):
def main(): def main():
if len(sys.argv) < 2: parser = argparse.ArgumentParser()
print 'Usage: <path to clang>[ <path to plugin>]' parser.add_argument(
return -1 '--reset-results', action='store_true',
help='If specified, overwrites the expected results in place.')
parser.add_argument('clang_path', help='The path to the clang binary.')
parser.add_argument('plugin_path', nargs='?',
help='The path to the plugin library, if any.')
args = parser.parse_args()
os.chdir(os.path.dirname(os.path.realpath(__file__))) os.chdir(os.path.dirname(os.path.realpath(__file__)))
clang_path = sys.argv[1] print 'Using clang %s...' % args.clang_path
plugin_path = sys.argv[2] if len(sys.argv) > 2 else None print 'Using plugin %s...' % args.plugin_path
print 'Using clang %s...' % clang_path
print 'Using plugin %s...' % plugin_path
passing, failing = run_tests(clang_path, plugin_path) passing, failing = run_tests(args.clang_path,
args.plugin_path,
args.reset_results)
print 'Ran %d tests: %d succeeded, %d failed' % ( print 'Ran %d tests: %d succeeded, %d failed' % (
len(passing) + len(failing), len(passing), len(failing)) len(passing) + len(failing), len(passing), len(failing))
for test in failing: for test in failing:
......
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