Просмотр исходного кода

Add unit test target to Swift package.

Peter Andrews 5 лет назад
Родитель
Сommit
97670f92a6

+ 6 - 0
GoogleSignIn/Tests/Unit/GIDAuthStateMigrationTest.m

@@ -17,11 +17,17 @@
 #import "GoogleSignIn/Sources/GIDAuthStateMigration.h"
 #import "GoogleSignIn/Sources/GIDSignInCallbackSchemes.h"
 
+#ifdef SWIFT_PACKAGE
+@import AppAuth;
+@import GTMAppAuth;
+@import OCMock;
+#else
 #import <AppAuth/AppAuth.h>
 #import <GTMAppAuth/GTMAppAuthFetcherAuthorization+Keychain.h>
 #import <GTMAppAuth/GTMKeychain.h>
 #import <GTMAppAuth/GTMOAuth2KeychainCompatibility.h>
 #import <OCMock/OCMock.h>
+#endif
 
 static NSString *const kTokenURL = @"https://host.com/example/token/url";
 static NSString *const kCallbackPath = @"/callback/path";

+ 9 - 0
GoogleSignIn/Tests/Unit/GIDAuthenticationTest.m

@@ -25,6 +25,14 @@
 #import "GoogleSignIn/Tests/Unit/OIDTokenRequest+Testing.h"
 #import "GoogleSignIn/Tests/Unit/OIDTokenResponse+Testing.h"
 
+#ifdef SWIFT_PACKAGE
+@import AppAuth;
+@import GoogleUtilities_MethodSwizzler;
+@import GoogleUtilities_SwizzlerTestHelpers;
+@import GTMAppAuth;
+@import GTMSessionFetcherCore;
+@import OCMock;
+#else
 #import <AppAuth/OIDAuthState.h>
 #import <AppAuth/OIDAuthorizationRequest.h>
 #import <AppAuth/OIDAuthorizationResponse.h>
@@ -39,6 +47,7 @@
 #import <GTMAppAuth/GTMAppAuthFetcherAuthorization.h>
 #import <GTMSessionFetcher/GTMSessionFetcher.h>
 #import <OCMock/OCMock.h>
+#endif
 
 static NSString *const kClientID = @"87654321.googleusercontent.com";
 static NSString *const kNewAccessToken = @"new_access_token";

+ 6 - 0
GoogleSignIn/Tests/Unit/GIDEMMErrorHandlerTest.m

@@ -18,9 +18,15 @@
 #import "GoogleSignIn/Sources/GIDEMMErrorHandler.h"
 #import "GoogleSignIn/Sources/GIDSignInStrings.h"
 
+#ifdef SWIFT_PACKAGE
+@import GoogleUtilities_MethodSwizzler;
+@import GoogleUtilities_SwizzlerTestHelpers;
+@import OCMock;
+#else
 #import <GoogleUtilities/GULSwizzler.h>
 #import <GoogleUtilities/GULSwizzler+Unswizzle.h>
 #import <OCMock/OCMock.h>
+#endif
 
 NS_ASSUME_NONNULL_BEGIN
 

+ 4 - 0
GoogleSignIn/Tests/Unit/GIDFakeFetcher.h

@@ -14,7 +14,11 @@
  * limitations under the License.
  */
 
+#ifdef SWIFT_PACKAGE
+@import GTMSessionFetcherCore;
+#else
 #import <GTMSessionFetcher/GTMSessionFetcher.h>
+#endif
 
 // A fake |GTMHTTPFetcher| for testing.
 @interface GIDFakeFetcher : GTMSessionFetcher

+ 4 - 0
GoogleSignIn/Tests/Unit/GIDFakeFetcherService.h

@@ -14,7 +14,11 @@
  * limitations under the License.
  */
 
+#ifdef SWIFT_PACKAGE
+@import GTMSessionFetcherCore;
+#else
 #import <GTMSessionFetcher/GTMSessionFetcher.h>
+#endif
 
 // A fake |GTMHTTPFetcherService| for testing.
 @interface GIDFakeFetcherService : NSObject<GTMSessionFetcherServiceProtocol>

+ 4 - 0
GoogleSignIn/Tests/Unit/GIDGoogleUserTest.m

@@ -26,7 +26,11 @@
 #import "GoogleSignIn/Tests/Unit/OIDAuthorizationRequest+Testing.h"
 #import "GoogleSignIn/Tests/Unit/OIDTokenResponse+Testing.h"
 
+#ifdef SWIFT_PACKAGE
+@import AppAuth;
+#else
 #import <AppAuth/OIDAuthState.h>
+#endif
 
 @interface GIDGoogleUserTest : XCTestCase
 @end

