Skip to content

Commit 508b517

Browse files
committed
feat(discovery): add more options for discovering tags and tests
1 parent 2b4ce26 commit 508b517

File tree

1 file changed

+53
-5
lines changed
  • packages/runner/src/robotcode/runner/cli/discover

1 file changed

+53
-5
lines changed

packages/runner/src/robotcode/runner/cli/discover/discover.py

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ class TestItem:
190190
longname: str
191191
uri: Optional[DocumentUri] = None
192192
rel_source: Optional[str] = None
193+
source: Optional[str] = None
193194
needs_parse_include: bool = False
194195
children: Optional[List["TestItem"]] = None
195196
description: Optional[str] = None
@@ -260,6 +261,7 @@ def visit_suite(self, suite: TestSuite) -> None:
260261
name=suite.name,
261262
longname=suite.longname,
262263
uri=str(Uri.from_path(Path(suite.source).resolve())) if suite.source else None,
264+
source=str(suite.source),
263265
rel_source=get_rel_source(suite.source),
264266
range=Range(
265267
start=Position(line=0, character=0),
@@ -311,6 +313,7 @@ def visit_test(self, test: TestCase) -> None:
311313
name=test.name,
312314
longname=test.longname,
313315
uri=str(Uri.from_path(Path(test.source).resolve())) if test.source else None,
316+
source=str(test.source),
314317
rel_source=get_rel_source(test.source),
315318
range=Range(
316319
start=Position(line=test.lineno - 1, character=0),
@@ -504,6 +507,7 @@ def handle_options(
504507
"--diagnostics / --no-diagnostics",
505508
"show_diagnostics",
506509
default=True,
510+
show_default=True,
507511
help="Display `robot` parsing errors and warning that occur during discovering.",
508512
)
509513
}
@@ -593,12 +597,28 @@ def print(item: TestItem, indent: int = 0) -> Iterable[str]:
593597
add_help_option=True,
594598
epilog='Use "-- --help" to see `robot` help.',
595599
)
600+
@click.option(
601+
"--tags / --no-tags",
602+
"show_tags",
603+
default=False,
604+
show_default=True,
605+
help="Show the tags that are present.",
606+
)
607+
@click.option(
608+
"--full-paths / --no-full-paths",
609+
"full_paths",
610+
default=False,
611+
show_default=True,
612+
help="Show full paths instead of releative.",
613+
)
596614
@add_options(*DIAGOSTICS_OPTIONS)
597615
@add_options(*ROBOT_OPTIONS)
598616
@pass_application
599617
def tests(
600618
app: Application,
601619
show_diagnostics: bool,
620+
full_paths: bool,
621+
show_tags: bool,
602622
by_longname: Tuple[str, ...],
603623
exclude_by_longname: Tuple[str, ...],
604624
robot_options_and_args: Tuple[str, ...],
@@ -627,7 +647,14 @@ def tests(
627647

628648
def print(items: List[TestItem]) -> Iterable[str]:
629649
for item in items:
630-
yield f"{item.longname}{os.linesep}"
650+
yield click.style(f"{item.longname}", bold=True, fg="green" if show_tags else None)
651+
yield click.style(
652+
f" ({item.source if full_paths else item.rel_source}"
653+
f":{item.range.start.line + 1 if item.range is not None else 1}){os.linesep}"
654+
)
655+
if show_tags and item.tags:
656+
yield click.style(" Tags:", bold=True)
657+
yield f" {', '. join(normalize(str(tag), ignore='_') for tag in item.tags)}{os.linesep}"
631658

632659
if collector.tests:
633660
app.echo_via_pager(print(collector.tests))
@@ -704,15 +731,32 @@ class TagsResult:
704731
"--normalized / --not-normalized",
705732
"normalized",
706733
default=True,
734+
show_default=True,
707735
help="Whether or not normalized tags are shown.",
708736
)
737+
@click.option(
738+
"--tests / --no-tests",
739+
"show_tests",
740+
default=False,
741+
show_default=True,
742+
help="Show tests where the tag is present.",
743+
)
744+
@click.option(
745+
"--full-paths / --no-full-paths",
746+
"full_paths",
747+
default=False,
748+
show_default=True,
749+
help="Show full paths instead of releative.",
750+
)
709751
@add_options(*DIAGOSTICS_OPTIONS)
710752
@add_options(*ROBOT_OPTIONS)
711753
@pass_application
712754
def tags(
713755
app: Application,
714756
show_diagnostics: bool,
715757
normalized: bool,
758+
show_tests: bool,
759+
full_paths: bool,
716760
by_longname: Tuple[str, ...],
717761
exclude_by_longname: Tuple[str, ...],
718762
robot_options_and_args: Tuple[str, ...],
@@ -729,7 +773,7 @@ def tags(
729773
robotcode discover tags
730774
robotcode --profile regression discover tags
731775
732-
robotcode --profile regression discover tags -i wip
776+
robotcode --profile regression discover tags --tests -i wip
733777
```
734778
"""
735779

@@ -742,9 +786,13 @@ def tags(
742786

743787
def print(tags: Dict[str, List[TestItem]]) -> Iterable[str]:
744788
for tag, items in tags.items():
745-
yield f"{tag}{os.linesep}"
746-
# for t in items:
747-
# yield f" {t.longname}{os.linesep}"
789+
yield click.style(f"{tag}{os.linesep}", bold=show_tests, fg="green" if show_tests else None)
790+
if show_tests:
791+
for t in items:
792+
yield click.style(f" {t.longname}", bold=True) + click.style(
793+
f" ({t.source if full_paths else t.rel_source}"
794+
f":{t.range.start.line + 1 if t.range is not None else 1}){os.linesep}"
795+
)
748796

749797
if collector.normalized_tags:
750798
app.echo_via_pager(print(collector.normalized_tags if normalized else collector.tags))

0 commit comments

Comments
 (0)