Skip to content

Commit 0fe8385

Browse files
authored
Remove unnecessary compiler checks for Concurrency support (#12232)
1 parent 5ac4a05 commit 0fe8385

File tree

26 files changed

+2078
-2214
lines changed

26 files changed

+2078
-2214
lines changed

FirebaseAppCheck/Tests/Unit/Swift/AppCheckAPITests.swift

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,16 @@ final class AppCheckAPITests {
6363
}
6464

6565
// Get token (async/await)
66-
#if compiler(>=5.5.2) && canImport(_Concurrency)
67-
if #available(iOS 13.0, macOS 11.15, macCatalyst 13.0, tvOS 13.0, watchOS 7.0, *) {
68-
// async/await is a Swift 5.5+ feature available on iOS 15+
69-
Task {
70-
do {
71-
try await AppCheck.appCheck().token(forcingRefresh: false)
72-
} catch {
73-
// ...
74-
}
66+
if #available(iOS 13.0, macOS 11.15, macCatalyst 13.0, tvOS 13.0, watchOS 7.0, *) {
67+
// async/await is a Swift 5.5+ feature available on iOS 15+
68+
Task {
69+
do {
70+
try await AppCheck.appCheck().token(forcingRefresh: false)
71+
} catch {
72+
// ...
7573
}
7674
}
77-
#endif // compiler(>=5.5.2) && canImport(_Concurrency)
75+
}
7876

7977
// Set `AppCheckProviderFactory`
8078
AppCheck.setAppCheckProviderFactory(DummyAppCheckProviderFactory())
@@ -97,18 +95,16 @@ final class AppCheckAPITests {
9795
}
9896

9997
// Get token (async/await)
100-
#if compiler(>=5.5.2) && canImport(_Concurrency)
101-
if #available(iOS 13.0, macOS 11.15, macCatalyst 13.0, tvOS 13.0, watchOS 7.0, *) {
102-
// async/await is a Swift 5.5+ feature available on iOS 15+
103-
Task {
104-
do {
105-
_ = try await debugProvider.getToken()
106-
} catch {
107-
// ...
108-
}
98+
if #available(iOS 13.0, macOS 11.15, macCatalyst 13.0, tvOS 13.0, watchOS 7.0, *) {
99+
// async/await is a Swift 5.5+ feature available on iOS 15+
100+
Task {
101+
do {
102+
_ = try await debugProvider.getToken()
103+
} catch {
104+
// ...
109105
}
110106
}
111-
#endif // compiler(>=5.5.2) && canImport(_Concurrency)
107+
}
112108

113109
_ = debugProvider.localDebugToken()
114110
_ = debugProvider.currentDebugToken()
@@ -170,20 +166,18 @@ final class AppCheckAPITests {
170166
}
171167
}
172168
// Get token (async/await)
173-
#if compiler(>=5.5.2) && canImport(_Concurrency)
174-
if #available(iOS 13.0, macOS 11.15, macCatalyst 13.0, tvOS 13.0, watchOS 7.0, *) {
175-
// async/await is a Swift 5.5+ feature available on iOS 15+
176-
Task {
177-
do {
178-
_ = try await deviceCheckProvider.getToken()
179-
} catch AppCheckErrorCode.unsupported {
180-
// ...
181-
} catch {
182-
// ...
183-
}
169+
if #available(iOS 13.0, macOS 11.15, macCatalyst 13.0, tvOS 13.0, watchOS 7.0, *) {
170+
// async/await is a Swift 5.5+ feature available on iOS 15+
171+
Task {
172+
do {
173+
_ = try await deviceCheckProvider.getToken()
174+
} catch AppCheckErrorCode.unsupported {
175+
// ...
176+
} catch {
177+
// ...
184178
}
185179
}
186-
#endif // compiler(>=5.5.2) && canImport(_Concurrency)
180+
}
187181
}
188182
}
189183
#endif // !os(watchOS)

FirebaseAuth/Tests/Sample/SwiftApiTests/AccountInfoTests.swift

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -75,29 +75,27 @@ class AccountInfoTests: TestsBase {
7575
waitForExpectations(timeout: TestsBase.kExpectationsTimeout)
7676
}
7777

