From ba8a594a2a89f3cbdd269ac0b0dbb7ba00871c36 Mon Sep 17 00:00:00 2001 From: Guillaume Peillex Date: Sat, 28 Jun 2025 19:19:52 +0200 Subject: [PATCH 1/2] Fix 4345 * Flatten the request.include and request.exclude test collections so that all leafs (i.e tests and not suites) are collected * Create a new test collection that is the exclusion of request.exclude tests from the request.include ones --- src/ctest.ts | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/ctest.ts b/src/ctest.ts index 4a3635708..8c937dc9d 100644 --- a/src/ctest.ts +++ b/src/ctest.ts @@ -1077,8 +1077,29 @@ export class CTestDriver implements vscode.Disposable { return; } - const requestedTests = request.include || this.testItemCollectionToArray(testExplorer.items); - const tests = this.uniqueTests(requestedTests); + // Helper to collect all leaf tests from a list of test items (suites or tests) + function flattenTests(items: readonly vscode.TestItem[]): vscode.TestItem[] { + const result: vscode.TestItem[] = []; + function collect(item: vscode.TestItem) { + if (item.children.size === 0) { + result.push(item); + } else { + item.children.forEach(collect); + } + } + items.forEach(collect); + return result; + } + + // Expand suites in include and exclude to all their leaf tests + const requestedTests = request.include + ? flattenTests(request.include) + : this.testItemCollectionToArray(testExplorer.items).flatMap(item => flattenTests([item])); + const excludeTests = request.exclude ? flattenTests(request.exclude) : []; + const excludeSet = new Set(excludeTests.map(item => item.id)); + + const filteredRequestedTests = requestedTests.filter(test => !excludeSet.has(test.id)); + const tests = this.uniqueTests(filteredRequestedTests); if (!await this.checkTestPreset(tests)) { return; From b37d59dc71037117f9797b809450ba8af1510260 Mon Sep 17 00:00:00 2001 From: Hannia Valera Date: Thu, 25 Sep 2025 14:52:44 -0500 Subject: [PATCH 2/2] added changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2fd7eef6e..bf19b297b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,7 @@ Bug Fixes: - Fix issue with switching to presets during Quick Start. [#4409](https://github.com/microsoft/vscode-cmake-tools/issues/4409) - Fix bug that shows empty lines in Pinned Commands view. [#4406](https://github.com/microsoft/vscode-cmake-tools/issues/4406) - Fix Compiler Warnings not shown in Problems Window [#4567]https://github.com/microsoft/vscode-cmake-tools/issues/4567 +- Fix bug in which clicking "Run Test" for filtered tests executed all tests instead [#4501](https://github.com/microsoft/vscode-cmake-tools/pull/4501) [@hippo91](https://github.com/hippo91) ## 1.20.53