Skip to content

Commit

Permalink
Fix Swift Testing Capture Groups (#373)
Browse files Browse the repository at this point in the history
  • Loading branch information
cpisciotta authored Feb 11, 2025
1 parent ac0ed6c commit 6179579
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 55 deletions.
28 changes: 14 additions & 14 deletions Sources/XcbeautifyLib/CaptureGroups.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2010,7 +2010,7 @@ struct SwiftTestingRunStartedCaptureGroup: CaptureGroup {

/// Regular expression to capture the start of a test run.
/// $1 = message
static let regex = XCRegex(pattern: #"^.\s+(Test run started\.)$"#)
static let regex = XCRegex(pattern: #"^􀟈 (Test run started\.)$"#)

let message: String

Expand All @@ -2027,7 +2027,7 @@ struct SwiftTestingRunCompletionCaptureGroup: CaptureGroup {
/// Regular expression to capture the number of tests and total time.
/// $1 = number of tests
/// $2 = total time in seconds
static let regex = XCRegex(pattern: #"^.\s+Test run with (\d+) test(?:s)? passed after ([\d.]+) seconds\.$"#)
static let regex = XCRegex(pattern: #"^􁁛 Test run with (\d+) test(?:s)? passed after ([\d.]+) seconds\.$"#)

let numberOfTests: Int
let totalTime: String
Expand All @@ -2048,7 +2048,7 @@ struct SwiftTestingRunFailedCaptureGroup: CaptureGroup {
/// $1 = number of tests
/// $2 = total time in seconds
/// $3 = number of issues
static let regex = XCRegex(pattern: #"^.\s+Test run with (\d+) test(?:s)? failed after ([\d.]+) seconds with (\d+) issue[s]?\.$"#)
static let regex = XCRegex(pattern: #"^􀢄 Test run with (\d+) test(?:s)? failed after ([\d.]+) seconds with (\d+) issue[s]?\.$"#)

let numberOfTests: Int
let totalTime: String
Expand All @@ -2070,7 +2070,7 @@ struct SwiftTestingSuiteStartedCaptureGroup: CaptureGroup {

/// Regular expression to capture the start of a test suite.
/// $1 = suite name
static let regex = XCRegex(pattern: #"^.\s+Suite (.*) started\.$"#)
static let regex = XCRegex(pattern: #"^􀟈 Suite (.*) started\.$"#)

let suiteName: String

Expand All @@ -2086,7 +2086,7 @@ struct SwiftTestingTestStartedCaptureGroup: CaptureGroup {

/// Regular expression to capture the start of a test case.
/// $1 = test name
static let regex = XCRegex(pattern: #"^.\s+Test\s+(.*) started\.$"#)
static let regex = XCRegex(pattern: #"^􀟈 Test\s+(.*) started\.$"#)

let testName: String
let wholeMessage: String
Expand All @@ -2105,7 +2105,7 @@ struct SwiftTestingSuitePassedCaptureGroup: CaptureGroup {
/// Regular expression to capture the successful completion of a test suite.
/// $1 = suite name
/// $2 = total time taken in seconds
static let regex = XCRegex(pattern: #"^.\s+Suite (.*) passed after ([\d.]+) seconds\.$"#)
static let regex = XCRegex(pattern: #"^􁁛 Suite (.*) passed after ([\d.]+) seconds\.$"#)

let suiteName: String
let timeTaken: String
Expand All @@ -2126,7 +2126,7 @@ struct SwiftTestingSuiteFailedCaptureGroup: CaptureGroup {
/// $1 = suite name
/// $2 = total time taken in seconds
/// $3 = number of issues
static let regex = XCRegex(pattern: #"^.\s+Suite (.*) failed after ([\d.]+) seconds with (\d+) issue[s]?\.$"#)
static let regex = XCRegex(pattern: #"^􀢄 Suite (.*) failed after ([\d.]+) seconds with (\d+) issue[s]?\.$"#)

let suiteName: String
let timeTaken: String
Expand All @@ -2150,7 +2150,7 @@ struct SwiftTestingTestFailedCaptureGroup: CaptureGroup {
/// $1 = test name
/// $2 = time taken in seconds
/// $3 = number of issues
static let regex = XCRegex(pattern: #"^.\s+Test (?!run\s)(.*) failed after ([\d.]+) seconds with (\d+) issue[s]?\.$"#)
static let regex = XCRegex(pattern: #"^􀢄 Test (?!run\s)(.*) failed after ([\d.]+) seconds with (\d+) issue[s]?\.$"#)

let testName: String
let timeTaken: String
Expand All @@ -2173,7 +2173,7 @@ struct SwiftTestingTestPassedCaptureGroup: CaptureGroup {
/// Regular expression to capture the successful completion of a test case.
/// $1 = test name
/// $2 = time taken in seconds
static let regex = XCRegex(pattern: #"^.*Test (?!run\s)(.*) passed after ([\d.]+) seconds\.$"#)
static let regex = XCRegex(pattern: #"^􁁛 Test (?!run\s)(.*) passed after ([\d.]+) seconds\.$"#)

let testName: String
let timeTaken: String
Expand All @@ -2192,7 +2192,7 @@ struct SwiftTestingTestSkippedCaptureGroup: CaptureGroup {

/// Regular expression to capture a skipped test case.
/// $1 = test name
static let regex = XCRegex(pattern: #"^.\s+Test (.*) skipped\.$"#)
static let regex = XCRegex(pattern: #"^􀙟 Test (.*) skipped\.$"#)

let testName: String

Expand All @@ -2209,7 +2209,7 @@ struct SwiftTestingTestSkippedReasonCaptureGroup: CaptureGroup {
/// Regular expression to capture a skipped test case with a reason.
/// $1 = test name
/// $2 = optional reason
static let regex = XCRegex(pattern: #"^.\s+Test (.*) skipped(?:\s*:\s*"(.*)")?$"#)
static let regex = XCRegex(pattern: #"^􀙟 Test (.*) skipped(?:\s*:\s*"(.*)")?$"#)

let testName: String
let reason: String?
Expand All @@ -2228,7 +2228,7 @@ struct SwiftTestingIssueCaptureGroup: CaptureGroup {
/// Regular expression to capture the symbol, test description, and issue details.
/// $1 = test description
/// $2 = issue details
static let regex = XCRegex(pattern: #"^.\s+Test (.*?) recorded an issue(?: at (.*))?$"#)
static let regex = XCRegex(pattern: #"^􀢄 Test (.*?) recorded an issue(?: at (.*))?$"#)

let testDescription: String
let issueDetails: String?
Expand All @@ -2248,7 +2248,7 @@ struct SwiftTestingIssueArgumentCaptureGroup: CaptureGroup {
/// Regular expression to capture the symbol, test description, and optional number of arguments.
/// $1 = test description
/// $2 = number of arguments (optional)
static let regex = XCRegex(pattern: #"^.\s+Test (.*?) recorded an issue(?: with (\d+) arguments?)?"#)
static let regex = XCRegex(pattern: #"^􀢄 Test (.*?) recorded an issue(?: with (\d+) arguments?)?"#)

let testDescription: String
let numberOfArguments: Int?
Expand All @@ -2267,7 +2267,7 @@ struct SwiftTestingPassingArgumentCaptureGroup: CaptureGroup {

/// Regular expression to capture the symbol and number of arguments.
/// $1 = number of arguments
static let regex = XCRegex(pattern: #"^.\s+Passing (\d+) argument[s]?.*$"#)
static let regex = XCRegex(pattern: #"^􀟈 Passing (\d+) argument[s]?.*$"#)

let numberOfArguments: Int

Expand Down
18 changes: 9 additions & 9 deletions Tests/XcbeautifyLibTests/ParserTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ final class ParserTests: XCTestCase {
}

func testMatchSwiftTestingRunStarted() throws {
let input = "􀟈 Test run started."
let input = "􀟈 Test run started."
let captureGroup = try XCTUnwrap(parser.parse(line: input) as? SwiftTestingRunStartedCaptureGroup)
XCTAssertEqual(captureGroup.message, "Test run started.")
}
Expand All @@ -184,7 +184,7 @@ final class ParserTests: XCTestCase {
}

func testMatchSwiftTestingRunFailed() throws {
let input = "􀢄 Test run with 7 tests failed after 4.8 seconds with 2 issues."
let input = "􀢄 Test run with 7 tests failed after 4.8 seconds with 2 issues."
let captureGroup = try XCTUnwrap(parser.parse(line: input) as? SwiftTestingRunFailedCaptureGroup)
XCTAssertEqual(captureGroup.numberOfTests, 7)
XCTAssertEqual(captureGroup.totalTime, "4.8")
Expand All @@ -204,43 +204,43 @@ final class ParserTests: XCTestCase {
}

func testMatchSwiftTestingSuitePassed() throws {
let input = "􁁛 Suite TestSuiteName passed after 5.3 seconds."
let input = "􁁛 Suite TestSuiteName passed after 5.3 seconds."
let captureGroup = try XCTUnwrap(parser.parse(line: input) as? SwiftTestingSuitePassedCaptureGroup)
XCTAssertEqual(captureGroup.suiteName, "TestSuiteName")
XCTAssertEqual(captureGroup.timeTaken, "5.3")
}

func testMatchSwiftTestingSuiteFailed() throws {
let input = #"􀢄 Suite "AnotherTestSuite" failed after 6.4 seconds with 3 issues."#
let input = #"􀢄 Suite "AnotherTestSuite" failed after 6.4 seconds with 3 issues."#
let captureGroup = try XCTUnwrap(parser.parse(line: input) as? SwiftTestingSuiteFailedCaptureGroup)
XCTAssertEqual(captureGroup.suiteName, "\"AnotherTestSuite\"")
XCTAssertEqual(captureGroup.timeTaken, "6.4")
XCTAssertEqual(captureGroup.numberOfIssues, 3)
}

func testMatchSwiftTestingTestFailed() throws {
let input = #"􀢄 Test "SomeTest" failed after 2.5 seconds with 1 issue."#
let input = #"􀢄 Test "SomeTest" failed after 2.5 seconds with 1 issue."#
let captureGroup = try XCTUnwrap(parser.parse(line: input) as? SwiftTestingTestFailedCaptureGroup)
XCTAssertEqual(captureGroup.testName, "\"SomeTest\"")
XCTAssertEqual(captureGroup.timeTaken, "2.5")
XCTAssertEqual(captureGroup.numberOfIssues, 1)
}

func testMatchSwiftTestingTestPassed() throws {
let input = "􁁛 Test SampleTest passed after 3.0 seconds."
let input = "􁁛 Test SampleTest passed after 3.0 seconds."
let captureGroup = try XCTUnwrap(parser.parse(line: input) as? SwiftTestingTestPassedCaptureGroup)
XCTAssertEqual(captureGroup.testName, "SampleTest")
XCTAssertEqual(captureGroup.timeTaken, "3.0")
}

func testMatchSwiftTestingTestSkipped() throws {
let input = #"􀙟 Test "SkippedTest" skipped."#
let input = #"􀙟 Test "SkippedTest" skipped."#
let captureGroup = try XCTUnwrap(parser.parse(line: input) as? SwiftTestingTestSkippedCaptureGroup)
XCTAssertEqual(captureGroup.testName, "\"SkippedTest\"")
}

func testMatchSwiftTestingTestSkippedWithReason() throws {
let input = #"􀙟 Test "SkippedTest" skipped: "Not relevant for this platform.""#
let input = #"􀙟 Test "SkippedTest" skipped: "Not relevant for this platform.""#
let captureGroup = try XCTUnwrap(parser.parse(line: input) as? SwiftTestingTestSkippedReasonCaptureGroup)
XCTAssertEqual(captureGroup.testName, "\"SkippedTest\"")
XCTAssertEqual(captureGroup.reason, "Not relevant for this platform.")
Expand All @@ -254,7 +254,7 @@ final class ParserTests: XCTestCase {
}

func testMatchSwiftTestingPassingArgument() throws {
let input = #"􀟈 Passing 2 arguments input → "argument1, argument2""#
let input = #"􀟈 Passing 2 arguments input → "argument1, argument2""#
let captureGroup = try XCTUnwrap(parser.parse(line: input) as? SwiftTestingPassingArgumentCaptureGroup)
XCTAssertEqual(captureGroup.numberOfArguments, 2)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -672,42 +672,42 @@ final class AzureDevOpsPipelinesRendererTests: XCTestCase {
}

func testSwiftTestingRunCompletion() {
let input = #"􁁛 Test run with 5 tests passed after 12.345 seconds."#
let input = #"􁁛 Test run with 5 tests passed after 12.345 seconds."#
let formatted = logFormatted(input)
let expectedOutput = "Test run with 5 tests passed after 12.345 seconds"
XCTAssertEqual(formatted, expectedOutput)
}

func testSwiftTestingRunFailed() {
let input = #"􀢄 Test run with 10 tests failed after 15.678 seconds with 3 issues."#
let input = #"􀢄 Test run with 10 tests failed after 15.678 seconds with 3 issues."#
let formatted = logFormatted(input)
let expectedOutput = "##vso[task.logissue type=error]Test run with 10 tests failed after 15.678 seconds with 3 issue(s)"
XCTAssertEqual(formatted, expectedOutput)
}

func testSwiftTestingSuiteFailed() {
let input = #"􀢄 Suite "MyTestSuite" failed after 8.456 seconds with 2 issues."#
let input = #"􀢄 Suite "MyTestSuite" failed after 8.456 seconds with 2 issues."#
let formatted = logFormatted(input)
let expectedOutput = "##vso[task.logissue type=error]Suite \"MyTestSuite\" failed after 8.456 seconds with 2 issue(s)"
XCTAssertEqual(formatted, expectedOutput)
}

func testSwiftTestingTestFailed() {
let input = #"􀢄 Test "myTest" failed after 1.234 seconds with 1 issue."#
let input = #"􀢄 Test "myTest" failed after 1.234 seconds with 1 issue."#
let formatted = logFormatted(input)
let expectedOutput = "##vso[task.logissue type=error]\"myTest\" (1.234 seconds) 1 issue(s)"
XCTAssertEqual(formatted, expectedOutput)
}

func testSwiftTestingTestSkipped() {
let input = #"􀙟 Test myTest() skipped."#
let input = #"􀙟 Test myTest() skipped."#
let formatted = logFormatted(input)
let expectedOutput = " ⊘ myTest() skipped"
XCTAssertEqual(formatted, expectedOutput)
}

func testSwiftTestingTestSkippedReason() {
let input = #"􀙟 Test myTest() skipped: "Reason for skipping""#
let input = #"􀙟 Test myTest() skipped: "Reason for skipping""#
let formatted = logFormatted(input)
let expectedOutput = " ⊘ myTest() skipped (Reason for skipping)"
XCTAssertEqual(formatted, expectedOutput)
Expand All @@ -721,7 +721,7 @@ final class AzureDevOpsPipelinesRendererTests: XCTestCase {
}

func testSwiftTestingIssueArguments() {
let input = #"􀢄 Test "myTest" recorded an issue with 2 arguments."#
let input = #"􀢄 Test "myTest" recorded an issue with 2 arguments."#
let formatted = logFormatted(input)
let expectedOutput = "##vso[task.logissue type=error]Recorded an issue (2) argument(s)"
XCTAssertEqual(formatted, expectedOutput)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -669,42 +669,42 @@ final class GitHubActionsRendererTests: XCTestCase {
}

func testSwiftTestingRunCompletion() {
let input = #"􁁛 Test run with 5 tests passed after 12.345 seconds."#
let input = #"􁁛 Test run with 5 tests passed after 12.345 seconds."#
let formatted = logFormatted(input)
let expectedOutput = "::notice ::Test run with 5 tests passed after 12.345 seconds"
XCTAssertEqual(formatted, expectedOutput)
}

func testSwiftTestingRunFailed() {
let input = #"􀢄 Test run with 10 tests failed after 15.678 seconds with 3 issues."#
let input = #"􀢄 Test run with 10 tests failed after 15.678 seconds with 3 issues."#
let formatted = logFormatted(input)
let expectedOutput = "::error ::Test run with 10 tests failed after 15.678 seconds with 3 issue(s)"
XCTAssertEqual(formatted, expectedOutput)
}

func testSwiftTestingSuiteFailed() {
let input = #"􀢄 Suite "MyTestSuite" failed after 8.456 seconds with 2 issues."#
let input = #"􀢄 Suite "MyTestSuite" failed after 8.456 seconds with 2 issues."#
let formatted = logFormatted(input)
let expectedOutput = "::error ::Suite \"MyTestSuite\" failed after 8.456 seconds with 2 issue(s)"
XCTAssertEqual(formatted, expectedOutput)
}

func testSwiftTestingTestFailed() {
let input = #"􀢄 Test "myTest" failed after 1.234 seconds with 1 issue."#
let input = #"􀢄 Test "myTest" failed after 1.234 seconds with 1 issue."#
let formatted = logFormatted(input)
let expectedOutput = "::error ::\"myTest\" (1.234 seconds) 1 issue(s)"
XCTAssertEqual(formatted, expectedOutput)
}

func testSwiftTestingTestSkipped() {
let input = #"􀙟 Test myTest() skipped."#
let input = #"􀙟 Test myTest() skipped."#
let formatted = logFormatted(input)
let expectedOutput = "::notice ::Skipped myTest()"
XCTAssertEqual(formatted, expectedOutput)
}

func testSwiftTestingTestSkippedReason() {
let input = #"􀙟 Test myTest() skipped: "Reason for skipping""#
let input = #"􀙟 Test myTest() skipped: "Reason for skipping""#
let formatted = logFormatted(input)
let expectedOutput = "::notice ::Skipped myTest().(Reason for skipping)"
XCTAssertEqual(formatted, expectedOutput)
Expand All @@ -718,7 +718,7 @@ final class GitHubActionsRendererTests: XCTestCase {
}

func testSwiftTestingIssueArguments() {
let input = #"􀢄 Test "myTest" recorded an issue with 2 arguments."#
let input = #"􀢄 Test "myTest" recorded an issue with 2 arguments."#
let formatted = logFormatted(input)
let expectedOutput = "::error ::Recorded an issue (2) argument(s)"
XCTAssertEqual(formatted, expectedOutput)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ final class TeamCityRendererTests: XCTestCase {
}

func testSwiftTestingRunCompletion() {
let input = #"􁁛 Test run with 5 tests passed after 12.345 seconds."#
let input = #"􁁛 Test run with 5 tests passed after 12.345 seconds."#
let output = "##teamcity[message text=\'Test run succeeded\' errorDetails=\'Test run with 5 tests passed after 12.345 seconds\' status=\'INFO\']\nTest run succeeded"
XCTAssertEqual(noColoredFormatted(input), output)
}
Expand All @@ -687,33 +687,33 @@ final class TeamCityRendererTests: XCTestCase {
}

func testSwiftTestingRunFailed() {
let input = #"􀢄 Test run with 10 tests failed after 15.678 seconds with 3 issues."#
let input = #"􀢄 Test run with 10 tests failed after 15.678 seconds with 3 issues."#
let formatted = noColoredFormatted(input)
let expectedOutput = "##teamcity[message text=\'Test run failed\' errorDetails=\'10 tests failed after 15.678 seconds with 3 issue(s)\' status=\'ERROR\']\nTest run failed"
XCTAssertEqual(formatted, expectedOutput)
}

func testSwiftTestingSuiteFailed() {
let input = #"􀢄 Suite "MyTestSuite" failed after 8.456 seconds with 2 issues."#
let input = #"􀢄 Suite "MyTestSuite" failed after 8.456 seconds with 2 issues."#
let formatted = noColoredFormatted(input)

XCTAssertEqual(formatted, "##teamcity[message text=\'Suite failed\' errorDetails=\'\"MyTestSuite\" failed after 8.456 seconds with 2 issue(s)\' status=\'ERROR\']\nSuite failed")
}

func testSwiftTestingTestFailed() {
let input = #"􀢄 Test "myTest" failed after 1.234 seconds with 1 issue."#
let input = #"􀢄 Test "myTest" failed after 1.234 seconds with 1 issue."#
let formatted = noColoredFormatted(input)
XCTAssertEqual(formatted, "##teamcity[message text=\'Test failed\' errorDetails=\'\"myTest\" (1.234 seconds) 1 issue(s)\' status=\'ERROR\']\nTest failed")
}

func testSwiftTestingTestSkipped() {
let input = #"􀙟 Test "myTest" skipped."#
let input = #"􀙟 Test "myTest" skipped."#
let formatted = noColoredFormatted(input)
XCTAssertEqual(formatted, "##teamcity[message text=\'Test skipped|n\"myTest\"\' status=\'WARNING\']\nTest skipped")
}

func testSwiftTestingTestSkippedReason() {
let input = #"􀙟 Test "myTest" skipped: "Reason for skipping""#
let input = #"􀙟 Test "myTest" skipped: "Reason for skipping""#
let formatted = noColoredFormatted(input)
XCTAssertEqual(formatted, "##teamcity[message text=\'Test skipped|n\"myTest\" (Reason for skipping)\' status=\'WARNING\']\nTest skipped")
}
Expand All @@ -725,7 +725,7 @@ final class TeamCityRendererTests: XCTestCase {
}

func testSwiftTestingIssueArguments() {
let input = #"􀢄 Test "myTest" recorded an issue with 2 arguments."#
let input = #"􀢄 Test "myTest" recorded an issue with 2 arguments."#
let formatted = noColoredFormatted(input)
XCTAssertEqual(formatted, "##teamcity[message text=\'Recorded an issue|n(2 argument(s))\' status=\'WARNING\']\nRecorded an issue")
}
Expand Down
Loading

0 comments on commit 6179579

Please sign in to comment.