Skip to content

Commit 46406b8

Browse files
committed
implement running and debugging testcases from testcontroller
1 parent 8203db3 commit 46406b8

File tree

7 files changed

+317
-61
lines changed

7 files changed

+317
-61
lines changed

package.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"url": "https://github.com/d-biehl/robotcode.git"
1111
},
1212
"engines": {
13-
"vscode": "^1.59.0"
13+
"vscode": "^1.60.0"
1414
},
1515
"categories": [
1616
"Programming Languages",
@@ -395,19 +395,19 @@
395395
"devDependencies": {
396396
"@types/glob": "^7.1.4",
397397
"@types/mocha": "^9.0.0",
398-
"@types/node": "^16.7.6",
399-
"@types/vscode": "^1.59.0",
400-
"@typescript-eslint/eslint-plugin": "^4.29.3",
401-
"@typescript-eslint/parser": "^4.29.3",
398+
"@types/node": "^16.7.10",
399+
"@types/vscode": "^1.60.0",
400+
"@typescript-eslint/eslint-plugin": "^4.30.0",
401+
"@typescript-eslint/parser": "^4.30.0",
402402
"eslint": "^7.32.0",
403403
"eslint-config-airbnb": "^18.2.1",
404404
"eslint-config-prettier": "^8.3.0",
405405
"eslint-config-standard": "^16.0.3",
406-
"eslint-config-standard-with-typescript": "20.0.0",
406+
"eslint-config-standard-with-typescript": "21.0.1",
407407
"eslint-plugin-import": "^2.24.2",
408408
"eslint-plugin-jsx-a11y": "^6.4.1",
409409
"eslint-plugin-node": "^11.1.0",
410-
"eslint-plugin-prettier": "^3.4.1",
410+
"eslint-plugin-prettier": "^4.0.0",
411411
"eslint-plugin-promise": "^5.1.0",
412412
"eslint-plugin-react": "^7.25.1",
413413
"eslint-plugin-react-hooks": "^4.2.0",
@@ -416,10 +416,10 @@
416416
"prettier": "^2.3.2",
417417
"ts-loader": "^9.2.5",
418418
"typescript": "^4.4.2",
419-
"vsce": "^1.96.2",
419+
"vsce": "^1.96.3",
420420
"vscode-debugadapter-testsupport": "^1.49.0",
421421
"vscode-test": "^1.6.1",
422-
"webpack": "^5.51.1",
422+
"webpack": "^5.51.2",
423423
"webpack-cli": "^4.8.0"
424424
}
425425
}

robotcode/debugger/__main__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@ async def start_debugpy_async() -> None:
188188
args = [
189189
"--listener",
190190
f"robotcode.debugger.listeners.ListenerV2:no_debug={repr(no_debug)}",
191+
"--listener",
192+
"robotcode.debugger.listeners.ListenerV3",
191193
*args,
192194
]
193195

robotcode/debugger/listeners.py

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
from typing import Any, Dict
1+
from typing import Any, Dict, Iterator, Union, cast
22

33
from .debugger import Debugger
4+
from .types import Event
45

56

67
class ListenerV2:
@@ -11,6 +12,14 @@ def __init__(self, no_debug: bool = False) -> None:
1112
self.debug = not no_debug
1213

1314
def start_suite(self, name: str, attributes: Dict[str, Any]) -> None:
15+
Debugger.instance().send_event(
16+
self,
17+
Event(
18+
event="robotStarted",
19+
body=dict(attributes),
20+
),
21+
)
22+
1423
Debugger.instance().start_output_group(name, attributes, "SUITE")
1524

1625
if self.debug:
@@ -22,7 +31,23 @@ def end_suite(self, name: str, attributes: Dict[str, Any]) -> None:
2231

2332
Debugger.instance().end_output_group(name, attributes)
2433

34+
Debugger.instance().send_event(
35+
self,
36+
Event(
37+
event="robotEnded",
38+
body=dict(attributes),
39+
),
40+
)
41+
2542
def start_test(self, name: str, attributes: Dict[str, Any]) -> None:
43+
Debugger.instance().send_event(
44+
self,
45+
Event(
46+
event="robotStarted",
47+
body=dict(attributes),
48+
),
49+
)
50+
2651
Debugger.instance().start_output_group(name, attributes, "TEST")
2752

2853
if self.debug:
@@ -34,6 +59,14 @@ def end_test(self, name: str, attributes: Dict[str, Any]) -> None:
3459

3560
Debugger.instance().end_output_group(name, attributes)
3661

