From 95bc61354165025ba7add2788c685a92b95b4272 Mon Sep 17 00:00:00 2001 From: ninjinkun Date: Mon, 28 Dec 2020 17:04:12 +0900 Subject: [PATCH 1/3] feature: add googletest plugin --- launchable/test_runners/googletest.py | 32 +++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 launchable/test_runners/googletest.py diff --git a/launchable/test_runners/googletest.py b/launchable/test_runners/googletest.py new file mode 100644 index 000000000..4d5a3bb2e --- /dev/null +++ b/launchable/test_runners/googletest.py @@ -0,0 +1,32 @@ +import sys +import re +import click + +from . import launchable +from ..testpath import TestPath + + +def make_test_path(cls, case) -> TestPath: + return [{'type': 'class', 'name': cls}, {'type': 'case', 'name': case}] + + +@launchable.subset +def subset(client): + # Read targets from stdin, which generally looks like //foo/bar:zot + for label in sys.stdin: + # -> //foo/bar & zot + result = re.match(r'^ *Test #\d+: ([^ ]+)$', label) + if result: + (cls, case) = result.group(1).split('.') + client.test_path(make_test_path(cls, case)) + + client.formatter = lambda x: x[0]['name'] + "." + x[1]['name'] + client.run() + + +@click.argument('report_dirs', required=True, nargs=-1) +@launchable.record.tests +def record_tests(client, report_dirs): + for root in report_dirs: + client.scan(root, "*.xml") + client.run() From cf4af244c3c464adb484da8c6495838ab8a02c01 Mon Sep 17 00:00:00 2001 From: ninjinkun Date: Mon, 28 Dec 2020 19:17:59 +0900 Subject: [PATCH 2/3] fix: add comment --- launchable/test_runners/googletest.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/launchable/test_runners/googletest.py b/launchable/test_runners/googletest.py index 4d5a3bb2e..a5a617f20 100644 --- a/launchable/test_runners/googletest.py +++ b/launchable/test_runners/googletest.py @@ -14,7 +14,8 @@ def make_test_path(cls, case) -> TestPath: def subset(client): # Read targets from stdin, which generally looks like //foo/bar:zot for label in sys.stdin: - # -> //foo/bar & zot + # handle ctest -N output + # Test #1: FooTest.Bar -> (FooTest, Bar) result = re.match(r'^ *Test #\d+: ([^ ]+)$', label) if result: (cls, case) = result.group(1).split('.') From 4bf7746f0ed9862e751fdd7438a04ab7516825fe Mon Sep 17 00:00:00 2001 From: ninjinkun Date: Mon, 28 Dec 2020 21:23:12 +0900 Subject: [PATCH 3/3] feature: add --gtest_list_tests support --- launchable/test_runners/googletest.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/launchable/test_runners/googletest.py b/launchable/test_runners/googletest.py index a5a617f20..50ed20785 100644 --- a/launchable/test_runners/googletest.py +++ b/launchable/test_runners/googletest.py @@ -13,12 +13,25 @@ def make_test_path(cls, case) -> TestPath: @launchable.subset def subset(client): # Read targets from stdin, which generally looks like //foo/bar:zot - for label in sys.stdin: + cls = '' + for label in map(str.rstrip, sys.stdin): + # handle Google Test's --gtest_list_tests output + # FooTest. + # Bar + # Baz + gtest_class = re.match(r'^([^\.]+)\.', label) + if gtest_class: + cls = gtest_class.group(1) + gtest_case = re.match(r'^ ([^ ]+)', label) + if gtest_case and cls: + case = gtest_case.group(1) + client.test_path(make_test_path(cls, case)) + # handle ctest -N output # Test #1: FooTest.Bar -> (FooTest, Bar) - result = re.match(r'^ *Test #\d+: ([^ ]+)$', label) - if result: - (cls, case) = result.group(1).split('.') + ctest_result = re.match(r'^ Test #\d+: ([^ ]+)$', label) + if ctest_result: + (cls, case) = ctest_result.group(1).split('.') client.test_path(make_test_path(cls, case)) client.formatter = lambda x: x[0]['name'] + "." + x[1]['name']