Skip to content

Commit 043cb78

Browse files
committed
test(runner): cover every discover subcommand with acceptance tests
Brings `discover` up to the same coverage level as `results`: nine new test files plus extended fixtures, all driven through the existing in-process `CliRunner`. - One file per subcommand (`test_all`, `test_tests`, `test_tasks`, `test_suites`, `test_tags`, `test_info`, `test_files`) - `test_filters` parametrises Robot-native filters (`--include`, `--exclude`, `--suite`, `--test`, `-bl`, `-ebl`) across the subcommands that support them - `test_errors` covers non-existent paths, missing arguments, invalid formats and parse-warning behaviour - New fixture suites: `tasks.robot` (RPA), `tagged.robot` (tag normalisation), `parse_error.robot` (duplicate tests, deprecated section), `mixed_dir/` (Tests + Tasks files side-by-side), and `files_tree/` (extensions + `.gitignore` for `discover files`) - `conftest.py` gains the new suite fixtures plus `walk_test_items`/`walk_suite_items` helpers, and pins each invocation to `--root <SUITES_DIR>` so the project's `robot.toml` doesn't leak into the test environment 105 new discover tests (240 across the full runner-CLI suite). Two production bugs surfaced while writing the tests and were fixed in the preceding commit.
1 parent 0f26a3f commit 043cb78

20 files changed

Lines changed: 910 additions & 5 deletions

tests/robotcode/runner/cli/discover/conftest.py

Lines changed: 80 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,17 @@ def run(args: Sequence[str], *, expect_ok: bool = True) -> CliResult:
7474
def json_discover(robotcode_cli: CliRunner) -> JsonRunner:
7575
"""Callable: `(subcommand, *args, suite_path) -> dict`.
7676
77-
Wraps `robotcode --format json discover <subcommand> ... <path>` and
78-
returns the parsed JSON object.
77+
Wraps `robotcode --root <SUITES_DIR> --format json discover
78+
--no-diagnostics <subcommand> ... <path>` and returns the parsed JSON.
79+
80+
- `--root SUITES_DIR` isolates the tests from the project's
81+
`robot.toml`, which sets `rpa = false` globally and would suppress
82+
Robot's auto-detection of Task suites.
83+
- `--no-diagnostics` keeps stdout clean of Robot's WARN/ERROR
84+
console-logger lines when the suite has parse issues — those would
85+
otherwise be interleaved with the JSON document. The JSON
86+
`diagnostics` field is still populated because it comes from a
87+
separate `DiagnosticsLogger`.
7988
"""
8089

