microsoft / microsoft/vscode-cmake-tools
[Feature] Fix limitation of defining testProgram from the COMMAND field of add_test
- Dominant language
- TypeScript
- Stars
- 1.7k
- Forks
- 546
- Avg merge
- 2d 16h
- Merged PRs (30d)
- 32
Description
### Request Overview
This is in relation to a problem I found when trying to remotely debug a test in VScode. There is a more detailed description of the problem in [CMake discussion](https://discourse.cmake.org/t/add-test-assumes-test-executable-is-first-string-after-command/15012). You can look there for more specifics of the issue.
Essentially, when you want to run a test remotely the first field after COMMAND in add_test() cannot be the executable because it is likely of the wrong architecture for the build host and will fail when executed. In the cmake tool extension the code expects that the first field will be assigned to the testProgram variable. This is wrong in a remote environment where the first field can not be the test executable.
In src/ctest.ts:
```
private testProgram(testName: string): string {
if (this.tests) {
for (const test of this.tests.tests) {
if (test.name === testName) {
return test.command[0];
}
}
} else if (this.legacyTests) {
for (const test of this.legacyTests) {
if (test.name === testName) {
return test.name;
}
}
}
return '';
}
```
I assume test.command[0] refers to the first field after the COMMAND property in add_test().
In my case where I want to run the tests remotely my first element is a shell script the second one is the executable. The rest are the arguments. This successfully runs the test on the remote host. If I try to assign testProgram to the program field in a launch.json configuration and try to launch a debug session of the test, it fails. The error is that the first element after COMMAND is not an appropriate file format. Which is correct since it is a shell script. If I change the COMMAND so the first element is the test executable followed by the arguments then I can successfully perform a remote debug of the test. But of course if I try to run the test it fails because it tries to run the test locally and then the test executable is the wrong architecture for the local build host.
I have hopes that CMake can be convinced to add some fields to add_start to specifically define the test executable and arguments. These can be used to define variables that can be used that I can use in a launch,json configuration, rather than trying to glean the values from the COMMAND field.
I am not sure how to go about getting CMake team's attention to see if this is reasonable. But, I wanted to make this feature request here so that if CMake can come up with a resolution the extension can be updated to take of advantage of the resolution so that remote debugging of tests can be done.
Thanks
Chris
### Additional Information
_No response_
Contributor guide
Research direction
Start with src/ctest.ts and the testProgram method, then trace how test.command and launch.json use the selected program. Review the linked CMake discussion to determine whether a separate test executable can be identified for remote debugging; done means remote test execution and debugging work without relying on command[0] or breaking local tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cmake, typescript
- Domain
- developer-experience, testing
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100