Skip to content

Commit

Permalink
Merge pull request #571 from launchableinc/dotnet
Browse files Browse the repository at this point in the history
The --bare option and DRY
  • Loading branch information
kohsuke authored Jul 10, 2023
2 parents 658f19b + db2812f commit f380956
Showing 1 changed file with 36 additions and 48 deletions.
84 changes: 36 additions & 48 deletions launchable/test_runners/dotnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,20 @@
from launchable.testpath import TestPath


@launchable.subset
def subset(client):
"""
Alpha: Supports only Zero Input Subsetting
"""
if not client.is_get_tests_from_previous_sessions:
click.echo(
click.style(
"The dotnet profile only supports Zero Input Subsetting.\nMake sure to use `--get-tests-from-previous-sessions` opton", # noqa: E501
fg="red"),
err=True)

# ref: https://github.com/Microsoft/vstest-docs/blob/main/docs/filter.md
separator = "|"
prefix = "FullyQualifiedName="

if client.is_output_exclusion_rules:
separator = "&"
prefix = "FullyQualifiedName!="
# main subset logic
def do_subset(client, bare):
if bare:
separator = "."
prefix = ""
else:
# LEGACY: we recommend the bare mode with native NUnit integration
# ref: https://github.com/Microsoft/vstest-docs/blob/main/docs/filter.md
separator = "|"
prefix = "FullyQualifiedName="

if client.is_output_exclusion_rules:
separator = "&"
prefix = "FullyQualifiedName!="

def formatter(test_path: TestPath):
paths = []
Expand All @@ -36,6 +31,11 @@ def formatter(test_path: TestPath):
t = path.get("type", "")
if t == 'Assembly':
continue
if t == 'ParameterizedMethod':
# For parameterized test, we get something like
# Assembly=calc.dll#TestSuite=SomeNamespace#TestSuite=TestClassName#ParameterizedMethod=DivideTest#TestCase=DivideTest(1,3)
# see record_test_result.json as an example.
continue
paths.append(path.get("name", ""))

return prefix + ".".join(paths)
Expand All @@ -53,38 +53,26 @@ def exclusion_output_handler(subset_tests: List[TestPath], rest_tests: List[Test
client.run()


@launchable.split_subset
def split_subset(client):
# ref: https://github.com/Microsoft/vstest-docs/blob/main/docs/filter.md
separator = "|"
prefix = "FullyQualifiedName="

if client.is_output_exclusion_rules:
separator = "&"
prefix = "FullyQualifiedName!="

def formatter(test_path: TestPath):
paths = []

for path in test_path:
t = path.get("type", "")
if t == 'Assembly':
continue
paths.append(path.get("name", ""))

return prefix + ".".join(paths)
@click.option('--bare', help='outputs class names alone', default=False, is_flag=True)
@launchable.subset
def subset(client, bare):
"""
Alpha: Supports only Zero Input Subsetting
"""
if not client.is_get_tests_from_previous_sessions:
click.echo(
click.style(
"The dotnet profile only supports Zero Input Subsetting.\nMake sure to use `--get-tests-from-previous-sessions` opton", # noqa: E501
fg="red"),
err=True)

def exclusion_output_handler(subset_tests: List[TestPath], rest_tests: List[TestPath]):
if client.rest:
with open(client.rest, "w+", encoding="utf-8") as fp:
fp.write(client.separator.join(formatter(t) for t in subset_tests))
do_subset(client, bare)

click.echo(client.separator.join(formatter(t) for t in rest_tests))

client.separator = separator
client.formatter = formatter
client.exclusion_output_handler = exclusion_output_handler
client.run()
@click.option('--bare', help='outputs class names alone', default=False, is_flag=True)
@launchable.split_subset
def split_subset(client, bare):
do_subset(client, bare)


@click.argument('files', required=True, nargs=-1)
Expand Down

0 comments on commit f380956

Please sign in to comment.