62+
Debugger.instance().send_event(
63+
self,
64+
Event(
65+
event="robotEnded",
66+
body=dict(attributes),
67+
),
68+
)
69+
3770
def start_keyword(self, name: str, attributes: Dict[str, Any]) -> None:
3871
Debugger.instance().start_output_group(
3972
f"{name}({', '.join(repr(v) for v in attributes.get('args', []))})",
@@ -82,3 +115,29 @@ def debug_file(self, path: str) -> None:
82115

83116
def close(self) -> None:
84117
pass
118+
119+
120+
class ListenerV3:
121+
ROBOT_LISTENER_API_VERSION = "3"
122+
123+
def start_suite(self, data: Any, result: Any) -> None:
124+
from robot.running import TestCase, TestSuite
125+
126+
def enqueue(item: Union[TestSuite, TestCase]) -> Iterator[str]:
127+
if isinstance(item, TestSuite):
128+
for s in item.suites:
129+
yield from enqueue(s)
130+
for s in item.tests:
131+
yield from enqueue(s)
132+
133+
yield item.longname
134+
135+
items = [i for i in enqueue(cast(TestSuite, data))]
136+
137+
Debugger.instance().send_event(
138+
self,
139+
Event(
140+
event="robotEnqueued",
141+
body={"items": items},
142+
),
143+
)

robotcode/language_server/robotframework/parts/discovering.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ async def get_tests_from_document(self, text_document: TextDocumentIdentifier, i
162162
return [
163163
TestItem(
164164
type="test",
165-
id=f"{id}.{v.longname}" if id else v.longname,
165+
id=f"{id}.{v.name}" if id else v.longname,
166166
label=v.name,
167167
uri=str(Uri.from_path(v.source)),
168168
range=Range(

vscode-client/debugmanager.ts

Lines changed: 28 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -188,49 +188,40 @@ export class DebugManager {
188188
this._disposables.dispose();
189189
}
190190

191-
static async debugSuiteOrTestcase(
192-
resource: string | vscode.Uri | undefined,
193-
testcases?: string | string[],
191+
static async runTests(
192+
folder: vscode.WorkspaceFolder,
193+
tests: string[],
194+
runId?: string,
194195
options?: vscode.DebugSessionOptions
195196
): Promise<void> {
196-
if (resource === undefined) return;
197+
if (tests.length) {
198+
const config = vscode.workspace.getConfiguration(CONFIG_SECTION, folder);
197199

198-
const uri = resource instanceof vscode.Uri ? resource : vscode.Uri.parse(resource);
200+
const args = [];
201+
args.push("--prerunmodifier");
199202

200-
const folder = vscode.workspace.getWorkspaceFolder(uri);
203+
args.push(`robotcode.debugger.modifiers.ByLongName:${tests.join(":")}`);
201204

202-
const config = vscode.workspace.getConfiguration(CONFIG_SECTION, folder);
203-
204-
const args = [];
205-
206-
if (testcases) {
207-
if (!(testcases instanceof Array)) {
208-
testcases = [testcases];
209-
}
210-
for (const testcase of testcases) {
211-
args.push("-t");
212-
args.push(testcase.toString());
213-
}
214-
}
215-
216-
const template = config.get("debug.defaultConfiguration", {});
205+
const template = config.get("debug.defaultConfiguration", {});
217206

218-
vscode.debug.startDebugging(
219-
folder,
220-
{
221-
...template,
222-
...{
223-
type: "robotcode",
224-
name: `robotcode: Suite: ${resource}${testcases ? ` Testcase: ${testcases}` : ""}`,
225-
request: "launch",
226-
cwd: folder?.uri.fsPath,
227-
target: uri.fsPath,
228-
args,
229-
console: config.get("debug.defaultConsole", "integratedTerminal"),
207+
await vscode.debug.startDebugging(
208+
folder,
209+
{
210+
...template,
211+
...{
212+
type: "robotcode",
213+
name: "robotcode: Run Tests",
214+
request: "launch",
215+
cwd: folder?.uri.fsPath,
216+
target: ".",
217+
args: args,
218+
console: config.get("debug.defaultConsole", "integratedTerminal"),
219+
runId: runId,
220+
},
230221
},
231-
},
232-
options
233-
);
222+
options
223+
);
224+
}
234225
}
235226

236227
static async attachPython(session: vscode.DebugSession, event: string, options?: { port: number }): Promise<void> {
@@ -264,7 +255,7 @@ export class DebugManager {
264255
}
265256
}
266257

267-
static async onRobotExited(
258+
private static async onRobotExited(
268259
session: vscode.DebugSession,
269260
outputFile?: string,
270261
logFile?: string,

vscode-client/extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export async function activateAsync(context: vscode.ExtensionContext): Promise<v
2121

2222
const debugManager = new DebugManager(context, pythonManager, languageClientManger, outputChannel);
2323

24-
const testControllerManger = new TestControllerManager(context, languageClientManger, outputChannel);
24+
const testControllerManger = new TestControllerManager(context, languageClientManger, debugManager, outputChannel);
2525

2626
context.subscriptions.push(
2727
pythonManager,

0 commit comments

Comments
 (0)