78-
#if compiler(>=5.5.2) && canImport(_Concurrency)
79-
@available(iOS 13, tvOS 13, macOS 10.15, watchOS 7, *)
80-
func testUpdatingUsersEmailAsync() async throws {
81-
let auth = Auth.auth()
82-
do {
83-
_ = try await auth.createUser(withEmail: kOldUserEmail, password: "password")
84-
XCTFail("Did not get error for recreating a user")
85-
} catch {
86-
XCTAssertEqual((error as NSError).code,
87-
AuthErrorCode.emailAlreadyInUse.rawValue,
88-
"Created a user despite it already exiting.")
89-
}
78+
@available(iOS 13, tvOS 13, macOS 10.15, watchOS 7, *)
79+
func testUpdatingUsersEmailAsync() async throws {
80+
let auth = Auth.auth()
81+
do {
82+
_ = try await auth.createUser(withEmail: kOldUserEmail, password: "password")
83+
XCTFail("Did not get error for recreating a user")
84+
} catch {
85+
XCTAssertEqual((error as NSError).code,
86+
AuthErrorCode.emailAlreadyInUse.rawValue,
87+
"Created a user despite it already exiting.")
88+
}
9089

91-
let user = try await auth.signIn(withEmail: kOldUserEmail, password: "password")
92-
XCTAssertEqual(user.user.email, kOldUserEmail)
93-
XCTAssertEqual(auth.currentUser?.email,
94-
kOldUserEmail,
95-
"Signed user does not match request.")
90+
let user = try await auth.signIn(withEmail: kOldUserEmail, password: "password")
91+
XCTAssertEqual(user.user.email, kOldUserEmail)
92+
XCTAssertEqual(auth.currentUser?.email,
93+
kOldUserEmail,
94+
"Signed user does not match request.")
9695

97-
try await auth.currentUser?.updateEmail(to: kNewUserEmail)
98-
XCTAssertEqual(auth.currentUser?.email,
99-
kNewUserEmail,
100-
"Signed user does not match change.")
101-
}
102-
#endif
96+
try await auth.currentUser?.updateEmail(to: kNewUserEmail)
97+
XCTAssertEqual(auth.currentUser?.email,
98+
kNewUserEmail,
99+
"Signed user does not match change.")
100+
}
103101
}

FirebaseAuth/Tests/Sample/SwiftApiTests/AnonymousTests.swift

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,14 @@ class AnonymousTests: TestsBase {
2929
deleteCurrentUser()
3030
}
3131

32-
#if compiler(>=5.5.2) && canImport(_Concurrency)
33-
@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
34-
func testUpdatingUsersEmailAsync() async throws {
35-
try await signInAnonymouslyAsync()
36-
if let isAnonymous = Auth.auth().currentUser?.isAnonymous {
37-
XCTAssertTrue(isAnonymous)
38-
} else {
39-
XCTFail("Missing currentUser after anonymous sign in")
40-
}
41-
try await deleteCurrentUserAsync()
32+
@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
33+
func testUpdatingUsersEmailAsync() async throws {
34+
try await signInAnonymouslyAsync()
35+
if let isAnonymous = Auth.auth().currentUser?.isAnonymous {
36+
XCTAssertTrue(isAnonymous)
37+
} else {
38+
XCTFail("Missing currentUser after anonymous sign in")
4239
}
43-
#endif
40+
try await deleteCurrentUserAsync()
41+
}
4442
}

FirebaseAuth/Tests/Sample/SwiftApiTests/EmailPasswordTests.swift

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,13 @@ class EmailPasswordTests: TestsBase {
3939
deleteCurrentUser()
4040
}
4141

42-
#if compiler(>=5.5.2) && canImport(_Concurrency)
43-
@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
44-
func testCreateAccountWithEmailAndPasswordAsync() async throws {
45-
let auth = Auth.auth()
46-
try await auth.createUser(withEmail: kNewEmailToCreateUser, password: "password")
47-
XCTAssertEqual(auth.currentUser?.email, kNewEmailToCreateUser, "Expected email doesn't match")
48-
try await deleteCurrentUserAsync()
49-
}
50-
#endif
42+
@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
43+
func testCreateAccountWithEmailAndPasswordAsync() async throws {
44+
let auth = Auth.auth()
45+
try await auth.createUser(withEmail: kNewEmailToCreateUser, password: "password")
46+
XCTAssertEqual(auth.currentUser?.email, kNewEmailToCreateUser, "Expected email doesn't match")
47+
try await deleteCurrentUserAsync()
48+
}
5149

5250
func testSignInExistingUserWithEmailAndPassword() {
5351
let auth = Auth.auth()
@@ -63,14 +61,12 @@ class EmailPasswordTests: TestsBase {
6361
waitForExpectations(timeout: TestsBase.kExpectationsTimeout)
6462
}
6563

66-
#if compiler(>=5.5.2) && canImport(_Concurrency)
67-
@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
68-
func testSignInExistingUserWithEmailAndPasswordAsync() async throws {
69-
let auth = Auth.auth()
70-
try await auth.signIn(withEmail: kExistingEmailToSignIn, password: "password")
71-
XCTAssertEqual(auth.currentUser?.email,
72-
kExistingEmailToSignIn,
73-
"Signed user does not match request.")
74-
}
75-
#endif
64+
@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
65+
func testSignInExistingUserWithEmailAndPasswordAsync() async throws {
66+
let auth = Auth.auth()
67+
try await auth.signIn(withEmail: kExistingEmailToSignIn, password: "password")
68+
XCTAssertEqual(auth.currentUser?.email,
69+
kExistingEmailToSignIn,
70+
"Signed user does not match request.")
71+
}
7672
}

