Skip to content

Add isFailure to Issue #1078

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

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
2 changes: 1 addition & 1 deletion Sources/Testing/ABI/EntryPoints/EntryPoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func entryPoint(passing args: __CommandLineArguments_v0?, eventHandler: Event.Ha

// Set up the event handler.
configuration.eventHandler = { [oldEventHandler = configuration.eventHandler] event, context in
if case let .issueRecorded(issue) = event.kind, !issue.isKnown, issue.severity >= .error {
if case let .issueRecorded(issue) = event.kind, issue.isFailure {
exitCode.withLock { exitCode in
exitCode = EXIT_FAILURE
}
Expand Down
15 changes: 15 additions & 0 deletions Sources/Testing/Issues/Issue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,21 @@ public struct Issue: Sendable {
/// The severity of this issue.
@_spi(Experimental)
public var severity: Severity

/// Whether or not this issue should cause the test it's associated with to be
/// considered a failure.
///
/// The value of this property is `true` for issues which have a severity level of
/// ``Issue/Severity/error`` or greater and are not known issues via
/// ``withKnownIssue(_:isIntermittent:sourceLocation:_:when:matching:)``.
/// Otherwise, the value of this property is `false.`
///
/// Use this property to determine if an issue should be considered a failure, instead of
/// directly comparing the value of the ``severity`` property.
@_spi(Experimental)
public var isFailure: Bool {
return !self.isKnown && self.severity >= .error
}

/// Any comments provided by the developer and associated with this issue.
///
Expand Down
2 changes: 2 additions & 0 deletions Tests/TestingTests/IssueTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1011,6 +1011,7 @@ final class IssueTests: XCTestCase {
}
XCTAssertFalse(issue.isKnown)
XCTAssertEqual(issue.severity, .error)
XCTAssertTrue(issue.isFailure)
guard case .unconditional = issue.kind else {
XCTFail("Unexpected issue kind \(issue.kind)")
return
Expand All @@ -1031,6 +1032,7 @@ final class IssueTests: XCTestCase {
}
XCTAssertFalse(issue.isKnown)
XCTAssertEqual(issue.severity, .warning)
XCTAssertFalse(issue.isFailure)
guard case .unconditional = issue.kind else {
XCTFail("Unexpected issue kind \(issue.kind)")
return
Expand Down
3 changes: 2 additions & 1 deletion Tests/TestingTests/KnownIssueTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#if canImport(XCTest)
import XCTest
@testable @_spi(ForToolsIntegrationOnly) import Testing
@testable @_spi(Experimental) @_spi(ForToolsIntegrationOnly) import Testing

final class KnownIssueTests: XCTestCase {
func testIssueIsKnownPropertyIsSetCorrectly() async {
Expand All @@ -26,6 +26,7 @@ final class KnownIssueTests: XCTestCase {
issueRecorded.fulfill()

XCTAssertTrue(issue.isKnown)
XCTAssertFalse(issue.isFailure)
}

await Test {
Expand Down