Skip to content

Commit cc5e5fe

Browse files
OmotolaCopilot
andcommitted
Fix: filter flag+value pairs when removing \ args
When filtering out args containing \ (for calls without a test name), also remove the preceding flag argument (e.g., --output-log) to avoid leaving dangling flags that cause ctest to fail. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent fa6470e commit cc5e5fe

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

src/ctest.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -462,9 +462,25 @@ export class CTestDriver implements vscode.Disposable {
462462

463463
// When testName is not provided, filter out args containing ${testName} to avoid
464464
// passing literal "${testName}" to ctest (e.g., during test discovery or batch runs).
465+
// Also removes the preceding flag arg (e.g., "--output-log") to avoid dangling flags.
465466
const testNamePlaceholder = '${testName}';
466-
const filterTestNameArgs = (args: string[]): string[] =>
467-
testName !== undefined ? args : args.filter(arg => !arg.includes(testNamePlaceholder));
467+
const filterTestNameArgs = (args: string[]): string[] => {
468+
if (testName !== undefined) {
469+
return args;
470+
}
471+
const filtered: string[] = [];
472+
for (let i = 0; i < args.length; i++) {
473+
if (args[i].includes(testNamePlaceholder)) {
474+
// Also remove preceding flag arg if it starts with '-'
475+
if (filtered.length > 0 && filtered[filtered.length - 1].startsWith('-')) {
476+
filtered.pop();
477+
}
478+
} else {
479+
filtered.push(args[i]);
480+
}
481+
}
482+
return filtered;
483+
};
468484

469485
const initialArgs = await Promise.all(filterTestNameArgs(this.ws.config.ctestDefaultArgs).map(async (value) => expandString(value, opts)));
470486
const additionalArgs = await Promise.all(filterTestNameArgs(this.ws.config.ctestArgs).map(async (value) => expandString(value, opts)));

0 commit comments

Comments
 (0)