Skip to content
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

Adds support for Skipped and Expected Failure test statuses #23

Merged
merged 1 commit into from
Dec 1, 2023
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
6 changes: 6 additions & 0 deletions Sources/xcresultparser/JunitXML.swift
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ public struct JunitXML: XmlSerializable {
} else {
testcase.addChild(failureWithoutSummary)
}
} else if thisTest.isSkipped {
testcase.addChild(skippedWithoutSummary)
}
combined.append(testcase)
}
Expand All @@ -216,6 +218,10 @@ public struct JunitXML: XmlSerializable {
private var failureWithoutSummary: XMLElement {
return XMLElement(name: "failure")
}

private var skippedWithoutSummary: XMLElement {
return XMLElement(name: "skipped")
}
}

extension XMLElement {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public struct MDResultFormatter: XCResultFormatting {

public let testFailIcon = "🔴  "
public let testPassIcon = "🟢  "
public let testSkipIcon = "⚪️  "

public init() { }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public protocol XCResultFormatting {
func failedTestItem(_ item: String, message: String) -> String
var testFailIcon: String { get }
var testPassIcon: String { get }

var testSkipIcon: String { get }

func codeCoverageTargetSummary(_ item: String) -> String
func codeCoverageFileSummary(_ item: String) -> String
func codeCoverageFunctionSummary(_ items: [String]) -> String
Expand All @@ -39,4 +40,7 @@ public extension XCResultFormatting {
var testPassIcon: String {
return "✓"
}
var testSkipIcon: String {
return "-"
}
}
26 changes: 23 additions & 3 deletions Sources/xcresultparser/XCResultFormatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ public struct XCResultFormatter {

private func actionTestFileStatusString(for testData: ActionTestMetadata, failureSummaries: [TestFailureIssueSummary]) -> String {
let duration = numFormatter.unwrappedString(for: testData.duration)
let icon = testData.isFailed ? outputFormatter.testFailIcon: outputFormatter.testPassIcon
let icon = actionTestFileStatusStringIcon(testData: testData)
let testTitle = "\(icon) \(testData.name ?? "Missing-Name") (\(duration))"
let testCaseName = testData.identifier?.replacingOccurrences(of: "/", with: ".") ?? "No-identifier"
if let summary = failureSummaries.first(where: { $0.testCaseName == testCaseName }) {
Expand All @@ -289,7 +289,19 @@ public struct XCResultFormatter {
return outputFormatter.singleTestItem(testTitle, failed: testData.isFailed)
}
}


private func actionTestFileStatusStringIcon(testData: ActionTestMetadata) -> String {
if testData.isSuccessful {
return outputFormatter.testPassIcon
}

if testData.isSkipped {
return outputFormatter.testSkipIcon
}

return outputFormatter.testFailIcon
}

private func actionTestFailureStatusString(with header: String, and failure: TestFailureIssueSummary) -> String {
return outputFormatter.failedTestItem(header, message: failure.message)
}
Expand Down Expand Up @@ -374,7 +386,15 @@ public struct XCResultFormatter {

extension ActionTestMetadata {
var isFailed: Bool {
return testStatus != "Success"
return isSuccessful == false && isSkipped == false
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the substantive change. isSuccessful and isSkipped look for specific string values and any others are considered to be a failure.

Ideally this would be an enum in XCResultKit and we could switch on it.

}

var isSuccessful: Bool {
return testStatus == "Success" || testStatus == "Expected Failure"
}

var isSkipped: Bool {
return testStatus == "Skipped"
}
}

Expand Down