|
1 | 1 | import Foundation |
2 | 2 | @testable import XcresultparserLib |
| 3 | +import XCResultKit |
3 | 4 | import Testing |
4 | 5 |
|
5 | 6 | @MainActor |
@@ -499,6 +500,73 @@ struct XcresultparserTests { |
499 | 500 | try assertXmlTestReportsAreEqual(expectedFileName: "junit_repeated", actual: junitXML) |
500 | 501 | } |
501 | 502 |
|
| 503 | + @Test |
| 504 | + func testFailureSummariesReturnsAllMatchingFailures() throws { |
| 505 | + let testMetadata = try makeTestMetadata() |
| 506 | + |
| 507 | + let matchingFailure1 = try makeFailureSummary( |
| 508 | + testCaseName: "TestClass.testMethod", |
| 509 | + message: "First assertion failed" |
| 510 | + ) |
| 511 | + let matchingFailure2 = try makeFailureSummary( |
| 512 | + testCaseName: "TestClass.testMethod", |
| 513 | + message: "Second assertion failed" |
| 514 | + ) |
| 515 | + let nonMatchingFailure = try makeFailureSummary( |
| 516 | + testCaseName: "OtherClass.otherMethod", |
| 517 | + message: "Unrelated failure" |
| 518 | + ) |
| 519 | + |
| 520 | + let result = testMetadata.failureSummaries(in: [matchingFailure1, nonMatchingFailure, matchingFailure2]) |
| 521 | + |
| 522 | + #expect(result.count == 2) |
| 523 | + #expect(result[0].message == "First assertion failed") |
| 524 | + #expect(result[1].message == "Second assertion failed") |
| 525 | + } |
| 526 | + |
| 527 | + @Test |
| 528 | + func testFailureSummariesWithBracketNotation() throws { |
| 529 | + let testMetadata = try makeTestMetadata() |
| 530 | + |
| 531 | + // Objective-C bracket notation: -[TestClass testMethod] |
| 532 | + let bracketFailure1 = try makeFailureSummary( |
| 533 | + testCaseName: "-[TestClass testMethod]", |
| 534 | + message: "Bracket notation failure 1" |
| 535 | + ) |
| 536 | + let bracketFailure2 = try makeFailureSummary( |
| 537 | + testCaseName: "-[TestClass testMethod]", |
| 538 | + message: "Bracket notation failure 2" |
| 539 | + ) |
| 540 | + |
| 541 | + let result = testMetadata.failureSummaries(in: [bracketFailure1, bracketFailure2]) |
| 542 | + |
| 543 | + #expect(result.count == 2) |
| 544 | + #expect(result[0].message == "Bracket notation failure 1") |
| 545 | + #expect(result[1].message == "Bracket notation failure 2") |
| 546 | + } |
| 547 | + |
| 548 | + @Test |
| 549 | + func testFailureSummariesReturnsEmptyForNoMatches() throws { |
| 550 | + let testMetadata = try makeTestMetadata() |
| 551 | + let nonMatchingFailure = try makeFailureSummary( |
| 552 | + testCaseName: "OtherClass.otherMethod", |
| 553 | + message: "Unrelated failure" |
| 554 | + ) |
| 555 | + |
| 556 | + let result = testMetadata.failureSummaries(in: [nonMatchingFailure]) |
| 557 | + |
| 558 | + #expect(result.isEmpty) |
| 559 | + } |
| 560 | + |
| 561 | + @Test |
| 562 | + func testFailureSummariesWithEmptyArray() throws { |
| 563 | + let testMetadata = try makeTestMetadata() |
| 564 | + |
| 565 | + let result = testMetadata.failureSummaries(in: []) |
| 566 | + |
| 567 | + #expect(result.isEmpty) |
| 568 | + } |
| 569 | + |
502 | 570 | @Test |
503 | 571 | func testCleanCodeWarnings() throws { |
504 | 572 | let xcresultFile = Bundle.module.url(forResource: "test", withExtension: "xcresult")! |
@@ -650,6 +718,36 @@ struct XcresultparserTests { |
650 | 718 |
|
651 | 719 | // MARK: helper functions |
652 | 720 |
|
| 721 | + private func makeTestMetadata( |
| 722 | + identifier: String = "TestClass/testMethod", |
| 723 | + name: String = "testMethod", |
| 724 | + status: String = "Failure", |
| 725 | + duration: String = "0.5" |
| 726 | + ) throws -> ActionTestMetadata { |
| 727 | + let json: [String: AnyObject] = [ |
| 728 | + "_type": ["_name": "ActionTestMetadata"] as AnyObject, |
| 729 | + "identifier": ["_type": ["_name": "String"], "_value": identifier] as AnyObject, |
| 730 | + "name": ["_type": ["_name": "String"], "_value": name] as AnyObject, |
| 731 | + "testStatus": ["_type": ["_name": "String"], "_value": status] as AnyObject, |
| 732 | + "duration": ["_type": ["_name": "Double"], "_value": duration] as AnyObject |
| 733 | + ] |
| 734 | + return try #require(ActionTestMetadata(json)) |
| 735 | + } |
| 736 | + |
| 737 | + private func makeFailureSummary( |
| 738 | + testCaseName: String, |
| 739 | + message: String = "Assertion failed", |
| 740 | + issueType: String = "Assertion Failure" |
| 741 | + ) throws -> TestFailureIssueSummary { |
| 742 | + let json: [String: AnyObject] = [ |
| 743 | + "_type": ["_name": "TestFailureIssueSummary"] as AnyObject, |
| 744 | + "testCaseName": ["_type": ["_name": "String"], "_value": testCaseName] as AnyObject, |
| 745 | + "issueType": ["_type": ["_name": "String"], "_value": issueType] as AnyObject, |
| 746 | + "message": ["_type": ["_name": "String"], "_value": message] as AnyObject |
| 747 | + ] |
| 748 | + return try #require(TestFailureIssueSummary(json)) |
| 749 | + } |
| 750 | + |
653 | 751 | func assertXmlTestReportsAreEqual( |
654 | 752 | expectedFileName: String, |
655 | 753 | actual: XmlSerializable, |
|
0 commit comments