Skip to content

Commit 18fc60f

Browse files
authored
Add Github Actions file references for Swift Testing issues (#440)
Ensures that we get the valid file/line/col output when we have Swift Testing test failures when using the github actions renderer, which allows swift testing failures to render inline in the github PR diff UI
1 parent d849742 commit 18fc60f

File tree

3 files changed

+45
-5
lines changed

3 files changed

+45
-5
lines changed

Sources/XcbeautifyLib/Renderers/Microsoft/MicrosoftOutputRendering.swift

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,35 @@ extension MicrosoftOutputRendering {
229229
}
230230

231231
func formatSwiftTestingIssue(group: SwiftTestingIssueCaptureGroup) -> String {
232-
let message = "Recorded an issue" + (group.issueDetails.map { " (\($0))" } ?? "")
232+
var fileComponents: FileComponents?
233+
var detailMessage = group.issueDetails?.trimmingCharacters(in: .whitespacesAndNewlines)
234+
235+
if let issueDetails = detailMessage, !issueDetails.isEmpty {
236+
let locationAndMessage = issueDetails.split(separator: ": ", maxSplits: 1, omittingEmptySubsequences: false)
237+
if let locationPart = locationAndMessage.first {
238+
let locationSegments = locationPart.split(separator: ":").map(String.init)
239+
if let path = locationSegments.first, !path.isEmpty {
240+
let line = locationSegments.count > 1 ? Int(locationSegments[1]) : nil
241+
let column = locationSegments.count > 2 ? Int(locationSegments[2]) : nil
242+
fileComponents = FileComponents(path: path, line: line, column: column)
243+
if locationAndMessage.count > 1 {
244+
detailMessage = String(locationAndMessage[1]).trimmingCharacters(in: .whitespacesAndNewlines)
245+
} else {
246+
detailMessage = nil
247+
}
248+
}
249+
}
250+
}
251+
252+
let message =
253+
if let detailMessage, !detailMessage.isEmpty {
254+
"Recorded an issue (\(detailMessage))"
255+
} else {
256+
"Recorded an issue"
257+
}
233258
return makeOutputLog(
234259
annotation: .error,
260+
fileComponents: fileComponents,
235261
message: message
236262
)
237263
}

Tests/XcbeautifyLibTests/RendererTests/AzureDevOpsPipelinesRendererTests.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,7 @@ final class AzureDevOpsPipelinesRendererTests: XCTestCase {
758758
func testSwiftTestingIssue() {
759759
let input = #"􀢄 Test "myTest" recorded an issue at PlanTests.swift:43:5: Expectation failed"#
760760
let formatted = logFormatted(input)
761-
let expectedOutput = "##vso[task.logissue type=error]Recorded an issue (PlanTests.swift:43:5: Expectation failed)"
761+
let expectedOutput = "##vso[task.logissue type=error;sourcepath=PlanTests.swift;linenumber=43;columnnumber=5]Recorded an issue (Expectation failed)"
762762
XCTAssertEqual(formatted, expectedOutput)
763763
}
764764

@@ -772,7 +772,14 @@ final class AzureDevOpsPipelinesRendererTests: XCTestCase {
772772
func testSwiftTestingIssueDetails() {
773773
let input = #"􀢄 Test "myTest" recorded an issue at PlanTests.swift:43:5: Expectation failed"#
774774
let formatted = logFormatted(input)
775-
let expectedOutput = "##vso[task.logissue type=error]Recorded an issue (PlanTests.swift:43:5: Expectation failed)"
775+
let expectedOutput = "##vso[task.logissue type=error;sourcepath=PlanTests.swift;linenumber=43;columnnumber=5]Recorded an issue (Expectation failed)"
776+
XCTAssertEqual(formatted, expectedOutput)
777+
}
778+
779+
func testSwiftTestingIssueWithoutDetailsProvidesFileOnlyAnnotation() {
780+
let input = #"􀢄 Test "myTest" recorded an issue at PlanTests.swift:43:5"#
781+
let formatted = logFormatted(input)
782+
let expectedOutput = "##vso[task.logissue type=error;sourcepath=PlanTests.swift;linenumber=43;columnnumber=5]Recorded an issue"
776783
XCTAssertEqual(formatted, expectedOutput)
777784
}
778785

Tests/XcbeautifyLibTests/RendererTests/GitHubActionsRendererTests.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,7 @@ final class GitHubActionsRendererTests: XCTestCase {
755755
func testSwiftTestingIssue() {
756756
let input = #"􀢄 Test "myTest" recorded an issue at PlanTests.swift:43:5: Expectation failed"#
757757
let formatted = logFormatted(input)
758-
let expectedOutput = "::error ::Recorded an issue (PlanTests.swift:43:5: Expectation failed)"
758+
let expectedOutput = "::error file=PlanTests.swift,line=43,col=5::Recorded an issue (Expectation failed)"
759759
XCTAssertEqual(formatted, expectedOutput)
760760
}
761761

@@ -769,7 +769,14 @@ final class GitHubActionsRendererTests: XCTestCase {
769769
func testSwiftTestingIssueDetails() {
770770
let input = #"􀢄 Test "myTest" recorded an issue at PlanTests.swift:43:5: Expectation failed"#
771771
let formatted = logFormatted(input)
772-
let expectedOutput = "::error ::Recorded an issue (PlanTests.swift:43:5: Expectation failed)"
772+
let expectedOutput = "::error file=PlanTests.swift,line=43,col=5::Recorded an issue (Expectation failed)"
773+
XCTAssertEqual(formatted, expectedOutput)
774+
}
775+
776+
func testSwiftTestingIssueWithoutDetailsProvidesFileOnlyAnnotation() {
777+
let input = #"􀢄 Test "myTest" recorded an issue at PlanTests.swift:43:5"#
778+
let formatted = logFormatted(input)
779+
let expectedOutput = "::error file=PlanTests.swift,line=43,col=5::Recorded an issue"
773780
XCTAssertEqual(formatted, expectedOutput)
774781
}
775782

0 commit comments

Comments
 (0)