Commit b61a1c1d authored by maruel@chromium.org's avatar maruel@chromium.org

Add --gtest_filter support to run_test_cases.py.

It works transparently when it is run through another method, like when
embedded in a .isolate command and additional commands are used.

R=cmp@chromium.org
NOTRY=true
BUG=
TEST=new unit test


Review URL: https://chromiumcodereview.appspot.com/10829014

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@148543 0039d316-1c4b-4281-b951-d872f2087c98
parent 9ea4c487
......@@ -557,7 +557,7 @@ def run_test_cases(executable, test_cases, jobs, timeout, no_dump):
return int(bool(fail))
def main():
def main(argv):
"""CLI frontend to validate arguments."""
def as_digit(variable, default):
if variable.isdigit():
......@@ -611,8 +611,12 @@ def main():
group.add_option(
'-T', '--test-case-file',
help='File containing the exact list of test cases to run')
group.add_option(
'--gtest_filter',
help='Runs a single test, provideded to keep compatibility with '
'other tools')
parser.add_option_group(group)
options, args = parser.parse_args()
options, args = parser.parse_args(argv)
levels = [logging.ERROR, logging.INFO, logging.DEBUG]
logging.basicConfig(
......@@ -634,6 +638,18 @@ def main():
if not os.path.isfile(executable):
parser.error('"%s" doesn\'t exist.' % executable)
if options.gtest_filter:
# Override any other option.
# Based on UnitTestOptions::FilterMatchesTest() in
# http://code.google.com/p/googletest/source/browse/#svn%2Ftrunk%2Fsrc
if '-' in options.gtest_filter:
options.whitelist, options.blacklist = options.gtest_filter.split('-', 1)
else:
options.whitelist = options.gtest_filter
options.blacklist = ''
options.whitelist = [i for i in options.whitelist.split(':') if i]
options.blacklist = [i for i in options.blacklist.split(':') if i]
# Grab the test cases.
if options.test_case_file:
with open(options.test_case_file, 'r') as f:
......@@ -647,7 +663,7 @@ def main():
options.shards)
if not test_cases:
return
return 0
return run_test_cases(
executable,
......@@ -658,4 +674,4 @@ def main():
if __name__ == '__main__':
sys.exit(main())
sys.exit(main(sys.argv[1:]))
......@@ -96,6 +96,23 @@ class RunTestCases(unittest.TestCase):
self.assertEquals('Sleeping.\nSlept.\n', output)
self.assertEquals(0, code)
def test_gtest_filter(self):
old = run_test_cases.run_test_cases
exe = os.path.join(ROOT_DIR, 'data', 'gtest_fake', 'gtest_fake_pass.py')
def expect(executable, test_cases, jobs, timeout, no_dump):
self.assertEquals(exe, executable)
self.assertEquals(['Foo.Bar1', 'Foo.Bar3'], test_cases)
self.assertEquals(run_test_cases.num_processors(), jobs)
self.assertEquals(120, timeout)
self.assertEquals(None, no_dump)
return 89
try:
run_test_cases.run_test_cases = expect
result = run_test_cases.main([exe, '--gtest_filter=Foo.Bar*-*.Bar2'])
self.assertEquals(89, result)
finally:
run_test_cases.run_test_cases = old
class WorkerPoolTest(unittest.TestCase):
def test_normal(self):
......
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