FirebaseAuth/Tests/Sample/SwiftApiTests/FacebookTests.swift

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ import XCTest
4444
// deleteFacebookTestingAccountbyID(facebookAccountID)
4545
// }
4646
//
47-
// #if compiler(>=5.5.2) && canImport(_Concurrency)
4847
// @available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
4948
// func testSignInWithFacebookAsync() async throws {
5049
// let auth = Auth.auth()
@@ -60,7 +59,6 @@ import XCTest
6059
// try await deleteCurrentUserAsync()
6160
// try await deleteFacebookTestingAccountbyIDAsync(facebookAccountID)
6261
// }
63-
// #endif
6462
//
6563
// func testLinkAnonymousAccountToFacebookAccount() throws {
6664
// let auth = Auth.auth()
@@ -90,7 +88,6 @@ import XCTest
9088
// deleteFacebookTestingAccountbyID(facebookAccountID)
9189
// }
9290
//
93-
// #if compiler(>=5.5.2) && canImport(_Concurrency)
9491
// @available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
9592
// func testLinkAnonymousAccountToFacebookAccountAsync() async throws {
9693
// let auth = Auth.auth()
@@ -111,7 +108,6 @@ import XCTest
111108
// try await deleteCurrentUserAsync()
112109
// try await deleteFacebookTestingAccountbyIDAsync(facebookAccountID)
113110
// }
114-
// #endif
115111
//
116112
// /// Creates a Facebook testing account using Facebook Graph API and return a dictionary that
117113
// /// constrains "id", "access_token", "login_url", "email" and "password" of the created account.
@@ -151,7 +147,6 @@ import XCTest
151147
// return returnValue
152148
// }
153149
//
154-
// #if compiler(>=5.5.2) && canImport(_Concurrency)
155150
// @available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
156151
// /// Creates a Facebook testing account using Facebook Graph API and return a dictionary that
157152
// /// constains "id", "access_token", "login_url", "email" and "password" of the created
@@ -174,7 +169,6 @@ import XCTest
174169
// }
175170
// return returnValue
176171
// }
177-
// #endif
178172
//
179173
// // ** Delete a Facebook testing account by account Id using Facebook Graph API. */
180174
// func deleteFacebookTestingAccountbyID(_ accountID: String) {
@@ -195,7 +189,6 @@ import XCTest
195189
// waitForExpectations(timeout: TestsBase.kExpectationsTimeout)
196190
// }
197191
//
198-
// #if compiler(>=5.5.2) && canImport(_Concurrency)
199192
// @available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
200193
// // ** Delete a Facebook testing account by account Id using Facebook Graph API. */
201194
// func deleteFacebookTestingAccountbyIDAsync(_ accountID: String) async throws {
@@ -208,5 +201,4 @@ import XCTest
208201
// fetcher.setRequestValue("text/plain", forHTTPHeaderField: "Content-Type")
209202
// try await fetcher.beginFetch()
210203
// }
211-
// #endif
212204
// }

FirebaseAuth/Tests/Sample/SwiftApiTests/GoogleTests.swift

Lines changed: 35 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,16 @@ class GoogleTests: TestsBase {
3737
waitForExpectations(timeout: TestsBase.kExpectationsTimeout)
3838
}
3939

40-
#if compiler(>=5.5.2) && canImport(_Concurrency)
41-
@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
42-
func testSignInWithGoogleAsync() async throws {
43-
let auth = Auth.auth()
44-
let userInfoDict = try await getGoogleAccessTokenAsync()
45-
let googleAccessToken: String = try XCTUnwrap(userInfoDict["access_token"] as? String)
46-
let googleIDToken: String = try XCTUnwrap(userInfoDict["id_token"] as? String)
47-
let credential = GoogleAuthProvider.credential(withIDToken: googleIDToken,
48-
accessToken: googleAccessToken)
49-
_ = try await auth.signIn(with: credential)
50-
}
51-
#endif
40+
@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
41+
func testSignInWithGoogleAsync() async throws {
42+
let auth = Auth.auth()
43+
let userInfoDict = try await getGoogleAccessTokenAsync()
44+
let googleAccessToken: String = try XCTUnwrap(userInfoDict["access_token"] as? String)
45+
let googleIDToken: String = try XCTUnwrap(userInfoDict["id_token"] as? String)
46+
let credential = GoogleAuthProvider.credential(withIDToken: googleIDToken,
47+
accessToken: googleAccessToken)
48+
_ = try await auth.signIn(with: credential)
49+
}
5250

