Skip to content

Commit 1418143

Browse files
committed
Format Test Capture Groups
1 parent 6822557 commit 1418143

File tree

5 files changed

+100
-114
lines changed

5 files changed

+100
-114
lines changed

Sources/XcbeautifyLib/CaptureGroups.swift

+25-17
Original file line numberDiff line numberDiff line change
@@ -443,18 +443,20 @@ struct ExecutedWithoutSkippedCaptureGroup: ExecutedCaptureGroup {
443443
/// $2 = number of failures
444444
/// $3 = number of unexpected failures
445445
/// $4 = wall clock time in seconds (e.g. 0.295)
446-
static let regex = Regex(pattern: #"^\s*Executed\s(\d+)\stest[s]?,\swith\s(\d+)\sfailure[s]?\s\((\d+)\sunexpected\)\sin\s\d+\.\d{3}\s\((\d+\.\d{3})\)\sseconds"#)
446+
static let regex = Regex(pattern: #"^\s*(Executed\s(\d+)\stest[s]?,\swith\s(\d+)\sfailure[s]?\s\((\d+)\sunexpected\)\sin\s\d+\.\d{3}\s\((\d+\.\d{3})\)\sseconds.*)$"#)
447447

448+
let wholeResult: String
448449
let numberOfTests: Int
449450
let numberOfSkipped = 0
450451
let numberOfFailures: Int
451452
let numberOfUnexpectedFailures: Int
452453
let wallClockTimeInSeconds: Double
453454

454455
init?(groups: [String]) {
455-
assert(groups.count >= 4)
456-
guard let _numberOfTests = groups[safe: 0], let _numberOfFailures = groups[safe: 1], let _numberOfUnexpectedFailures = groups[safe: 2], let _wallClockTimeInSeconds = groups[safe: 3] else { return nil }
456+
assert(groups.count >= 5)
457+
guard let wholeResult = groups[safe: 0], let _numberOfTests = groups[safe: 1], let _numberOfFailures = groups[safe: 2], let _numberOfUnexpectedFailures = groups[safe: 3], let _wallClockTimeInSeconds = groups[safe: 4] else { return nil }
457458
guard let numberOfTests = Int(_numberOfTests), let numberOfFailures = Int(_numberOfFailures), let numberOfUnexpectedFailures = Int(_numberOfUnexpectedFailures), let wallClockTimeInSeconds = Double(_wallClockTimeInSeconds) else { return nil }
459+
self.wholeResult = wholeResult
458460
self.numberOfTests = numberOfTests
459461
self.numberOfFailures = numberOfFailures
460462
self.numberOfUnexpectedFailures = numberOfUnexpectedFailures
@@ -471,18 +473,20 @@ struct ExecutedWithSkippedCaptureGroup: ExecutedCaptureGroup {
471473
/// $3 = number of failures
472474
/// $4 = number of unexpected failures
473475
/// $5 = wall clock time in seconds (e.g. 0.295)
474-
static let regex = Regex(pattern: #"^\s*Executed\s(\d+)\stest[s]?,\swith\s(\d+)\stest[s]?\sskipped\sand\s(\d+)\sfailure[s]?\s\((\d+)\sunexpected\)\sin\s\d+\.\d{3}\s\((\d+\.\d{3})\)\sseconds"#)
476+
static let regex = Regex(pattern: #"^\s*(Executed\s(\d+)\stest[s]?,\swith\s(\d+)\stest[s]?\sskipped\sand\s(\d+)\sfailure[s]?\s\((\d+)\sunexpected\)\sin\s\d+\.\d{3}\s\((\d+\.\d{3})\)\sseconds.*)$"#)
475477

478+
let wholeResult: String
476479
let numberOfTests: Int
477480
let numberOfSkipped: Int
478481
let numberOfFailures: Int
479482
let numberOfUnexpectedFailures: Int
480483
let wallClockTimeInSeconds: Double
481484

482485
init?(groups: [String]) {
483-
assert(groups.count >= 5)
484-
guard let _numberOfTests = groups[safe: 0], let _numberOfSkipped = groups[safe: 1], let _numberOfFailures = groups[safe: 2], let _numberOfUnexpectedFailures = groups[safe: 3], let _wallClockTimeInSeconds = groups[safe: 4] else { return nil }
486+
assert(groups.count >= 6)
487+
guard let wholeResult = groups[safe: 0], let _numberOfTests = groups[safe: 1], let _numberOfSkipped = groups[safe: 2], let _numberOfFailures = groups[safe: 3], let _numberOfUnexpectedFailures = groups[safe: 4], let _wallClockTimeInSeconds = groups[safe: 5] else { return nil }
485488
guard let numberOfTests = Int(_numberOfTests), let numberOfSkipped = Int(_numberOfSkipped), let numberOfFailures = Int(_numberOfFailures), let numberOfUnexpectedFailures = Int(_numberOfUnexpectedFailures), let wallClockTimeInSeconds = Double(_wallClockTimeInSeconds) else { return nil }
489+
self.wholeResult = wholeResult
486490
self.numberOfTests = numberOfTests
487491
self.numberOfSkipped = numberOfSkipped
488492
self.numberOfFailures = numberOfFailures
@@ -1115,18 +1119,20 @@ struct TestsRunCompletionCaptureGroup: CaptureGroup {
11151119
/// $2 = result
11161120
/// $3 = time
11171121
#if os(Linux)
1118-
static let regex = Regex(pattern: #"^\s*Test Suite '(.*)' (finished|passed|failed) at (.*)"#)
1122+
static let regex = Regex(pattern: #"^\s*(Test Suite '(.*)' (finished|passed|failed) at (.*).*)"#)
11191123
#else
1120-
static let regex = Regex(pattern: #"^\s*Test Suite '(?:.*\/)?(.*[ox]ctest.*)' (finished|passed|failed) at (.*)"#)
1124+
static let regex = Regex(pattern: #"^\s*(Test Suite '(?:.*\/)?(.*[ox]ctest.*)' (finished|passed|failed) at (.*).*)"#)
11211125
#endif
11221126

1127+
let wholeResult: String
11231128
let suite: String
11241129
let result: String
11251130
let time: String
11261131

11271132
init?(groups: [String]) {
1128-
assert(groups.count >= 3)
1129-
guard let suite = groups[safe: 0], let result = groups[safe: 1], let time = groups[safe: 2] else { return nil }
1133+
assert(groups.count >= 4)
1134+
guard let wholeResult = groups[safe: 0], let suite = groups[safe: 1], let result = groups[safe: 2], let time = groups[safe: 3] else { return nil }
1135+
self.wholeResult = wholeResult
11301136
self.suite = suite
11311137
self.result = result
11321138
self.time = time
@@ -1174,25 +1180,27 @@ struct TestSuiteStartCaptureGroup: CaptureGroup {
11741180

11751181
struct TestSuiteAllTestsPassedCaptureGroup: CaptureGroup {
11761182
static let outputType: OutputType = .result
1177-
static let regex = Regex(pattern: #"^\s*Test Suite 'All tests' passed at"#)
1183+
static let regex = Regex(pattern: #"^\s*(Test Suite 'All tests' passed at.*)"#)
11781184

1179-
private init() { }
1185+
let wholeResult: String
11801186

11811187
init?(groups: [String]) {
11821188
assert(groups.count >= 0)
1183-
self.init()
1189+
guard let wholeResult = groups[safe: 0] else { return nil }
1190+
self.wholeResult = wholeResult
11841191
}
11851192
}
11861193

11871194
struct TestSuiteAllTestsFailedCaptureGroup: CaptureGroup {
11881195
static let outputType: OutputType = .result
1189-
static let regex = Regex(pattern: #"^\s*Test Suite 'All tests' failed at"#)
1196+
static let regex = Regex(pattern: #"^\s*(Test Suite 'All tests' failed at.*)"#)
11901197

1191-
private init() { }
1198+
let wholeResult: String
11921199

11931200
init?(groups: [String]) {
1194-
assert(groups.count >= 0)
1195-
self.init()
1201+
assert(groups.count >= 1)
1202+
guard let wholeResult = groups[safe: 0] else { return nil }
1203+
self.wholeResult = wholeResult
11961204
}
11971205
}
11981206

Sources/XcbeautifyLib/Renderers/OutputRendering.swift

+15-15
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ protocol OutputRendering {
2222
func formatCursor(group: CursorCaptureGroup) -> String?
2323
func formatDuplicateLocalizedStringKey(group: DuplicateLocalizedStringKeyCaptureGroup) -> String
2424
func formatError(group: ErrorCaptureGroup) -> String
25-
func formatExecutedWithoutSkipped(group: ExecutedWithoutSkippedCaptureGroup) -> String?
26-
func formatExecutedWithSkipped(group: ExecutedWithSkippedCaptureGroup) -> String?
25+
func formatExecutedWithoutSkipped(group: ExecutedWithoutSkippedCaptureGroup) -> String
26+
func formatExecutedWithSkipped(group: ExecutedWithSkippedCaptureGroup) -> String
2727
func formatFailingTest(group: FailingTestCaptureGroup) -> String
2828
func formatFileMissingError(group: FileMissingErrorCaptureGroup) -> String
2929
func formatGenerateCoverageData(group: GenerateCoverageDataCaptureGroup) -> String
@@ -64,9 +64,9 @@ protocol OutputRendering {
6464
func formatTestCaseSkipped(group: TestCaseSkippedCaptureGroup) -> String
6565
func formatTestCasePending(group: TestCasePendingCaptureGroup) -> String
6666
func formatTestCasesStarted(group: TestCaseStartedCaptureGroup) -> String?
67-
func formatTestsRunCompletion(group: TestsRunCompletionCaptureGroup) -> String?
68-
func formatTestSuiteAllTestsFailed(group: TestSuiteAllTestsFailedCaptureGroup) -> String?
69-
func formatTestSuiteAllTestsPassed(group: TestSuiteAllTestsPassedCaptureGroup) -> String?
67+
func formatTestsRunCompletion(group: TestsRunCompletionCaptureGroup) -> String
68+
func formatTestSuiteAllTestsFailed(group: TestSuiteAllTestsFailedCaptureGroup) -> String
69+
func formatTestSuiteAllTestsPassed(group: TestSuiteAllTestsPassedCaptureGroup) -> String
7070
func formatTestSuiteStart(group: TestSuiteStartCaptureGroup) -> String
7171
func formatTestSuiteStarted(group: TestSuiteStartedCaptureGroup) -> String
7272
func formatTIFFUtil(group: TIFFutilCaptureGroup) -> String?
@@ -335,12 +335,12 @@ extension OutputRendering {
335335
nil
336336
}
337337

338-
func formatExecutedWithoutSkipped(group: ExecutedWithoutSkippedCaptureGroup) -> String? {
339-
nil
338+
func formatExecutedWithoutSkipped(group: ExecutedWithoutSkippedCaptureGroup) -> String {
339+
group.wholeResult
340340
}
341341

342-
func formatExecutedWithSkipped(group: ExecutedWithSkippedCaptureGroup) -> String? {
343-
nil
342+
func formatExecutedWithSkipped(group: ExecutedWithSkippedCaptureGroup) -> String {
343+
group.wholeResult
344344
}
345345

346346
func formatGenerateCoverageData(group: GenerateCoverageDataCaptureGroup) -> String {
@@ -490,16 +490,16 @@ extension OutputRendering {
490490
nil
491491
}
492492

493-
func formatTestsRunCompletion(group: TestsRunCompletionCaptureGroup) -> String? {
494-
nil
493+
func formatTestsRunCompletion(group: TestsRunCompletionCaptureGroup) -> String {
494+
group.wholeResult
495495
}
496496

497-
func formatTestSuiteAllTestsFailed(group: TestSuiteAllTestsFailedCaptureGroup) -> String? {
498-
nil
497+
func formatTestSuiteAllTestsFailed(group: TestSuiteAllTestsFailedCaptureGroup) -> String {
498+
group.wholeResult
499499
}
500500

501-
func formatTestSuiteAllTestsPassed(group: TestSuiteAllTestsPassedCaptureGroup) -> String? {
502-
nil
501+
func formatTestSuiteAllTestsPassed(group: TestSuiteAllTestsPassedCaptureGroup) -> String {
502+
group.wholeResult
503503
}
504504

505505
func formatTestSuiteStart(group: TestSuiteStartCaptureGroup) -> String {

Tests/XcbeautifyLibTests/RendererTests/GitHubActionsRendererTests.swift

+20-27
Original file line numberDiff line numberDiff line change
@@ -179,46 +179,39 @@ final class GitHubActionsRendererTests: XCTestCase {
179179

180180
func testExecuted() throws {
181181
let input1 = "Test Suite 'All tests' failed at 2022-01-15 21:31:49.073."
182-
let input2 = "Executed 3 tests, with 2 failures (1 unexpected) in 0.112 (0.112) seconds"
183-
184-
let input3 = "Test Suite 'All tests' passed at 2022-01-15 21:33:49.073."
185-
let input4 = "Executed 1 test, with 1 failure (1 unexpected) in 0.200 (0.200) seconds"
186-
187-
// First test plan
188182
let formatted1 = logFormatted(input1)
183+
XCTAssertEqual(input1, formatted1)
184+
185+
let input2 = "Executed 3 tests, with 2 failures (1 unexpected) in 0.112 (0.112) seconds"
189186
let formatted2 = logFormatted(input2)
190-
XCTAssertNil(formatted1)
191-
XCTAssertNil(formatted2)
187+
XCTAssertEqual(input2, formatted2)
192188

193-
#if os(macOS)
194-
// FIXME: Failing on Linux
189+
let input3 = "Test Suite 'All tests' passed at 2022-01-15 21:33:49.073."
195190
let formatted3 = logFormatted(input3)
196-
let formatted4 = logFormatted(input4)
197-
XCTAssertNil(formatted3)
198-
XCTAssertNil(formatted4)
191+
XCTAssertEqual(input3, formatted3)
199192

200-
#endif
193+
let input4 = "Executed 1 test, with 1 failure (1 unexpected) in 0.200 (0.200) seconds"
194+
let formatted4 = logFormatted(input4)
195+
XCTAssertEqual(input4, formatted4)
201196
}
202197

203198
#if os(macOS)
204199
func testExecutedWithSkipped() {
205200
let input1 = "Test Suite 'All tests' failed at 2022-01-15 21:31:49.073."
206-
let input2 = "Executed 56 tests, with 3 test skipped and 2 failures (1 unexpected) in 1.029 (1.029) seconds"
207-
208-
let input3 = "Test Suite 'All tests' passed at 2022-01-15 21:33:49.073."
209-
let input4 = "Executed 1 test, with 1 test skipped and 1 failure (1 unexpected) in 3.000 (3.000) seconds"
210-
211-
// First test plan
212201
let formatted1 = logFormatted(input1)
202+
XCTAssertEqual(input1, formatted1)
203+
204+
let input2 = "Executed 56 tests, with 3 test skipped and 2 failures (1 unexpected) in 1.029 (1.029) seconds"
213205
let formatted2 = logFormatted(input2)
214-
XCTAssertNil(formatted1)
215-
XCTAssertNil(formatted2)
206+
XCTAssertEqual(input2, formatted2)
216207

217-
// Second test plan
208+
let input3 = "Test Suite 'All tests' passed at 2022-01-15 21:33:49.073."
218209
let formatted3 = logFormatted(input3)
210+
XCTAssertEqual(input3, formatted3)
211+
212+
let input4 = "Executed 1 test, with 1 test skipped and 1 failure (1 unexpected) in 3.000 (3.000) seconds"
219213
let formatted4 = logFormatted(input4)
220-
XCTAssertNil(formatted3)
221-
XCTAssertNil(formatted4)
214+
XCTAssertEqual(input4, formatted4)
222215
}
223216
#endif
224217

@@ -486,15 +479,15 @@ final class GitHubActionsRendererTests: XCTestCase {
486479
func testTestSuiteAllTestsPassed() {
487480
let input = "Test Suite 'All tests' passed at 2022-01-15 21:31:49.073."
488481
let formatted = logFormatted(input)
489-
XCTAssertNil(formatted)
482+
XCTAssertEqual(input, formatted)
490483
}
491484
#endif
492485

493486
#if os(macOS)
494487
func testTestSuiteAllTestsFailed() {
495488
let input = "Test Suite 'All tests' failed at 2022-01-15 21:31:49.073."
496489
let formatted = logFormatted(input)
497-
XCTAssertNil(formatted)
490+
XCTAssertEqual(input, formatted)
498491
}
499492
#endif
500493

Tests/XcbeautifyLibTests/RendererTests/TeamCityRendererTests.swift

+20-29
Original file line numberDiff line numberDiff line change
@@ -162,46 +162,39 @@ final class TeamCityRendererTests: XCTestCase {
162162

163163
func testExecutedWithoutSkipped() throws {
164164
let input1 = "Test Suite 'All tests' failed at 2022-01-15 21:31:49.073."
165-
let input2 = "Executed 3 tests, with 2 failures (1 unexpected) in 0.112 (0.112) seconds"
166-
167-
let input3 = "Test Suite 'All tests' passed at 2022-01-15 21:33:49.073."
168-
let input4 = "Executed 1 test, with 1 failure (1 unexpected) in 0.200 (0.200) seconds"
169-
170-
// First test plan
171165
let formatted1 = noColoredFormatted(input1)
166+
XCTAssertEqual(input1, formatted1)
167+
168+
let input2 = "Executed 3 tests, with 2 failures (1 unexpected) in 0.112 (0.112) seconds"
172169
let formatted2 = noColoredFormatted(input2)
173-
XCTAssertNil(formatted1)
174-
XCTAssertNil(formatted2)
170+
XCTAssertEqual(input2, formatted2)
175171

176-
#if os(macOS)
177-
// FIXME: Failing on Linux
178-
// Second test plan
172+
let input3 = "Test Suite 'All tests' passed at 2022-01-15 21:33:49.073."
179173
let formatted3 = noColoredFormatted(input3)
174+
XCTAssertEqual(input3, formatted3)
175+
176+
let input4 = "Executed 1 test, with 1 failure (1 unexpected) in 0.200 (0.200) seconds"
180177
let formatted4 = noColoredFormatted(input4)
181-
XCTAssertNil(formatted3)
182-
XCTAssertNil(formatted4)
183-
#endif
178+
XCTAssertEqual(input4, formatted4)
184179
}
185180

186181
#if os(macOS)
187182
func testExecutedWithSkipped() {
188183
let input1 = "Test Suite 'All tests' failed at 2022-01-15 21:31:49.073."
189-
let input2 = "Executed 56 tests, with 3 test skipped and 2 failures (1 unexpected) in 1.029 (1.029) seconds"
190-
191-
let input3 = "Test Suite 'All tests' passed at 2022-01-15 21:33:49.073."
192-
let input4 = "Executed 1 test, with 1 test skipped and 1 failure (1 unexpected) in 3.000 (3.000) seconds"
193-
194-
// First test plan
195184
let formatted1 = noColoredFormatted(input1)
185+
XCTAssertEqual(input1, formatted1)
186+
187+
let input2 = "Executed 56 tests, with 3 test skipped and 2 failures (1 unexpected) in 1.029 (1.029) seconds"
196188
let formatted2 = noColoredFormatted(input2)
197-
XCTAssertNil(formatted1)
198-
XCTAssertNil(formatted2)
189+
XCTAssertEqual(input2, formatted2)
199190

200-
// Second test plan
191+
let input3 = "Test Suite 'All tests' passed at 2022-01-15 21:33:49.073."
201192
let formatted3 = noColoredFormatted(input3)
193+
XCTAssertEqual(input3, formatted3)
194+
195+
let input4 = "Executed 1 test, with 1 test skipped and 1 failure (1 unexpected) in 3.000 (3.000) seconds"
202196
let formatted4 = noColoredFormatted(input4)
203-
XCTAssertNil(formatted3)
204-
XCTAssertNil(formatted4)
197+
XCTAssertEqual(input4, formatted4)
205198
}
206199
#endif
207200

@@ -457,18 +450,16 @@ final class TeamCityRendererTests: XCTestCase {
457450
#if os(macOS)
458451
func testTestSuiteAllTestsPassed() {
459452
let input = "Test Suite 'All tests' passed at 2022-01-15 21:31:49.073."
460-
461453
let formatted = noColoredFormatted(input)
462-
XCTAssertNil(formatted)
454+
XCTAssertEqual(input, formatted)
463455
}
464456
#endif
465457

466458
#if os(macOS)
467459
func testTestSuiteAllTestsFailed() {
468460
let input = "Test Suite 'All tests' failed at 2022-01-15 21:31:49.073."
469-
470461
let formatted = noColoredFormatted(input)
471-
XCTAssertNil(formatted)
462+
XCTAssertEqual(input, formatted)
472463
}
473464
#endif
474465

0 commit comments

Comments
 (0)