Skip to content

Fix ${cmake.testProgram} launch from the Run and Debug view (#4574) - #5070

Merged
Omotola merged 2 commits into
mainfrom
dev/oakeredolu/4574-ctest-launch-picker
Sep 3, 2026
Merged

Fix ${cmake.testProgram} launch from the Run and Debug view (#4574)#5070
Omotola merged 2 commits into
mainfrom
dev/oakeredolu/4574-ctest-launch-picker

Conversation

@Omotola

@Omotola Omotola commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

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.json configuration from the Run and Debug view (F5) provides no test context, so the literal placeholder string reached the debug adapter and failed with:

launch: program '${cmake.testProgram}' does not exist

Many users (see the issue thread) expected F5 to work.

Fix

Add a DebugConfigurationProvider (CTestLaunchConfigurationProvider) registered for cppdbg, cppvsdbg, lldb, lldb-dap and gdb. Its resolveDebugConfiguration runs before variable substitution, so it can intercept the still-literal ${cmake.test*} placeholders:

  • Configs that don't reference the placeholders are returned unchanged (fast path), so there is no double prompt for the Test Explorer flow (which substitutes before startDebugging) or for unrelated launches.
  • When placeholders are present, 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.
  • If the project is unconfigured / no tests are found / the picked test has no resolvable program, it shows a clear error and aborts the launch instead of passing a broken config to the debugger.

The substitution logic previously inlined in debugCTestImpl is extracted into a shared applyTestPlaceholderSubstitutions helper used by both entry points.

Notes

  • The CTest info accessors now guard against tests without a command.
  • Placeholder detection walks the configuration recursively rather than relying on JSON.stringify.
  • Docs (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) Launch config 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).

Recording 2026-09-02 135618

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
@azure-pipelines

Copy link
Copy Markdown
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
@Omotola
Omotola merged commit 182a294 into main Sep 3, 2026
37 of 38 checks passed
@Omotola
Omotola deleted the dev/oakeredolu/4574-ctest-launch-picker branch September 3, 2026 18:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] launch:program '${cmake.testProgram}' does not exist

2 participants