Skip to content

Commit b0681e8

Browse files
authored
Associate CTest tests with add_test() wrappers (#4490) (#4491)
When CTest tests are associated directly with `add_test()` calls, then using functions that wrap `add_test()` results in many tests linked to the exact same line of code. Instead, walk the CTest backtrace from the `add_test()` call and associate the test with the outermost stack frame.
1 parent 194805d commit b0681e8

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Improvements:
1616
- Add name de-mangling for C++ symbols in the Test Explorer view when running tests with coverage. [#4340](https://github.com/microsoft/vscode-cmake-tools/pull/4340) [@rjaegers](https://github.com/rjaegers)
1717
- No longer convert paths on lowercase on MacOS to enable cpp tools to resolve them. [#4325](https://github.com/microsoft/vscode-cmake-tools/pull/4325) [@tringenbach](https://github.com/tringenbach)
1818
- Speedup & reduce heap allocations in shlex split module function. Significant gains for mid-large compile_commands.json - CompilationDatabase construction. [#4458](https://github.com/microsoft/vscode-cmake-tools/pull/4458) [@borjamunozf](https://github.com/borjamunozf)
19+
- In the Test Explorer, associate CTest tests with outermost function or macro invocation that calls `add_test()` instead of with the `add_test()` call itself. [#4490](https://github.com/microsoft/vscode-cmake-tools/issues/4490) [@malsyned](https://github.com/malsyned)
1920

2021
Bug Fixes:
2122

src/ctest.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -835,11 +835,16 @@ export class CTestDriver implements vscode.Disposable {
835835
}
836836
}
837837

838-
if (!testDefFile && test.backtrace !== undefined && this.tests!.backtraceGraph.nodes[test.backtrace] !== undefined) {
838+
const nodes = this.tests!.backtraceGraph.nodes;
839+
if (!testDefFile && test.backtrace !== undefined && nodes[test.backtrace] !== undefined) {
839840
// Use the backtrace graph to find the file and line number
840841
// This finds the CMake module's file and line number and not the test file and line number
841-
testDefFile = this.tests!.backtraceGraph.files[this.tests!.backtraceGraph.nodes[test.backtrace].file];
842-
testDefLine = this.tests!.backtraceGraph.nodes[test.backtrace].line;
842+
let node = nodes[test.backtrace];
843+
while (node.parent !== undefined && nodes[node.parent].command !== undefined) {
844+
node = nodes[node.parent];
845+
}
846+
testDefFile = this.tests!.backtraceGraph.files[node.file];
847+
testDefLine = node.line;
843848
}
844849

845850
const testAndParentSuite = this.createTestItemAndSuiteTree(test.name, testExplorerRoot, initializedTestExplorer, testDefFile ? vscode.Uri.file(testDefFile) : undefined);

0 commit comments

Comments
 (0)