+ 4 - 0
GoogleSignIn/Tests/Unit/GIDSignInButtonTest.m

@@ -19,7 +19,11 @@
 #import "GoogleSignIn/Sources/GIDSignIn_Private.h"
 #import "GoogleSignIn/Tests/Unit/GIDFakeSignIn.h"
 
+#ifdef SWIFT_PACKAGE
+@import OCMock;
+#else
 #import <OCMock/OCMock.h>
+#endif
 
 static NSString *const kWidthConstraintIdentifier =
     @"buttonWidth - auto generated by GIDSignInButton";

+ 7 - 0
GoogleSignIn/Tests/Unit/GIDSignInTest.m

@@ -33,6 +33,12 @@
 #import "GoogleSignIn/Tests/Unit/OIDAuthorizationResponse+Testing.h"
 #import "GoogleSignIn/Tests/Unit/OIDTokenResponse+Testing.h"
 
+#ifdef SWIFT_PACKAGE
+@import AppAuth;
+@import GTMAppAuth;
+@import GTMSessionFetcherCore;
+@import OCMock;
+#else
 #import <AppAuth/OIDAuthState.h>
 #import <AppAuth/OIDAuthorizationRequest.h>
 #import <AppAuth/OIDAuthorizationResponse.h>
@@ -47,6 +53,7 @@
 #import <GTMAppAuth/GTMAppAuthFetcherAuthorization.h>
 #import <GTMSessionFetcher/GTMSessionFetcher.h>
 #import <OCMock/OCMock.h>
+#endif
 
 // Create a BLOCK to store the actual address for arg in param.
 #define SAVE_TO_ARG_BLOCK(param) [OCMArg checkWithBlock:^(id arg) {\

+ 4 - 0
GoogleSignIn/Tests/Unit/OIDAuthState+Testing.h

@@ -14,7 +14,11 @@
  * limitations under the License.
  */
 
+#ifdef SWIFT_PACKAGE
+@import AppAuth;
+#else
 #import <AppAuth/OIDAuthState.h>
+#endif
 
 @interface OIDAuthState (Testing)
 

+ 4 - 0
GoogleSignIn/Tests/Unit/OIDAuthorizationRequest+Testing.h

@@ -14,7 +14,11 @@
  * limitations under the License.
  */
 
+#ifdef SWIFT_PACKAGE
+@import AppAuth;
+#else
 #import <AppAuth/OIDAuthorizationRequest.h>
+#endif
 
 extern NSString *const OIDAuthorizationRequestTestingClientID;
 extern NSString *const OIDAuthorizationRequestTestingScope;

+ 4 - 0
GoogleSignIn/Tests/Unit/OIDAuthorizationRequest+Testing.m

@@ -16,9 +16,13 @@
 
 #import "GoogleSignIn/Tests/Unit/OIDServiceConfiguration+Testing.h"
 
+#ifdef SWIFT_PACKAGE
+@import AppAuth;
+#else
 #import <AppAuth/OIDAuthorizationRequest.h>
 #import <AppAuth/OIDResponseTypes.h>
 #import <AppAuth/OIDServiceConfiguration.h>
+#endif
 
 NSString *const OIDAuthorizationRequestTestingClientID = @"87654321.googleusercontent.com";
 NSString *const OIDAuthorizationRequestTestingScope = @"email";

+ 4 - 0
GoogleSignIn/Tests/Unit/OIDAuthorizationResponse+Testing.h

@@ -14,7 +14,11 @@
  * limitations under the License.
  */
 
+#ifdef SWIFT_PACKAGE
+@import AppAuth;
+#else
 #import <AppAuth/OIDAuthorizationResponse.h>
+#endif
 
 @interface OIDAuthorizationResponse (Testing)
 

+ 4 - 0
GoogleSignIn/Tests/Unit/OIDAuthorizationResponse+Testing.m

@@ -16,7 +16,11 @@
 
 #import "GoogleSignIn/Tests/Unit/OIDAuthorizationRequest+Testing.h"
 
+#ifdef SWIFT_PACKAGE
+@import AppAuth;
+#else
 #import <AppAuth/OIDGrantTypes.h>
+#endif
 
 @implementation OIDAuthorizationResponse (Testing)
 

+ 4 - 0
GoogleSignIn/Tests/Unit/OIDServiceConfiguration+Testing.h

@@ -14,7 +14,11 @@
  * limitations under the License.
  */
 
+#ifdef SWIFT_PACKAGE
+@import AppAuth;
+#else
 #import <AppAuth/OIDServiceConfiguration.h>
