Fix ${cmake.testProgram} launch from the Run and Debug view (#4574) - #5070
Merged
Conversation
The ${cmake.testProgram}, ${cmake.testArgs}, ${cmake.testWorkingDirectory}
and ${cmake.testEnvironment} placeholders were only substituted in the Test
Explorer "Debug Test" flow, where a test name is known. Launching such a
configuration from the Run and Debug view (F5) passed the literal string to
the debugger, failing with "program '${cmake.testProgram}' does not exist".
Add a DebugConfigurationProvider (registered for cppdbg, cppvsdbg, lldb,
lldb-dap and gdb) that resolves these placeholders before variable
substitution. When no test context exists, it refreshes the discovered CTest
tests and prompts the user to pick one (auto-selecting when only one exists),
then substitutes the placeholders for that test. Configurations that don't
reference the placeholders (including those already substituted by the Test
Explorer flow) are returned unchanged, so there is no double prompt.
The resolver validates that the selected test maps to a real program and
reports a clear error otherwise, and the CTest info accessors guard against
tests without a command. Placeholder detection walks the configuration
recursively instead of relying on JSON.stringify.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: e55cc9b5-dc8d-413d-a219-8c6418ec1d25
Contributor
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
Resolve CHANGELOG.md conflict by keeping the #4574 entry alongside the #4267 and #5028 Bug Fixes entries from main. src/ctest.ts auto-merged; typecheck and the 22 ctest unit tests pass. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: e55cc9b5-dc8d-413d-a219-8c6418ec1d25
MacGyver Codilla (mcodilla)
approved these changes
Sep 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4574
Problem
The
${cmake.testProgram},${cmake.testArgs},${cmake.testWorkingDirectory}and${cmake.testEnvironment}placeholders are only meaningful for a specific CTest test. They were substituted exclusively in the Test Explorer "Debug Test" flow (debugCTestImpl), where a test name is known.Starting the same
launch.jsonconfiguration from the Run and Debug view (F5) provides no test context, so the literal placeholder string reached the debug adapter and failed with:Many users (see the issue thread) expected F5 to work.
Fix
Add a
DebugConfigurationProvider(CTestLaunchConfigurationProvider) registered forcppdbg,cppvsdbg,lldb,lldb-dapandgdb. ItsresolveDebugConfigurationruns before variable substitution, so it can intercept the still-literal${cmake.test*}placeholders:startDebugging) or for unrelated launches.The substitution logic previously inlined in
debugCTestImplis extracted into a sharedapplyTestPlaceholderSubstitutionshelper used by both entry points.Notes
command.JSON.stringify.docs/debug-launch.md) updated to describe the new F5 behavior and note that"presentation": { "hidden": true }still restricts a config to the Test Explorer only.Testing
Manually validated with a CTest project: F5 on a
(ctest) Launchconfig now shows a test picker, resolves${cmake.testProgram}to the real executable, passes${cmake.testArgs}, and the debugger attaches and hits breakpoints. The Test Explorer "Debug Test" path continues to work unchanged (no extra prompt).