Skip to content

Commit

Permalink
Rename RequirementError to RequireError
Browse files Browse the repository at this point in the history
Fixed test failure on linux
  • Loading branch information
younata committed Dec 18, 2023
1 parent d2bb507 commit d2ef0d6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 20 deletions.
16 changes: 5 additions & 11 deletions Sources/Nimble/Requirement.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation

public struct RequirementError: Error, CustomNSError {
public struct RequireError: Error, CustomNSError {
let message: String
let location: SourceLocation

Expand All @@ -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<T>(_ expression: Expression<T>, _ style: ExpectationStyle, _ matcher: Matcher<T>, to: String, description: String?, captureExceptions: Bool = true) -> (Bool, FailureMessage, T?) {

Check warning on line 18 in Sources/Nimble/Requirement.swift

View workflow job for this annotation

GitHub Actions / lint

Large Tuple Violation: Tuples should have at most 2 members (large_tuple)
func run() -> (Bool, FailureMessage, T?) {

Check warning on line 19 in Sources/Nimble/Requirement.swift

View workflow job for this annotation

GitHub Actions / lint

Large Tuple Violation: Tuples should have at most 2 members (large_tuple)
let msg = FailureMessage()
Expand Down Expand Up @@ -90,7 +84,7 @@ public struct SyncRequirement<Value> {
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
}
Expand Down Expand Up @@ -154,7 +148,7 @@ public struct AsyncRequirement<Value> {
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
}
Expand Down
16 changes: 8 additions & 8 deletions Tests/NimbleTests/AsyncAwaitTest+Require.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion Tests/NimbleTests/DSLTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

Expand Down

0 comments on commit d2ef0d6

Please sign in to comment.