Skip to content

Commit 400a5f8

Browse files
Add GoogleTest failure pattern to default ctest failurePatterns (#4756)
* Initial plan * Add GoogleTest failure pattern to default ctest failurePatterns Add a third default failure pattern `(.*?):(\\d+): *(Failure.*)` that matches GoogleTest's output format (e.g., `file.cpp:135: Failure`). The existing patterns only matched lines containing `error:`, which doesn't match GoogleTest's failure format, resulting in non-clickable file paths in the Test Results panel. Fixes #4589 Co-authored-by: hanniavalera <90047725+hanniavalera@users.noreply.github.com> * Restore .npmrc file that was accidentally deleted Co-authored-by: hanniavalera <90047725+hanniavalera@users.noreply.github.com> * Fix GoogleTest test assertions to avoid cross-platform URI path issues On Linux CI, vscode.Uri.file('D:/...').path returns '/D:/...' (with leading slash), causing assertion failures. Use Unix-style paths in test cases since the tests validate regex pattern matching, not URI path handling. Co-authored-by: hanniavalera <90047725+hanniavalera@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: hanniavalera <90047725+hanniavalera@users.noreply.github.com>
1 parent 16e3df7 commit 400a5f8

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Improvements:
1717
- Allow preset modification commands to target CMakeUserPresets.json. The target file is determined by the focused editor, or by prompting the user when both files exist. [#4564](https://github.com/microsoft/vscode-cmake-tools/issues/4564)
1818

1919
Bug Fixes:
20+
- Fix Test Results panel not hyperlinking file paths for GoogleTest failures. The default `cmake.ctest.failurePatterns` now includes a pattern matching GoogleTest's `file:line: Failure` output format. [#4589](https://github.com/microsoft/vscode-cmake-tools/issues/4589)
2021
- Fix wrong path created for artifact when parsing code model using CMake File API. [#3015](https://github.com/microsoft/vscode-cmake-tools/issues/3015)
2122
- Fix garbled characters (Mojibake) in the Output panel when MSVC outputs UTF-8 (e.g., with `/utf-8`) on non-UTF-8 Windows systems. When `cmake.outputLogEncoding` is `auto`, the build output is now validated as UTF-8 before falling back to the system code page. [#4520](https://github.com/microsoft/vscode-cmake-tools/issues/4520)
2223
- Fix CMakePresets.json discovery failing in multi-folder workspaces when the presets file is in a subdirectory specified by `cmake.sourceDirectory`. [#4727](https://github.com/microsoft/vscode-cmake-tools/issues/4727)

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2528,6 +2528,9 @@
25282528
},
25292529
{
25302530
"regexp": "(.*?)\\((\\d+)\\): *(?:error: *)(.*)"
2531+
},
2532+
{
2533+
"regexp": "(.*?):(\\d+): *(Failure.*)"
25312534
}
25322535
],
25332536
"markdownDescription": "%cmake-tools.configuration.cmake.ctest.failurePatterns.markdownDescription%",

test/unit-tests/ctest.test.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,38 @@ suite('CTest test', () => {
6767
assertMessageFields(result6, '/path/to/file', 46, 0, 'the message', undefined, undefined);
6868
});
6969

70+
test('Find GoogleTest failure patterns in output', () => {
71+
// Default patterns from package.json
72+
const defaultPatterns = [
73+
{ regexp: '(.*?):(\\d+): *(?:error: *)(.*)' },
74+
{ regexp: '(.*?)\\((\\d+)\\): *(?:error: *)(.*)' },
75+
{ regexp: '(.*?):(\\d+): *(Failure.*)' }
76+
];
77+
78+
// GoogleTest failure format
79+
const gtestOutput = '/path/to/TestFile.cpp:135: Failure\nValue of: expr\n Actual: true\nExpected: false\n';
80+
const gtestResults = searchOutputForFailures(defaultPatterns, gtestOutput);
81+
expect(gtestResults.length).to.eq(1);
82+
assertMessageFields(gtestResults[0], '/path/to/TestFile.cpp', 134, 0, 'Failure', undefined, undefined);
83+
84+
// GCC/Clang error format still works (no regression)
85+
const gccOutput = '/path/to/file.cpp:10: error: undefined reference\n';
86+
const gccResults = searchOutputForFailures(defaultPatterns, gccOutput);
87+
expect(gccResults.length).to.eq(1);
88+
assertMessageFields(gccResults[0], '/path/to/file.cpp', 9, 0, 'undefined reference', undefined, undefined);
89+
90+
// MSVC error format still works (no regression)
91+
const msvcOutput = '/project/file.cpp(20): error: something went wrong\n';
92+
const msvcResults = searchOutputForFailures(defaultPatterns, msvcOutput);
93+
expect(msvcResults.length).to.eq(1);
94+
assertMessageFields(msvcResults[0], '/project/file.cpp', 19, 0, 'something went wrong', undefined, undefined);
95+
96+
// Lines without "Failure" or "error:" should not match
97+
const noMatchOutput = '[ RUN ] MyTest.TestCase\n[ PASSED ] 1 test.\n';
98+
const noMatchResults = searchOutputForFailures(defaultPatterns, noMatchOutput);
99+
expect(noMatchResults.length).to.eq(0);
100+
});
101+
70102
function assertMessageFields(
71103
tm: TestMessage,
72104
file: string, line: number, column: number, message: string,

0 commit comments

Comments
 (0)