+#endif
 
 @interface OIDServiceConfiguration (Testing)
 

+ 4 - 0
GoogleSignIn/Tests/Unit/OIDTokenRequest+Testing.h

@@ -14,7 +14,11 @@
  * limitations under the License.
  */
 
+#ifdef SWIFT_PACKAGE
+@import AppAuth;
+#else
 #import <AppAuth/OIDTokenRequest.h>
+#endif
 
 @interface OIDTokenRequest (Testing)
 

+ 4 - 0
GoogleSignIn/Tests/Unit/OIDTokenRequest+Testing.m

@@ -16,8 +16,12 @@
 
 #import "GoogleSignIn/Tests/Unit/OIDAuthorizationResponse+Testing.h"
 
+#ifdef SWIFT_PACKAGE
+@import AppAuth;
+#else
 #import <AppAuth/OIDAuthorizationRequest.h>
 #import <AppAuth/OIDScopeUtilities.h>
+#endif
 
 @implementation OIDTokenRequest (Testing)
 

+ 4 - 0
GoogleSignIn/Tests/Unit/OIDTokenResponse+Testing.h

@@ -14,7 +14,11 @@
  * limitations under the License.
  */
 
+#ifdef SWIFT_PACKAGE
+@import AppAuth;
+#else
 #import <AppAuth/OIDTokenResponse.h>
+#endif
 
 extern NSString *const kAccessToken;
 extern NSTimeInterval const kAccessTokenExpiresIn;

+ 4 - 0
GoogleSignIn/Tests/Unit/OIDTokenResponse+Testing.m

@@ -17,9 +17,13 @@
 #import "GoogleSignIn/Tests/Unit/OIDAuthorizationRequest+Testing.h"
 #import "GoogleSignIn/Tests/Unit/OIDTokenRequest+Testing.h"
 
+#ifdef SWIFT_PACKAGE
+@import AppAuth;
+#else
 #import <AppAuth/OIDScopeUtilities.h>
 #import <AppAuth/OIDTokenRequest.h>
 #import <AppAuth/OIDTokenResponse.h>
+#endif
 
 NSString *const kAccessToken = @"access_token";
 NSTimeInterval const kAccessTokenExpiresIn = 3600;

+ 29 - 5
Package.swift

@@ -19,7 +19,7 @@ import PackageDescription
 
 let package = Package(
   name: "GoogleSignIn",
-  platforms: [.iOS(.v9)],
+  platforms: [.iOS(.v10)],
   products: [
     .library(
       name: "GoogleSignIn",
@@ -39,14 +39,22 @@ let package = Package(
       name: "GTMSessionFetcher",
       url: "https://github.com/google/gtm-session-fetcher.git",
       "1.5.0" ..< "2.0.0"),
+    .package(
+      name: "OCMock",
+      url: "https://github.com/firebase/ocmock.git",
+      .revision("7291762d3551c5c7e31c49cce40a0e391a52e889")),
+    .package(
+      name: "GoogleUtilities",
+      url: "https://github.com/google/GoogleUtilities.git",
+      "7.3.0" ..< "8.0.0"),
   ],
   targets: [
     .target(
       name: "GoogleSignIn",
       dependencies: [
-        .product(name:"AppAuth", package: "AppAuth"),
-	.product(name:"GTMAppAuth", package: "GTMAppAuth"),
-	.product(name:"GTMSessionFetcherCore", package: "GTMSessionFetcher"),
+        .product(name: "AppAuth", package: "AppAuth"),
+	      .product(name: "GTMAppAuth", package: "GTMAppAuth"),
+	      .product(name: "GTMSessionFetcherCore", package: "GTMSessionFetcher"),
       ],
       path: "GoogleSignIn/Sources",
       publicHeadersPath: "Public",
@@ -61,6 +69,22 @@ let package = Package(
         .linkedFramework("Security"),
         .linkedFramework("UIKit"),
       ]
-    )
+    ),
+    .testTarget(
+      name: "GoogleSignIn-UnitTests",
+      dependencies: [
+        "GoogleSignIn",
+        "OCMock",
+        .product(name: "AppAuth", package: "AppAuth"),
+        .product(name: "GTMAppAuth", package: "GTMAppAuth"),
+        .product(name: "GTMSessionFetcherCore", package: "GTMSessionFetcher"),
+        .product(name: "GULMethodSwizzler", package: "GoogleUtilities"),
+        .product(name: "GULSwizzlerTestHelpers", package: "GoogleUtilities"),
+      ],
+      path: "GoogleSignIn/Tests/Unit",
+      cSettings: [
+        .headerSearchPath("../../../"),
+      ]
+    ),
   ]
 )