Skip to content

Commit a9f6f24

Browse files
authored
feat: Limit number of splits by the delimiter (#4357)
Allow to specify a max number of splits by the delimiter. See #4355
1 parent a1ceda2 commit a9f6f24

File tree

5 files changed

+37
-4
lines changed

5 files changed

+37
-4
lines changed

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2264,6 +2264,12 @@
22642264
"markdownDescription": "%cmake-tools.configuration.cmake.ctest.testSuiteDelimiter.markdownDescription%",
22652265
"scope": "machine-overridable"
22662266
},
2267+
"cmake.ctest.testSuiteDelimiterMaxOccurrence": {
2268+
"type": "number",
2269+
"default": 0,
2270+
"markdownDescription": "%cmake-tools.configuration.cmake.ctest.testSuiteDelimiterMaxOccurrence.markdownDescription%",
2271+
"scope": "machine-overridable"
2272+
},
22672273
"cmake.ctest.debugLaunchTarget": {
22682274
"type": "string",
22692275
"default": null,

package.nls.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@
127127
"Markdown text between `` should not be translated or localized (they represent literal text) and the capitalization, spacing, and punctuation (including the ``) should not be altered."
128128
]
129129
},
130+
"cmake-tools.configuration.cmake.ctest.testSuiteDelimiterMaxOccurrence.markdownDescription": {
131+
"message": "Maximum number of times the delimiter may be used to split the name of the test. `0` means no limit."
132+
},
130133
"cmake-tools.configuration.cmake.ctest.debugLaunchTarget.description": "Target name from launch.json to start when debugging a test with CTest. By default and in case of a non-existing target, this will show a picker with all available targets.",
131134
"cmake-tools.configuration.cmake.parseBuildDiagnostics.description": "Parse compiler output for warnings and errors.",
132135
"cmake-tools.configuration.cmake.enabledOutputParsers.description": {

src/config.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ export interface ExtensionConfigurationSettings {
174174
buildToolArgs: string[];
175175
parallelJobs: number;
176176
ctestPath: string;
177-
ctest: { parallelJobs: number; allowParallelJobs: boolean; testExplorerIntegrationEnabled: boolean; testSuiteDelimiter: string; debugLaunchTarget: string | null };
177+
ctest: { parallelJobs: number; allowParallelJobs: boolean; testExplorerIntegrationEnabled: boolean; testSuiteDelimiter: string; testSuiteDelimiterMaxOccurrence: number; debugLaunchTarget: string | null };
178178
parseBuildDiagnostics: boolean;
179179
enabledOutputParsers: string[];
180180
debugConfig: CppDebugConfiguration;
@@ -394,6 +394,9 @@ export class ConfigurationReader implements vscode.Disposable {
394394
get testSuiteDelimiter(): string {
395395
return this.configData.ctest.testSuiteDelimiter;
396396
}
397+
get testSuiteDelimiterMaxOccurrence(): number {
398+
return this.configData.ctest.testSuiteDelimiterMaxOccurrence;
399+
}
397400
get ctestDebugLaunchTarget(): string | null {
398401
return this.configData.ctest.debugLaunchTarget;
399402
}
@@ -621,7 +624,7 @@ export class ConfigurationReader implements vscode.Disposable {
621624
parallelJobs: new vscode.EventEmitter<number>(),
622625
ctestPath: new vscode.EventEmitter<string>(),
623626
cpackPath: new vscode.EventEmitter<string>(),
624-
ctest: new vscode.EventEmitter<{ parallelJobs: number; allowParallelJobs: boolean; testExplorerIntegrationEnabled: boolean; testSuiteDelimiter: string; debugLaunchTarget: string | null }>(),
627+
ctest: new vscode.EventEmitter<{ parallelJobs: number; allowParallelJobs: boolean; testExplorerIntegrationEnabled: boolean; testSuiteDelimiter: string; testSuiteDelimiterMaxOccurrence: number; debugLaunchTarget: string | null }>(),
625628
parseBuildDiagnostics: new vscode.EventEmitter<boolean>(),
626629
enabledOutputParsers: new vscode.EventEmitter<string[]>(),
627630
debugConfig: new vscode.EventEmitter<CppDebugConfiguration>(),

src/ctest.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -694,10 +694,30 @@ export class CTestDriver implements vscode.Disposable {
694694
let parentSuiteItem = testExplorerRoot;
695695
let testLabel = testName;
696696

697+
function limited_split(regexString: string, subject: string, maxCount: number): string[] {
698+
if (maxCount === 0) {
699+
maxCount = Number.MAX_SAFE_INTEGER;
700+
}
701+
const delimiterRegExp = new RegExp(regexString, 'dg');
702+
const parts = [];
703+
let lastStart = 0;
704+
while (parts.length < maxCount) {
705+
const match: any = delimiterRegExp.exec(subject);
706+
if (match === null || match.indices === null) {
707+
break;
708+
}
709+
710+
parts.push(subject.substring(lastStart, match.indices[0][0]));
711+
lastStart = match.indices[0][1];
712+
}
713+
714+
parts.push(subject.substring(lastStart));
715+
return parts;
716+
}
717+
697718
// If a suite delimiter is set, create a suite tree
698719
if (this.ws.config.testSuiteDelimiter) {
699-
const delimiterRegExp = new RegExp(this.ws.config.testSuiteDelimiter);
700-
const parts = testName.split(delimiterRegExp);
720+
const parts = limited_split(this.ws.config.testSuiteDelimiter, testName, this.ws.config.testSuiteDelimiterMaxOccurrence);
701721
testLabel = parts.pop() || testName; // The last part is the test label
702722

703723
// Create a suite item for each suite ID part if it doesn't exist yet at that tree level

test/unit-tests/config.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ function createConfig(conf: Partial<ExtensionConfigurationSettings>): Configurat
3030
allowParallelJobs: false,
3131
testExplorerIntegrationEnabled: true,
3232
testSuiteDelimiter: '',
33+
testSuiteDelimiterMaxOccurrence: 0,
3334
debugLaunchTarget: null
3435
},
3536
parseBuildDiagnostics: true,

0 commit comments

Comments
 (0)