Skip to content

Commit

Permalink
Compatibility for Swift 5.5 in tests suite
Browse files Browse the repository at this point in the history
  • Loading branch information
malcommac committed Nov 14, 2023
1 parent 333b577 commit def2291
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions Tests/SwiftLocationTests/SwiftLocationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ final class SwiftLocationTests: XCTestCase {
mockLocationManager.onValidatePlistConfiguration = { permission in
switch permission {
case .always:
LocationErrors.plistNotConfigured
return LocationErrors.plistNotConfigured
case .whenInUse:
nil
return nil
}
}

Expand All @@ -106,7 +106,7 @@ final class SwiftLocationTests: XCTestCase {
do {
let expectedStatus = CLAuthorizationStatus.restricted
mockLocationManager.onRequestWhenInUseAuthorization = {
expectedStatus
return expectedStatus
}
let newStatus = try await location.requestPermission(.whenInUse)
XCTAssertEqual(expectedStatus, newStatus)
Expand All @@ -120,7 +120,7 @@ final class SwiftLocationTests: XCTestCase {
do {
let expectedStatus = CLAuthorizationStatus.authorizedAlways
mockLocationManager.onRequestAlwaysAuthorization = {
expectedStatus
return expectedStatus
}

let newStatus = try await location.requestPermission(.always)
Expand Down Expand Up @@ -148,11 +148,11 @@ final class SwiftLocationTests: XCTestCase {

sleep(1)
#if os(macOS)
mockLocationManager.onRequestAlwaysAuthorization = { .authorizedAlways }
mockLocationManager.onRequestAlwaysAuthorization = { return .authorizedAlways }
let newStatus = try await location.requestPermission(.always)
XCTAssertEqual(newStatus, .authorizedAlways)
#else
mockLocationManager.onRequestWhenInUseAuthorization = { .authorizedWhenInUse }
mockLocationManager.onRequestWhenInUseAuthorization = { return .authorizedWhenInUse }
let newStatus = try await location.requestPermission(.whenInUse)
XCTAssertEqual(newStatus, .authorizedWhenInUse)
#endif
Expand All @@ -166,19 +166,19 @@ final class SwiftLocationTests: XCTestCase {
XCTAssertEqual(mockLocationManager.accuracyAuthorization, .reducedAccuracy)

#if os(macOS)
mockLocationManager.onRequestAlwaysAuthorization = { .authorizedAlways }
mockLocationManager.onRequestAlwaysAuthorization = { return .authorizedAlways }
let newStatus = try await location.requestPermission(.always)
XCTAssertEqual(newStatus, .authorizedAlways)
#else
mockLocationManager.onRequestWhenInUseAuthorization = { .authorizedWhenInUse }
mockLocationManager.onRequestWhenInUseAuthorization = { return .authorizedWhenInUse }
let newStatus = try await location.requestPermission(.whenInUse)
XCTAssertEqual(newStatus, .authorizedWhenInUse)
#endif

// Test misconfigured Info.plist file
do {
mockLocationManager.onRequestValidationForTemporaryAccuracy = { purposeKey in
LocationErrors.plistNotConfigured
return LocationErrors.plistNotConfigured
}
let _ = try await location.requestTemporaryPrecisionAuthorization(purpose: "test")
XCTFail("This should fail")
Expand All @@ -189,7 +189,7 @@ final class SwiftLocationTests: XCTestCase {
// Test correct configuration
do {
mockLocationManager.onRequestValidationForTemporaryAccuracy = { purposeKey in
nil
return nil
}
let newStatus = try await location.requestTemporaryPrecisionAuthorization(purpose: "test")
XCTAssertEqual(newStatus, .fullAccuracy)
Expand All @@ -203,10 +203,10 @@ final class SwiftLocationTests: XCTestCase {
func testUpdatingLocations() async throws {
// Request authorization
#if os(macOS)
mockLocationManager.onRequestAlwaysAuthorization = { .authorizedAlways }
mockLocationManager.onRequestAlwaysAuthorization = { return .authorizedAlways }
try await location.requestPermission(.always)
#else
mockLocationManager.onRequestWhenInUseAuthorization = { .authorizedWhenInUse }
mockLocationManager.onRequestWhenInUseAuthorization = { return .authorizedWhenInUse }
try await location.requestPermission(.whenInUse)
#endif
let expectedValues = simulateLocationUpdates()
Expand All @@ -226,10 +226,10 @@ final class SwiftLocationTests: XCTestCase {
func testRequestLocation() async throws {
// Request authorization
#if os(macOS)
mockLocationManager.onRequestAlwaysAuthorization = { .authorizedAlways}
mockLocationManager.onRequestAlwaysAuthorization = { return .authorizedAlways}
try await location.requestPermission(.always)
#else
mockLocationManager.onRequestWhenInUseAuthorization = { .authorizedWhenInUse }
mockLocationManager.onRequestWhenInUseAuthorization = { return .authorizedWhenInUse }
try await location.requestPermission(.whenInUse)
#endif
// Check the return of an error
Expand Down

0 comments on commit def2291

Please sign in to comment.