diff --git a/Sources/Nimble/Adapters/AdapterProtocols.swift b/Sources/Nimble/Adapters/AdapterProtocols.swift index 55471229a..a28bf2be5 100644 --- a/Sources/Nimble/Adapters/AdapterProtocols.swift +++ b/Sources/Nimble/Adapters/AdapterProtocols.swift @@ -1,7 +1,6 @@ /// Protocol for the assertion handler that Nimble uses for all expectations. public protocol AssertionHandler { func assert(_ assertion: Bool, message: FailureMessage, location: SourceLocation) - func require(_ passed: Bool, message: FailureMessage, location: SourceLocation) } /// Global backing interface for assertions that Nimble creates. diff --git a/Sources/Nimble/Adapters/AssertionDispatcher.swift b/Sources/Nimble/Adapters/AssertionDispatcher.swift index 30b245f20..94a9030eb 100644 --- a/Sources/Nimble/Adapters/AssertionDispatcher.swift +++ b/Sources/Nimble/Adapters/AssertionDispatcher.swift @@ -16,10 +16,4 @@ public class AssertionDispatcher: AssertionHandler { handler.assert(assertion, message: message, location: location) } } - - public func require(_ passed: Bool, message: FailureMessage, location: SourceLocation) { - for handler in handlers { - handler.require(passed, message: message, location: location) - } - } } diff --git a/Sources/Nimble/Adapters/AssertionRecorder.swift b/Sources/Nimble/Adapters/AssertionRecorder.swift index 6ceeb7869..239393eda 100644 --- a/Sources/Nimble/Adapters/AssertionRecorder.swift +++ b/Sources/Nimble/Adapters/AssertionRecorder.swift @@ -11,10 +11,8 @@ public struct AssertionRecord: CustomStringConvertible { /// The source location the expectation occurred on. public let location: SourceLocation - public let issueType: IssueType - public var description: String { - return "AssertionRecord { success=\(success), message='\(message.stringValue)', location=\(location), issueType=\(issueType) }" + return "AssertionRecord { success=\(success), message='\(message.stringValue)', location=\(location) }" } } @@ -33,17 +31,7 @@ public class AssertionRecorder: AssertionHandler { AssertionRecord( success: assertion, message: message, - location: location, - issueType: .assertionFailure)) - } - - public func require(_ passed: Bool, message: FailureMessage, location: SourceLocation) { - assertions.append( - AssertionRecord( - success: passed, - message: message, - location: location, - issueType: .thrownError)) + location: location)) } } diff --git a/Sources/Nimble/Adapters/NimbleXCTestHandler.swift b/Sources/Nimble/Adapters/NimbleXCTestHandler.swift index 2b3f3dd57..697dc8d80 100644 --- a/Sources/Nimble/Adapters/NimbleXCTestHandler.swift +++ b/Sources/Nimble/Adapters/NimbleXCTestHandler.swift @@ -9,12 +9,6 @@ public class NimbleXCTestHandler: AssertionHandler { recordFailure("\(message.stringValue)\n", location: location) } } - - public func require(_ passed: Bool, message: FailureMessage, location: SourceLocation) { - if !passed { - recordFailure("\(message.stringValue)\n", issueType: .thrownError, location: location) - } - } } /// Alternative handler for Nimble. This assertion handler passes failures along @@ -31,18 +25,6 @@ public class NimbleShortXCTestHandler: AssertionHandler { recordFailure("\(msg)\n", location: location) } } - - public func require(_ passed: Bool, message: FailureMessage, location: SourceLocation) { - if !passed { - let msg: String - if let actual = message.actualValue { - msg = "got: \(actual) \(message.postfixActual)" - } else { - msg = "expected \(message.to) \(message.postfixMessage)" - } - recordFailure("\(msg)\n", issueType: .thrownError, location: location) - } - } } /// Fallback handler in case XCTest is unavailable. This assertion handler will abort @@ -51,10 +33,6 @@ class NimbleXCTestUnavailableHandler: AssertionHandler { func assert(_ assertion: Bool, message: FailureMessage, location: SourceLocation) { fatalError("XCTest is not available and no custom assertion handler was configured. Aborting.") } - - func require(_ passed: Bool, message: FailureMessage, location: SourceLocation) { - fatalError("XCTest is not available and no custom assertion handler was configured. Aborting.") - } } #if canImport(Darwin) @@ -94,21 +72,7 @@ func isXCTestAvailable() -> Bool { #endif } -public enum IssueType { - case assertionFailure - case thrownError - - #if canImport(Darwin) - var xctIssueType: XCTIssueReference.IssueType { - switch self { - case .assertionFailure: return .assertionFailure - case .thrownError: return .thrownError - } - } - #endif -} - -public func recordFailure(_ message: String, issueType: IssueType = .assertionFailure, location: SourceLocation) { +public func recordFailure(_ message: String, location: SourceLocation) { #if !canImport(Darwin) XCTFail("\(message)", file: location.file, line: location.line) #else @@ -116,7 +80,7 @@ public func recordFailure(_ message: String, issueType: IssueType = .assertionFa let line = Int(location.line) let location = XCTSourceCodeLocation(filePath: location.file, lineNumber: line) let sourceCodeContext = XCTSourceCodeContext(location: location) - let issue = XCTIssue(type: issueType.xctIssueType, compactDescription: message, sourceCodeContext: sourceCodeContext) + let issue = XCTIssue(type: .assertionFailure, compactDescription: message, sourceCodeContext: sourceCodeContext) testCase.record(issue) } else { let msg = """ diff --git a/Sources/Nimble/Requirement.swift b/Sources/Nimble/Requirement.swift index 7058ce0c1..d4d441d22 100644 --- a/Sources/Nimble/Requirement.swift +++ b/Sources/Nimble/Requirement.swift @@ -88,7 +88,7 @@ public struct SyncRequirement { public func verify(_ pass: Bool, _ message: FailureMessage, _ value: Value?) throws -> Value { let handler = NimbleEnvironment.activeInstance.assertionHandler - handler.require(pass, message: message, location: expression.location) + handler.assert(pass, message: message, location: expression.location) guard pass, let value else { throw RequirementError(message: message.stringValue, location: self.location) } @@ -146,7 +146,7 @@ public struct AsyncRequirement { public func verify(_ pass: Bool, _ message: FailureMessage, _ value: Value?) throws -> Value { let handler = NimbleEnvironment.activeInstance.assertionHandler - handler.require(pass, message: message, location: expression.location) + handler.assert(pass, message: message, location: expression.location) guard pass, let value else { throw RequirementError(message: message.stringValue, location: self.location) }