8190
def run(
@@ -84,7 +93,17 @@ def run(
8493
suite_path: Path,
8594
expect_ok: bool = True,
8695
) -> Any:
87-
args: List[str] = ["--format", "json", "discover", subcommand, *extra, str(suite_path)]
96+
args: List[str] = [
97+
"--root",
98+
str(SUITES_DIR),
99+
"--format",
100+
"json",
101+
"discover",
102+
"--no-diagnostics",
103+
subcommand,
104+
*extra,
105+
str(suite_path),
106+
]
88107
result = robotcode_cli(args, expect_ok=expect_ok)
89108
if not expect_ok or not result.stdout.strip():
90109
return result
@@ -98,15 +117,18 @@ def run(
98117

99118
@pytest.fixture
100119
def text_discover(robotcode_cli: CliRunner) -> CliRunner:
101-
"""Callable: `(subcommand, *args, suite_path) -> CliResult`. Default TEXT format."""
120+
"""Callable: `(subcommand, *args, suite_path) -> CliResult`. Default TEXT format.
121+
122+
Same `--root SUITES_DIR` isolation as `json_discover`.
123+
"""
102124

103125
def run(
104126
subcommand: str,
105127
*extra: str,
106128
suite_path: Optional[Path] = None,
107129
expect_ok: bool = True,
108130
) -> CliResult:
109-
args: List[str] = ["discover", subcommand, *extra]
131+
args: List[str] = ["--root", str(SUITES_DIR), "discover", subcommand, *extra]
110132
if suite_path is not None:
111133
args.append(str(suite_path))
112134
return robotcode_cli(args, expect_ok=expect_ok)
@@ -127,3 +149,56 @@ def flat_suite() -> Path:
127149
@pytest.fixture
128150
def nested_suite() -> Path:
129151
return SUITES_DIR / "nested"
152+
153+
154+
@pytest.fixture
155+
def tasks_suite() -> Path:
156+
return SUITES_DIR / "tasks.robot"
157+
158+
159+
@pytest.fixture
160+
def mixed_suite() -> Path:
161+
"""Directory with one `Tests` and one `Tasks` .robot file side-by-side."""
162+
return SUITES_DIR / "mixed_dir"
163+
164+
165+
@pytest.fixture
166+
def tagged_suite() -> Path:
167+
return SUITES_DIR / "tagged.robot"
168+
169+
170+
@pytest.fixture
171+
def parse_error_suite() -> Path:
172+
return SUITES_DIR / "parse_error.robot"
173+
174+
175+
@pytest.fixture
176+
def files_tree() -> Path:
177+
return SUITES_DIR / "files_tree"
178+
179+
180+
# ---------------------------------------------------------------------------
181+
# Walk helpers
182+
# ---------------------------------------------------------------------------
183+
184+
185+
def walk_test_items(item: Any) -> List[Any]:
186+
"""Recursively collect TestItem dicts of type "test"/"task" from a tree."""
187+
out: List[Any] = []
188+
if isinstance(item, dict):
189+
if item.get("type") in ("test", "task"):
190+
out.append(item)
191+
for child in item.get("children") or []:
192+
out.extend(walk_test_items(child))
193+
return out
194+
195+
196+
def walk_suite_items(item: Any) -> List[Any]:
197+
"""Recursively collect TestItem dicts of type "suite" from a tree."""
198+
out: List[Any] = []
199+
if isinstance(item, dict):
200+
if item.get("type") == "suite":
201+
out.append(item)
202+
for child in item.get("children") or []:
203+
out.extend(walk_suite_items(child))
204+
return out
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ignored_by_git.robot
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This file should be skipped by `discover files` because its extension is neither `.robot` nor `.resource`.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*** Test Cases ***
2+
Deep Test
3+
Log deep
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*** Test Cases ***
2+
Sub One Test
3+
Log s1
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*** Keywords ***
2+
Helper Keyword
3+
Log helper
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
*** Tasks ***
2+
Task One
3+
[Tags] nightly
4+
Log k1
5+
6+
Task Two
7+
[Tags] nightly
8+
Log k2
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
*** Test Cases ***
2+
Test One
3+
[Tags] smoke
4+
Log t1
5+
6+
Test Two
7+
[Tags] regression
8+
Log t2
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
*** Test Cases ***
2+
Test One
3+
[Tags] smoke
4+
Log one
5+
6+
Test Two
7+
8+
Duplicate Test
9+
Log first occurrence
10+
11+
Duplicate Test
12+
Log second occurrence with the same name on purpose
13+
14+
*** Keyword ***
15+
Bad Section Header
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
*** Settings ***
2+
Documentation Distinct tag set for `discover tags` tests, including
3+
... variants that exercise Robot's tag normalisation.
4+
5+
*** Test Cases ***
6+
Smoke Login
7+
[Tags] smoke bug-1
8+
Log s1
9+
10+
Smoke Logout
11+
[Tags] smoke WIP
12+
Log s2
13+
14+
Regression Login
15+
[Tags] regression bug_1
16+
Log r1
17+
18+
Slow Path
19+
[Tags] slow
20+
Log sp
21+
22+
Bug Variant A
23+
[Tags] BUG1
24+
Log a
25+
26+
Bug Variant B
27+
[Tags] bug 1
28+
Log b

0 commit comments

Comments
 (0)