From d2ef0d67b93a4cb85aa1b98c66344d44735a9a54 Mon Sep 17 00:00:00 2001 From: Rachel Brindle Date: Mon, 18 Dec 2023 08:55:47 -0800 Subject: [PATCH] Rename RequirementError to RequireError Fixed test failure on linux --- Sources/Nimble/Requirement.swift | 16 +++++----------- Tests/NimbleTests/AsyncAwaitTest+Require.swift | 16 ++++++++-------- Tests/NimbleTests/DSLTest.swift | 2 +- 3 files changed, 14 insertions(+), 20 deletions(-) diff --git a/Sources/Nimble/Requirement.swift b/Sources/Nimble/Requirement.swift index 488ef3530..0b199f49a 100644 --- a/Sources/Nimble/Requirement.swift +++ b/Sources/Nimble/Requirement.swift @@ -1,6 +1,6 @@ import Foundation -public struct RequirementError: Error, CustomNSError { +public struct RequireError: Error, CustomNSError { let message: String let location: SourceLocation @@ -11,16 +11,10 @@ public struct RequirementError: Error, CustomNSError { ["XCTestErrorUserInfoKeyShouldIgnore": true] } - static func unknown(_ location: SourceLocation) -> RequirementError { - RequirementError(message: "Nimble error - file a bug if you see this!", location: location) + static func unknown(_ location: SourceLocation) -> RequireError { + RequireError(message: "Nimble error - file a bug if you see this!", location: location) } } - -public enum RequireError: Error { - case requirementFailed - case exceptionRaised(name: String, reason: String?, userInfo: [AnyHashable: Any]?) -} - internal func executeRequire(_ expression: Expression, _ style: ExpectationStyle, _ matcher: Matcher, to: String, description: String?, captureExceptions: Bool = true) -> (Bool, FailureMessage, T?) { func run() -> (Bool, FailureMessage, T?) { let msg = FailureMessage() @@ -90,7 +84,7 @@ public struct SyncRequirement { let handler = NimbleEnvironment.activeInstance.assertionHandler handler.assert(pass, message: message, location: expression.location) guard pass, let value else { - throw RequirementError(message: message.stringValue, location: self.location) + throw RequireError(message: message.stringValue, location: self.location) } return value } @@ -154,7 +148,7 @@ public struct AsyncRequirement { let handler = NimbleEnvironment.activeInstance.assertionHandler handler.assert(pass, message: message, location: expression.location) guard pass, let value else { - throw RequirementError(message: message.stringValue, location: self.location) + throw RequireError(message: message.stringValue, location: self.location) } return value } diff --git a/Tests/NimbleTests/AsyncAwaitTest+Require.swift b/Tests/NimbleTests/AsyncAwaitTest+Require.swift index 486a28234..fc1011e04 100644 --- a/Tests/NimbleTests/AsyncAwaitTest+Require.swift +++ b/Tests/NimbleTests/AsyncAwaitTest+Require.swift @@ -143,10 +143,10 @@ final class AsyncAwaitRequireTest: XCTestCase { // swiftlint:disable:this type_b // However, the functionality actually works as you'd expect it to, you're just expected to tag things to use the main actor. func isMainThread() -> Bool { Thread.isMainThread } - try await require(isMainThread()).toEventually(beFalse()) - try await require(isMainThread()).toEventuallyNot(beTrue()) - try await require(isMainThread()).toAlways(beFalse(), until: .seconds(1)) - try await require(isMainThread()).toNever(beTrue(), until: .seconds(1)) + try await requirea(isMainThread()).toEventually(beFalse()) + try await requirea(isMainThread()).toEventuallyNot(beTrue()) + try await requirea(isMainThread()).toAlways(beFalse(), until: .seconds(1)) + try await requirea(isMainThread()).toNever(beTrue(), until: .seconds(1)) } @MainActor @@ -155,10 +155,10 @@ final class AsyncAwaitRequireTest: XCTestCase { // swiftlint:disable:this type_b // However, the functionality actually works as you'd expect it to, you're just expected to tag things to use the main actor. func isMainThread() -> Bool { Thread.isMainThread } - try await require(isMainThread()).toEventually(beTrue()) - try await require(isMainThread()).toEventuallyNot(beFalse()) - try await require(isMainThread()).toAlways(beTrue(), until: .seconds(1)) - try await require(isMainThread()).toNever(beFalse(), until: .seconds(1)) + try await requirea(isMainThread()).toEventually(beTrue()) + try await requirea(isMainThread()).toEventuallyNot(beFalse()) + try await requirea(isMainThread()).toAlways(beTrue(), until: .seconds(1)) + try await requirea(isMainThread()).toNever(beFalse(), until: .seconds(1)) } func testToEventuallyWithCustomDefaultTimeout() async throws { diff --git a/Tests/NimbleTests/DSLTest.swift b/Tests/NimbleTests/DSLTest.swift index 3f1bf962f..8050b7d11 100644 --- a/Tests/NimbleTests/DSLTest.swift +++ b/Tests/NimbleTests/DSLTest.swift @@ -135,7 +135,7 @@ final class DSLTest: XCTestCase { do { try require(1).to(equal(2)) } catch { - expect(error).to(matchError(RequirementError.self)) + expect(error).to(matchError(RequireError.self)) } }