Skip to content

Commit e801af7

Browse files
authored
Propagate issue severity from exit test bodies. (#1272)
This PR ensures that an issue with `.warning` severity is recorded correctly from within the body of an exit test. For example: ```swift await #expect(processExitsWith: .success) { Issue.record("TODO: implement exit test body", severity: .warning) } ``` ### Checklist: - [ ] Code and documentation should follow the style of the [Style Guide](https://github.com/apple/swift-testing/blob/main/Documentation/StyleGuide.md). - [ ] If public symbols are renamed or modified, DocC references should be updated.
1 parent 0b48b60 commit e801af7

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

Sources/Testing/ExitTests/ExitTest.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1046,11 +1046,17 @@ extension ExitTest {
10461046
// TODO: improve fidelity of issue kind reporting (especially those without associated values)
10471047
.unconditional
10481048
}
1049+
let severity: Issue.Severity = switch issue._severity {
1050+
case .warning:
1051+
.warning
1052+
case .error:
1053+
.error
1054+
}
10491055
let sourceContext = SourceContext(
10501056
backtrace: nil, // `issue._backtrace` will have the wrong address space.
10511057
sourceLocation: issue.sourceLocation
10521058
)
1053-
var issueCopy = Issue(kind: issueKind, comments: comments, sourceContext: sourceContext)
1059+
var issueCopy = Issue(kind: issueKind, severity: severity, comments: comments, sourceContext: sourceContext)
10541060
if issue.isKnown {
10551061
// The known issue comment, if there was one, is already included in
10561062
// the `comments` array above.

Tests/TestingTests/ExitTestTests.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,26 @@ private import _TestingInternals
383383
}
384384
}
385385

386+
@Test("Issue severity")
387+
func issueSeverity() async {
388+
await confirmation("Recorded issue had warning severity") { wasWarning in
389+
var configuration = Configuration()
390+
configuration.eventHandler = { event, _ in
391+
if case let .issueRecorded(issue) = event.kind, issue.severity == .warning {
392+
wasWarning()
393+
}
394+
}
395+
396+
// Mock an exit test where the process exits successfully.
397+
configuration.exitTestHandler = ExitTest.handlerForEntryPoint()
398+
await Test {
399+
await #expect(processExitsWith: .success) {
400+
Issue.record("Issue recorded", severity: .warning)
401+
}
402+
}.run(configuration: configuration)
403+
}
404+
}
405+
386406
@Test("Capture list")
387407
func captureList() async {
388408
let i = 123

0 commit comments

Comments
 (0)