From 5ee906fa8160a959d6bf2ae608d0c2b5563e5439 Mon Sep 17 00:00:00 2001 From: Xinyu Sui Date: Tue, 18 Jul 2023 17:00:06 -0700 Subject: [PATCH] Support CTest labels --- package.json | 2 +- src/ctest.ts | 32 +++++++++++++++++++++++++------- yarn.lock | 8 ++++---- 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index 34b2df0f0..8a7c8e747 100644 --- a/package.json +++ b/package.json @@ -2574,7 +2574,7 @@ "@types/rimraf": "^3.0.0", "@types/sinon": "~9.0.10", "@types/tmp": "^0.2.0", - "@types/vscode": "1.60.0", + "@types/vscode": "1.63.0", "@types/which": "~2.0.0", "@types/xml2js": "^0.4.8", "@types/uuid": "~8.3.3", diff --git a/src/ctest.ts b/src/ctest.ts index 5089d5b5f..9000c1f08 100644 --- a/src/ctest.ts +++ b/src/ctest.ts @@ -105,7 +105,7 @@ interface CTestInfo { backtrace: number; command: string[]; name: string; - properties: { name: string; value: string }[]; + properties: { name: string; value: string | string[] }[]; }[]; version: { major: number; minor: number }; } @@ -552,18 +552,36 @@ export class CTestDriver implements vscode.Disposable { this.tests = JSON.parse(result.stdout) ?? undefined; if (this.tests && this.tests.kind === 'ctestInfo') { this.tests.tests.forEach(test => { + let testItem: vscode.TestItem; if (test.backtrace !== undefined && this.tests!.backtraceGraph.nodes[test.backtrace] !== undefined) { const testDefFile = this.tests!.backtraceGraph.files[this.tests!.backtraceGraph.nodes[test.backtrace].file]; const testDefLine = this.tests!.backtraceGraph.nodes[test.backtrace].line; - const testItem = initializedTestExplorer.createTestItem(test.name, test.name, vscode.Uri.file(testDefFile)); + testItem = initializedTestExplorer.createTestItem(test.name, test.name, vscode.Uri.file(testDefFile)); if (testDefLine !== undefined) { testItem.range = new vscode.Range(new vscode.Position(testDefLine - 1, 0), new vscode.Position(testDefLine - 1, 0)); } - testExplorerRoot.children.add(testItem); } else { - const testItem = initializedTestExplorer.createTestItem(test.name, test.name); - testExplorerRoot.children.add(testItem); + testItem = initializedTestExplorer.createTestItem(test.name, test.name); } + + const testTags: vscode.TestTag[] = []; + if (test.properties) { + for (const property of test.properties) { + if (property.name === "LABELS") { + if (util.isString(property.value)) { + testTags.push(new vscode.TestTag(property.value)); + } else { + testTags.push(...property.value.map(v => new vscode.TestTag(v))); + } + } + } + } + + if (testTags.length !== 0) { + testItem.tags = [...testItem.tags, ...testTags]; + } + + testExplorerRoot.children.add(testItem); }); }; } @@ -587,7 +605,7 @@ export class CTestDriver implements vscode.Disposable { /** * Filters out duplicate tests, i.e., both the parent and child are requested */ - private uniqueTests(tests: vscode.TestItem[]): vscode.TestItem[] { + private uniqueTests(tests: readonly vscode.TestItem[]): vscode.TestItem[] { const parents = new Set(); tests.forEach(t => { if (!t.parent) { @@ -902,7 +920,7 @@ export class CTestDriver implements vscode.Disposable { */ private ensureTestExplorerInitialized(): vscode.TestController { if (!testExplorer) { - testExplorer = vscode.tests.createTestController('cmakeToolsCTest', 'CTest'); + testExplorer = vscode.tests.createTestController('cmake-tools.CTest', 'CTest'); // Cast to any since this is not supported yet in the API we use. (testExplorer as any).refreshHandler = () => vscode.commands.executeCommand('cmake.refreshTestsAll'); diff --git a/yarn.lock b/yarn.lock index fc754b96b..04a2067d4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -444,10 +444,10 @@ resolved "https://registry.npmjs.org/@types/uuid/-/uuid-8.3.4.tgz#bd86a43617df0594787d38b735f55c805becf1bc" integrity sha512-c/I8ZRb51j+pYGAu5CrFMRxqZ2ke4y2grEBO5AUjgSkSk+qT2Ea+OdWElz/OiMf5MNpn2b17kuVBwZLQJXzihw== -"@types/vscode@1.60.0": - version "1.60.0" - resolved "https://registry.yarnpkg.com/@types/vscode/-/vscode-1.60.0.tgz#9330c317691b4f53441a18b598768faeeb71618a" - integrity sha512-wZt3VTmzYrgZ0l/3QmEbCq4KAJ71K3/hmMQ/nfpv84oH8e81KKwPEoQ5v8dNCxfHFVJ1JabHKmCvqdYOoVm1Ow== +"@types/vscode@1.63.0": + version "1.63.0" + resolved "https://registry.yarnpkg.com/@types/vscode/-/vscode-1.63.0.tgz#3bddb5b79a93e8fcdd420bb00f7066658c79c70c" + integrity sha512-iePu1axOi5WSThV6l2TYcciBIpAlMarjBC8H0y8L8ocsZLxh7MttzwFU3pjoItF5fRVGxHS0Hsvje9jO3yJsfw== "@types/which@~2.0.0": version "2.0.1"