Skip to content

Commit 5f07d3b

Browse files
Fix some ctest issues (#4866)
* Avoid overwriting of existing tests * Remove flickering of test tree * Ensure uri and label are updated if necessary * Update changelog.md * Update changelog.md --------- Co-authored-by: Ottmar Zittlau <[email protected]>
1 parent d274ffb commit 5f07d3b

2 files changed

Lines changed: 30 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ Bug Fixes:
9494
- Fix bug in which CTest is unable to run large amount of tests in parallel due to regex exceeding command line length limits [#4829](https://github.com/microsoft/vscode-cmake-tools/issues/4829) [@theuke](https://github.com/theuke)
9595
- Fix malformed devcontainer.json used for working with GitHub Codespaces and similar environments [#4588](https://github.com/microsoft/vscode-cmake-tools/pull/4588) [@kaladron](https://github.com/kaladron)
9696
- Fix hang in `buildWithResult` tool when there isn't a configure preset selected. [#4857](https://github.com/microsoft/vscode-cmake-tools/issues/4857)
97+
- Fix hiding of tests if test suite name and target name are the same when setting "Test Suite Delimiter" to `\` [#4408](https://github.com/microsoft/vscode-cmake-tools/issues/4408) [@ottmar-zittlau](https://github.com/ottmar-zittlau)
9798

9899
## 1.22.28
99100

src/ctest.ts

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,7 +1017,17 @@ export class CTestDriver implements vscode.Disposable {
10171017
parentSuiteItem = suiteItem;
10181018
}
10191019
}
1020-
const testItem = initializedTestExplorer.createTestItem(testName, testLabel, uri);
1020+
const existing = parentSuiteItem.children.get(testName);
1021+
let testItem: vscode.TestItem;
1022+
if (existing && existing.uri?.toString() === uri?.toString()) {
1023+
testItem = existing;
1024+
if (testItem.label !== testLabel) {
1025+
testItem.label = testLabel;
1026+
}
1027+
} else {
1028+
// Create or recreate testItem if the uri is stale or it does not already exist
1029+
testItem = initializedTestExplorer.createTestItem(testName, testLabel, uri);
1030+
}
10211031
return { test: testItem, parentSuite: parentSuiteItem };
10221032
}
10231033

@@ -1030,20 +1040,22 @@ export class CTestDriver implements vscode.Disposable {
10301040
log.error(localize('folder.not.found.in.test.explorer', 'Folder is not found in Test Explorer: {0}', sourceDir));
10311041
return;
10321042
}
1033-
// Clear all children and re-add later
1034-
testExplorerRoot.children.replace([]);
1043+
1044+
// Keep track of all currently active test ids to remove the invalid ones afterwards
1045+
const activeTestIDs = new Set<string>();
10351046

10361047
if (!ctestArgs) {
10371048
// Happens when testPreset is not selected
10381049
const testItem = initializedTestExplorer.createTestItem(testPresetRequired, localize('test.preset.required', 'Select a test preset to discover tests'));
1039-
testExplorerRoot.children.add(testItem);
1050+
testExplorerRoot.children.replace([testItem]);
10401051
return;
10411052
}
10421053

10431054
if (testType === "LegacyCTest" && this.legacyTests !== undefined) {
10441055
// Legacy CTest tests
10451056
for (const test of this.legacyTests) {
10461057
testExplorerRoot.children.add(initializedTestExplorer.createTestItem(test.name, test.name));
1058+
activeTestIDs.add(test.name);
10471059
}
10481060
} else if (testType === "CTestInfo" && this.tests !== undefined) {
10491061
if (this.tests && this.tests.kind === 'ctestInfo') {
@@ -1077,12 +1089,24 @@ export class CTestDriver implements vscode.Disposable {
10771089
if (testTags.length !== 0) {
10781090
testItem.tags = [...testItem.tags, ...testTags];
10791091
}
1080-
10811092
parentSuiteItem.children.add(testItem);
1093+
activeTestIDs.add(testItem.id);
10821094
});
10831095
};
10841096
}
10851097

1098+
const removeDeletedTests = (collection: vscode.TestItemCollection) => {
1099+
collection.forEach((item: vscode.TestItem, collection: vscode.TestItemCollection) => {
1100+
if (item.children.size > 0) {
1101+
removeDeletedTests(item.children);
1102+
}
1103+
if (item.children.size === 0 && !activeTestIDs.has(item.id)) {
1104+
collection.delete(item.id);
1105+
}
1106+
});
1107+
};
1108+
1109+
removeDeletedTests(testExplorerRoot.children);
10861110
}
10871111

10881112
/**

0 commit comments

Comments
 (0)