Skip to content

Commit 72bed50

Browse files
Add isFailure to Issue (#1078)
Add `isFailure` var to `Issue` ### Motivation: This adds a variable to `Issue` in order to inspect if an issue isFailing. This will be nice when inspecting an issue after it is recorded. ### Modifications: - Add `isFailure` variable - Update existing code to use `isFailure` ### Checklist: - [x] Code and documentation should follow the style of the [Style Guide](https://github.com/apple/swift-testing/blob/main/Documentation/StyleGuide.md). - [x] If public symbols are renamed or modified, DocC references should be updated.
1 parent 55f82ed commit 72bed50

File tree

4 files changed

+20
-2
lines changed

4 files changed

+20
-2
lines changed

Sources/Testing/ABI/EntryPoints/EntryPoint.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func entryPoint(passing args: __CommandLineArguments_v0?, eventHandler: Event.Ha
4242

4343
// Set up the event handler.
4444
configuration.eventHandler = { [oldEventHandler = configuration.eventHandler] event, context in
45-
if case let .issueRecorded(issue) = event.kind, !issue.isKnown, issue.severity >= .error {
45+
if case let .issueRecorded(issue) = event.kind, issue.isFailure {
4646
exitCode.withLock { exitCode in
4747
exitCode = EXIT_FAILURE
4848
}

Sources/Testing/Issues/Issue.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,21 @@ public struct Issue: Sendable {
103103
/// The severity of this issue.
104104
@_spi(Experimental)
105105
public var severity: Severity
106+
107+
/// Whether or not this issue should cause the test it's associated with to be
108+
/// considered a failure.
109+
///
110+
/// The value of this property is `true` for issues which have a severity level of
111+
/// ``Issue/Severity/error`` or greater and are not known issues via
112+
/// ``withKnownIssue(_:isIntermittent:sourceLocation:_:when:matching:)``.
113+
/// Otherwise, the value of this property is `false.`
114+
///
115+
/// Use this property to determine if an issue should be considered a failure, instead of
116+
/// directly comparing the value of the ``severity`` property.
117+
@_spi(Experimental)
118+
public var isFailure: Bool {
119+
return !self.isKnown && self.severity >= .error
120+
}
106121

107122
/// Any comments provided by the developer and associated with this issue.
108123
///

Tests/TestingTests/IssueTests.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,6 +1011,7 @@ final class IssueTests: XCTestCase {
10111011
}
10121012
XCTAssertFalse(issue.isKnown)
10131013
XCTAssertEqual(issue.severity, .error)
1014+
XCTAssertTrue(issue.isFailure)
10141015
guard case .unconditional = issue.kind else {
10151016
XCTFail("Unexpected issue kind \(issue.kind)")
10161017
return
@@ -1031,6 +1032,7 @@ final class IssueTests: XCTestCase {
10311032
}
10321033
XCTAssertFalse(issue.isKnown)
10331034
XCTAssertEqual(issue.severity, .warning)
1035+
XCTAssertFalse(issue.isFailure)
10341036
guard case .unconditional = issue.kind else {
10351037
XCTFail("Unexpected issue kind \(issue.kind)")
10361038
return

Tests/TestingTests/KnownIssueTests.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
#if canImport(XCTest)
1212
import XCTest
13-
@testable @_spi(ForToolsIntegrationOnly) import Testing
13+
@testable @_spi(Experimental) @_spi(ForToolsIntegrationOnly) import Testing
1414

1515
final class KnownIssueTests: XCTestCase {
1616
func testIssueIsKnownPropertyIsSetCorrectly() async {
@@ -26,6 +26,7 @@ final class KnownIssueTests: XCTestCase {
2626
issueRecorded.fulfill()
2727

2828
XCTAssertTrue(issue.isKnown)
29+
XCTAssertFalse(issue.isFailure)
2930
}
3031

3132
await Test {

0 commit comments

Comments
 (0)