5351
/// Sends http request to Google OAuth2 token server to use refresh token to exchange for Google
5452
/// access token.
@@ -84,32 +82,30 @@ class GoogleTests: TestsBase {
8482
return returnValue
8583
}
8684

87-
#if compiler(>=5.5.2) && canImport(_Concurrency)
88-
@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
89-
/// Sends http request to Google OAuth2 token server to use refresh token to exchange for Google
90-
/// access token.
91-
/// Returns a dictionary that constains "access_token", "token_type", "expires_in" and sometimes
92-
/// the "id_token". (The id_token is not guaranteed to be returned during a refresh exchange;
93-
/// see https://openid.net/specs/openid-connect-core-1_0.html#RefreshTokenResponse)
94-
func getGoogleAccessTokenAsync() async throws -> [String: Any] {
95-
let googleOauth2TokenServerUrl = "https://www.googleapis.com/oauth2/v4/token"
96-
let bodyString = "client_id=\(Credentials.kGoogleClientID)&grant_type=refresh_token" +
97-
"&refresh_token=\(Credentials.kGoogleTestAccountRefreshToken)"
98-
let postData = bodyString.data(using: .utf8)
99-
let service = GTMSessionFetcherService()
100-
let fetcher = service.fetcher(withURLString: googleOauth2TokenServerUrl)
101-
fetcher.bodyData = postData
102-
fetcher.setRequestValue(
103-
"application/x-www-form-urlencoded",
104-
forHTTPHeaderField: "Content-Type"
105-
)
106-
let data = try await fetcher.beginFetch()
107-
guard let returnValue = try JSONSerialization.jsonObject(with: data, options: [])
108-
as? [String: Any] else {
109-
XCTFail("Failed to serialize userInfo as a Dictionary")
110-
fatalError()
111-
}
112-
return returnValue
85+
@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
86+
/// Sends http request to Google OAuth2 token server to use refresh token to exchange for Google
87+
/// access token.
88+
/// Returns a dictionary that constains "access_token", "token_type", "expires_in" and sometimes
89+
/// the "id_token". (The id_token is not guaranteed to be returned during a refresh exchange;
90+
/// see https://openid.net/specs/openid-connect-core-1_0.html#RefreshTokenResponse)
91+
func getGoogleAccessTokenAsync() async throws -> [String: Any] {
92+
let googleOauth2TokenServerUrl = "https://www.googleapis.com/oauth2/v4/token"
93+
let bodyString = "client_id=\(Credentials.kGoogleClientID)&grant_type=refresh_token" +
94+
"&refresh_token=\(Credentials.kGoogleTestAccountRefreshToken)"
95+
let postData = bodyString.data(using: .utf8)
96+
let service = GTMSessionFetcherService()
97+
let fetcher = service.fetcher(withURLString: googleOauth2TokenServerUrl)
98+
fetcher.bodyData = postData
99+
fetcher.setRequestValue(
100+
"application/x-www-form-urlencoded",
101+
forHTTPHeaderField: "Content-Type"
102+
)
103+
let data = try await fetcher.beginFetch()
104+
guard let returnValue = try JSONSerialization.jsonObject(with: data, options: [])
105+
as? [String: Any] else {
106+
XCTFail("Failed to serialize userInfo as a Dictionary")
107+
fatalError()
113108
}
114-
#endif
109+
return returnValue
110+
}
115111
}

FirebaseAuth/Tests/Sample/SwiftApiTests/TestsBase.swift

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,17 @@ import XCTest
2121
class TestsBase: XCTestCase {
2222
static let kExpectationsTimeout = 10.0
2323

24-
#if compiler(>=5.5.2) && canImport(_Concurrency)
25-
@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
26-
func signInAnonymouslyAsync() async throws {
27-
let auth = Auth.auth()
28-
try await auth.signInAnonymously()
29-
}
24+
@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
25+
func signInAnonymouslyAsync() async throws {
26+
let auth = Auth.auth()
27+
try await auth.signInAnonymously()
28+
}
3029

31-
@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
32-
func deleteCurrentUserAsync() async throws {
33-
let auth = Auth.auth()
34-
try await auth.currentUser?.delete()
35-
}
36-
#endif
30+
@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
31+
func deleteCurrentUserAsync() async throws {
32+
let auth = Auth.auth()
33+
try await auth.currentUser?.delete()
34+
}
3735

3836
func signInAnonymously() {
3937
let auth = Auth.auth()

0 commit comments

Comments
 (0)