From e7f6804acf4da3568ceb4303d463fa2581788bad 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 +- Tests/NimbleTests/PollingTest+Require.swift | 18 ++++++++++-------- 4 files changed, 24 insertions(+), 28 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)) } } diff --git a/Tests/NimbleTests/PollingTest+Require.swift b/Tests/NimbleTests/PollingTest+Require.swift index b8cf5bcff..c47bf72c1 100644 --- a/Tests/NimbleTests/PollingTest+Require.swift +++ b/Tests/NimbleTests/PollingTest+Require.swift @@ -60,14 +60,16 @@ final class PollingRequireTest: XCTestCase { } func testPollUnwrapNegativeCase() { - failsWithErrorMessage("expected to eventually not be nil, got nil") { - try pollUnwrap(nil as Int?) - failsWithErrorMessage("unexpected error thrown: <\(errorToThrow)>") { - try pollUnwrap { try self.doThrowError() as Int? } - } - failsWithErrorMessage("unexpected error thrown: <\(errorToThrow)>") { - try pollUnwrap { try self.doThrowError() as Int? } - } + failsWithErrorMessage("expected to eventually not be nil, got ") { + do { + try pollUnwrap(nil as Int?) + } catch {} + } + failsWithErrorMessage("unexpected error thrown: <\(errorToThrow)>") { + try pollUnwrap { try self.doThrowError() as Int? } + } + failsWithErrorMessage("unexpected error thrown: <\(errorToThrow)>") { + try pollUnwrap { try self.doThrowError() as Int? } } }