Skip to content

Build tests prior to executing them#4881

Open
mcodilla wants to merge 19 commits intomainfrom
building-tests2
Open

Build tests prior to executing them#4881
mcodilla wants to merge 19 commits intomainfrom
building-tests2

Conversation

@mcodilla
Copy link
Copy Markdown
Contributor

@mcodilla mcodilla commented Apr 13, 2026

Original PR: #4523

Addresses the following issue: #4515

This PR

  • Solves merge conflicts
  • Modifies buildTestTargets() to correctly compute target name
  • Validates changes

Brian Cody and others added 9 commits July 22, 2025 16:10
…ting

- BLOCKER: Replace path.relative() with executableTargets lookup to map
  test program paths to actual CMake target names. The previous approach
  produced file paths (e.g. 'tests/my_test') instead of target names
  (e.g. 'my_test'), causing cmake --build --target to fail.
- BLOCKER: Fix accmulatedTestList.concat() no-op by using push(...) so
  tests are properly marked as errored on build failure.
- MAJOR: Check return value of recursive getTestTargets() call so child
  failures propagate correctly to the caller.
- MINOR: Add guard for empty testProgram() return to prevent nonsensical
  build targets from empty strings.
- MINOR: Fix typo accmulatedTestList -> accumulatedTestList.
- MINOR: Remove extra whitespace in for statement and redundant
  .toString() call.
- NIT: Remove trailing semicolon after for...of block.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@mcodilla mcodilla marked this pull request as ready for review April 13, 2026 21:15
@mcodilla mcodilla changed the title draft Build tests prior to executing them Apr 13, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates CTest Explorer “build before run” behavior so running/debugging selected tests builds their required executables instead of defaulting to the ALL target, improving usability for partial builds and excluded-from-all tests.

Changes:

  • Add logic in CTestDriver to collect test executables per CMakeProject and invoke targeted builds.
  • Map test executable paths back to CMake target names using project.executableTargets (with a filename-based fallback).
  • Add a CHANGELOG entry describing the new build-before-test behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 13 comments.

File Description
src/ctest.ts Adds target discovery and per-project targeted build step before running/debugging tests.
CHANGELOG.md Documents the user-visible behavior change for build-before-run in the test workflow.

Comment thread src/ctest.ts
Comment on lines +1939 to +1945
const buildResult = await project.build(accumulatedTargets, false, false);
if (buildResult.exitCode !== 0) {
success = false;
}
} catch (e) {
success = false;
}
Copy link

Copilot AI Apr 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The catch (e) here suppresses the underlying build error details. Please log the error (or include relevant information such as the target list and exit code) so users can diagnose why build-before-test failed.

Copilot uses AI. Check for mistakes.
Comment thread src/ctest.ts
Comment thread src/ctest.ts
Comment thread src/ctest.ts
Comment thread src/ctest.ts
Comment thread src/ctest.ts Outdated
Comment thread src/ctest.ts
Comment thread CHANGELOG.md Outdated
Comment thread src/ctest.ts Outdated
Comment thread src/ctest.ts Outdated
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.

[Feature] Customize or change the CMake command run when using "Run Test" from CTest Explorer

4 participants