Skip to content

feat: add ${cmake.testEnvironment} placeholder for CTest debug configurations - #4821

Merged
Omotola merged 8 commits into
mainfrom
copilot/add-cmake-test-environment-support
Mar 24, 2026
Merged

Omotola merged 8 commits into
mainfrom
copilot/add-cmake-test-environment-support

Conversation

Copilot AI commented Mar 16, 2026 •

Copy link
Copy Markdown
Contributor

This change addresses item #4572

This changes visible behavior

The following changes are proposed:

  • Add ${cmake.testEnvironment} launch.json placeholder that resolves CTest ENVIRONMENT test properties (set via set_tests_properties) into the [{ "name": "...", "value": "..." }] format expected by debug adapters
  • Automatically merge CTest ENVIRONMENT properties into the debug config when debugging tests without a launch.json
  • Add testEnvironment() parser to CTestDriver that converts CTest's ["A=B", "C=D"] format to a key-value map
  • Add replaceValueInObject() helper for replacing string placeholders with non-string values (arrays/objects)

Other Notes/Information

Usage in launch.json:

{
    "name": "(ctest) Launch",
    "type": "cppdbg",
    "request": "launch",
    "program": "${cmake.testProgram}",
    "args": ["${cmake.testArgs}"],
    "cwd": "${cmake.testWorkingDirectory}",
    "environment": "${cmake.testEnvironment}"
}

Two debug paths are covered:

  • With launch.json (debugCTestImpl): ${cmake.testEnvironment} is replaced with the environment array before launching
  • Without launch.json (debugCTest in cmakeProject.ts): CTest environment is merged into the auto-generated debug config alongside the existing configure/launch environment

The cmake.testEnvironment VS Code setting (for overriding CTest runtime env) already existed and is unrelated — this adds the per-test ENVIRONMENT property resolution for debug sessions.

Original prompt

This section details on the original issue you should resolve

<issue_title>[Feature] Support a new cmake.testEnvironment similar to cmake.testArgs</issue_title>
<issue_description>### Request Overview

I have a somewhat complicated CTest configuration that requires setting a number of environment variables while tests are being executed. The VS Code test explorer works correctly to run tests and report success; and I can attempt to debug one using the configuration outlined here: https://github.com/microsoft/vscode-cmake-tools/blob/main/docs/debug-launch.md#debugging-tests, but when debugging the tests, the necessary environment variables (like LD_LIBRARY_PATH) aren't set.

vscode-cmake-tools supports exposing cmake.testArgs to the launch config. I am requesting a similar cmake.testEnvironment that would allow me to pass through any environment variables that CTest has set during test execution.

It looks like this is less trivial to extract from CTest, because the format provided by the json-v1 format doesn't match the format launch.json takes - CTest provides something like:

"properties": [
    {
        "name": "ENVIRONMENT",
        "value": ["A=B", "C=D"...]
    }
]

and launch.json is expecting

  "environment": [{ "name": "A", "value": "B" }, { "name": "C", "value": "D" ],

Additional Information

No response</issue_description>

<agent_instructions>Create a PR to fix this issue and cite issue #4572 in the changelog</agent_instructions>

Comments on the Issue (you are Copilot in this section)


💬 Send tasks to Copilot coding agent from Slack and Teams to turn conversations into code. Copilot posts an update in your thread when it's finished.

… ENVIRONMENT in debug config (#4572)

Co-authored-by: Omotola <8052624+Omotola@users.noreply.github.com>
Copilot AI changed the title [WIP] [Feature] Support a new cmake.testEnvironment setting Mar 16, 2026
Copilot AI requested a review from Omotola March 16, 2026 23:24
@Omotola
Omotola marked this pull request as ready for review March 21, 2026 00:43
@Omotola

Omotola commented Mar 21, 2026

Copy link
Copy Markdown
Contributor

Validated locally. The test explorer is now able to access test variables passed to ctest.
image

@Omotola
Omotola merged commit f9b1a80 into main Mar 24, 2026
4 checks passed
@Omotola
Omotola deleted the copilot/add-cmake-test-environment-support branch March 24, 2026 19:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants