Skip to content

Add line terminator to XCTest filter regex #1086

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,8 @@ struct MixedSwiftTestingSuite {
}

#endif

final class DuplicateSuffixTests: XCTestCase {
func testPassing() throws {}
func testPassingSuffix() throws {}
}
2 changes: 1 addition & 1 deletion src/TestExplorer/TestRunArguments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ export class TestRunArguments {
// Only add leaf items to the list of arguments to pass to the test runner.
if (this.isLeafTestItem(testItem, !!isXCTest)) {
if (isXCTest) {
xcTestArgs.push(testItem.id);
xcTestArgs.push(`${testItem.id}$`);
} else {
swiftTestArgs.push(testItem.id);
}
Expand Down
8 changes: 7 additions & 1 deletion src/debugger/buildConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,13 @@ export class TestingConfigurationFactory {
}

private addTestsToArgs(args: string[]): string[] {
return [...args, ...this.testList.flatMap(arg => ["--filter", regexEscapedString(arg)])];
return [
...args,
...this.testList.flatMap(arg => [
"--filter",
regexEscapedString(arg, new Set(["$", "^"])),
]),
];
}

private addXCTestExecutableTestsToArgs(args: string[]): string[] {
Expand Down
4 changes: 2 additions & 2 deletions src/utilities/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,10 +306,10 @@ const regexEscapedCharacters = new Set(["(", ")", "[", "]", ".", "$", "^", "?",
* @param string A string to escape
* @returns The escaped string
*/
export function regexEscapedString(string: string): string {
export function regexEscapedString(string: string, omitting?: Set<string>): string {
let result = "";
for (const c of string) {
if (regexEscapedCharacters.has(c)) {
if (regexEscapedCharacters.has(c) && (!omitting || !omitting.has(c))) {
result += `\\${c}`;
} else {
result += c;
Expand Down
19 changes: 19 additions & 0 deletions test/suite/testexplorer/TestExplorerIntegration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ suite("Test Explorer Suite", function () {
["testPassing()", "testFailing()", "testDisabled()"],
"testWithKnownIssue()",
"testWithKnownIssueAndUnknownIssue()",
"DuplicateSuffixTests",
["testPassing()", "testPassingSuffix()"],
],
]);
} else if (workspaceContext.swiftVersion.isLessThanOrEqual(new Version(5, 10, 0))) {
Expand All @@ -158,6 +160,8 @@ suite("Test Explorer Suite", function () {
[
"DebugReleaseTestSuite",
["testDebug", "testRelease"],
"DuplicateSuffixTests",
["testPassing", "testPassingSuffix"],
"FailingXCTestSuite",
["testFailing"],
"MixedXCTestSuite",
Expand Down Expand Up @@ -331,6 +335,21 @@ suite("Test Explorer Suite", function () {
});
});

suite("Only runs specified test", async function () {
const passingRun = await runTest(
testExplorer.controller,
TestKind.standard,
"PackageTests.DuplicateSuffixTests/testPassing"
);

assertTestResults(passingRun, {
passed: [
"PackageTests.DuplicateSuffixTests",
"PackageTests.DebugReleaseTestSuite/testPassing",
],
});
});

suite("Runs multiple", function () {
const numIterations = 5;
const windowMock = mockNamespace(vscode, "window");
Expand Down
7 changes: 7 additions & 0 deletions test/suite/utilities/utilities.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,13 @@ suite("Utilities Test Suite", () => {
);
});

test("should escape a string that omits some characters", () => {
assert.strictEqual(
regexEscapedString(".^$|()?[]/:", new Set(["^", "$", "a"])),
"\\.^$\\|\\(\\)\\?\\[\\]\\/\\:"
);
});

test("should return an empty string when input is an empty string", () => {
assert.strictEqual(regexEscapedString(""), "");
});
Expand Down