Skip to content

Fix Swizzler test warnings #2144

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ - (BOOL)application:(UIApplication *)application

- (BOOL)application:(UIApplication *)application
continueUserActivity:(NSUserActivity *)userActivity
restorationHandler:(void (^)(NSArray *__nullable restorableObjects))restorationHandler {
restorationHandler:(void (^)(NSArray<id<UIUserActivityRestoring>> *__nullable
restorableObjects))restorationHandler {
_userActivity = userActivity;
return YES;
}
Expand Down Expand Up @@ -261,7 +262,7 @@ - (void)testHandleBackgroundSessionMethod {

UIApplication *currentApplication = [UIApplication sharedApplication];
NSString *sessionID = @"123";
void (^nilHandler)() = nil;
void (^nilHandler)(void) = nil;
[realAppDelegate application:currentApplication
handleEventsForBackgroundURLSession:sessionID
completionHandler:nilHandler];
Expand All @@ -274,8 +275,11 @@ - (void)testHandleBackgroundSessionMethod {

/** Tests registering and unregistering invalid interceptors. */
- (void)testInvalidInterceptor {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wnonnull"
XCTAssertThrows([GULAppDelegateSwizzler registerAppDelegateInterceptor:nil],
@"Should not register nil interceptor");
#pragma clang diagnostic pop
XCTAssertEqual([GULAppDelegateSwizzler interceptors].count, 0);

// Try to register some random object that does not conform to UIApplicationDelegate.
Expand Down Expand Up @@ -303,6 +307,8 @@ - (void)testInvalidInterceptor {
XCTAssertEqual([GULAppDelegateSwizzler interceptors].count, 1);

// Try to unregister an empty string. Should not remove anything.
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wnonnull"
XCTAssertThrows([GULAppDelegateSwizzler unregisterAppDelegateInterceptorWithID:nil],
@"Should not unregister nil interceptorID");
XCTAssertEqual([GULAppDelegateSwizzler interceptors].count, 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,16 @@ - (void)testSwizzlingAndUnswizzlingInheritedInstanceMethodsForSuperclassesWorksA
NSString *swizzledPollutedTestObjectSubclassSubclassDescription =
[originalPollutedTestObjectSubclassSubclassDescription stringByAppendingString:@"SWIZZLED!"];

NSString * (^newImplementationPollutedTestObject)() = ^NSString *(id _self) {
NSString * (^newImplementationPollutedTestObject)(NSString *) = ^NSString *(id _self) {
return swizzledPollutedTestObjectDescription;
};

NSString * (^newImplementationPollutedTestObjectSubclass)() = ^NSString *(id _self) {
NSString * (^newImplementationPollutedTestObjectSubclass)(NSString *) = ^NSString *(id _self) {
return swizzledPollutedTestObjectSubclassDescription;
};

NSString * (^newImplementationPollutedTestObjectSubclassSubclass)() = ^NSString *(id _self) {
NSString * (^newImplementationPollutedTestObjectSubclassSubclass)(NSString *) =
^NSString *(id _self) {
return swizzledPollutedTestObjectSubclassSubclassDescription;
};

Expand Down
34 changes: 17 additions & 17 deletions GoogleUtilities/Example/Tests/Swizzler/GULSwizzlerTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ @implementation GULSwizzlerTest
- (void)testOriginalImpInstanceMethod {
Method method = class_getInstanceMethod([NSObject class], @selector(description));
IMP originalImp = method_getImplementation(method);
NSString * (^newImplementation)() = ^NSString *() {
NSString * (^newImplementation)(void) = ^NSString *() {
return @"nonsense";
};

Expand Down Expand Up @@ -155,7 +155,7 @@ - (void)testOriginalImpCallThrough {
- (void)testOriginalImpClassMethod {
Method method = class_getInstanceMethod([NSObject class], @selector(description));
IMP originalImp = method_getImplementation(method);
NSString * (^newImplementation)() = ^NSString *() {
NSString * (^newImplementation)(void) = ^NSString *() {
return @"nonsense";
};

Expand All @@ -179,7 +179,7 @@ - (void)testOriginalImpInstanceAndClassImpsAreDifferent {
IMP instanceImp = method_getImplementation(instanceMethod);
IMP classImp = method_getImplementation(classMethod);

NSString * (^newImplementation)() = ^NSString *() {
NSString * (^newImplementation)(void) = ^NSString *() {
return @"nonsense";
};

Expand Down Expand Up @@ -208,7 +208,7 @@ - (void)testOriginalImpInstanceAndClassImpsAreDifferent {
/** Tests swizzling an instance method. */
- (void)testSwizzleInstanceMethod {
NSString *swizzledDescription = @"Not what you expected!";
NSString * (^newImplementation)() = ^NSString *() {
NSString * (^newImplementation)(void) = ^NSString *() {
return swizzledDescription;
};

Expand All @@ -224,7 +224,7 @@ - (void)testSwizzleInstanceMethod {
/** Tests swizzling a class method. */
- (void)testSwizzleClassMethod {
NSString *swizzledDescription = @"Swizzled class description";
NSString * (^newImplementation)() = ^NSString *() {
NSString * (^newImplementation)(void) = ^NSString *() {
return swizzledDescription;
};

Expand All @@ -241,7 +241,7 @@ - (void)testUnswizzleInstanceMethod {
NSObject *object = [[NSObject alloc] init];
NSString *originalDescription = [object description];
NSString *swizzledDescription = @"Swizzled description";
NSString * (^newImplementation)() = ^NSString *() {
NSString * (^newImplementation)(void) = ^NSString *() {
return swizzledDescription;
};

Expand All @@ -260,7 +260,7 @@ - (void)testUnswizzleInstanceMethod {
- (void)testUnswizzleClassMethod {
NSString *originalDescription = [NSObject description];
NSString *swizzledDescription = @"Swizzled class description";
NSString * (^newImplementation)() = ^NSString *() {
NSString * (^newImplementation)(void) = ^NSString *() {
return swizzledDescription;
};

Expand All @@ -276,7 +276,7 @@ - (void)testUnswizzleClassMethod {
/** Tests swizzling a class method doesn't swizzle an instance method of the same name. */
- (void)testSwizzlingAClassMethodDoesntSwizzleAnInstanceMethod {
NSString *swizzledDescription = @"Swizzled class description";
NSString * (^newImplementation)() = ^NSString *() {
NSString * (^newImplementation)(void) = ^NSString *() {
return swizzledDescription;
};

Expand All @@ -292,7 +292,7 @@ - (void)testSwizzlingAClassMethodDoesntSwizzleAnInstanceMethod {
/** Tests swizzling an instance method doesn't swizzle a class method of the same name. */
- (void)testSwizzlingAnInstanceMethodDoesntSwizzleAClassMethod {
NSString *swizzledDescription = @"Not what you expected!";
NSString * (^newImplementation)() = ^NSString *() {
NSString * (^newImplementation)(void) = ^NSString *() {
return swizzledDescription;
};

Expand All @@ -310,7 +310,7 @@ - (void)testSwizzlingAnInstanceMethodDoesntSwizzleAClassMethod {
- (void)testSwizzlingSuperclassInstanceMethod {
NSObject *generalObject = [[NSObject alloc] init];
BOOL generalObjectIsProxyValue = [generalObject isProxy];
BOOL (^newImplementation)() = ^BOOL() {
BOOL (^newImplementation)(void) = ^BOOL() {
return !generalObjectIsProxyValue;
};

Expand All @@ -325,7 +325,7 @@ - (void)testSwizzlingSuperclassInstanceMethod {
/** Tests swizzling a superclass's class method. */
- (void)testSwizzlingSuperclassClassMethod {
NSString *swizzledDescription = @"Swizzled class description";
NSString * (^newImplementation)() = ^NSString *() {
NSString * (^newImplementation)(void) = ^NSString *() {
return swizzledDescription;
};

Expand All @@ -344,7 +344,7 @@ - (void)testSwizzlingInstanceMethodThatCallsSuper {
TestObject *testObject = [[TestObject alloc] init];
NSString *originalDescription = [testObject description];
NSString *swizzledDescription = [originalDescription stringByAppendingString:@"SWIZZLED!"];
NSString * (^newImplementation)() = ^NSString *() {
NSString * (^newImplementation)(void) = ^NSString *() {
return swizzledDescription;
};

Expand Down Expand Up @@ -492,7 +492,7 @@ - (void)testSwizzlingInstanceMethodIsEffectiveOnMultipleInstancesOfSameClass {
- (void)testSwizzlingClassMethodThatCallsSuper {
NSString *originalDescription = [TestObject description];
NSString *swizzledDescription = @"Swizzled class description";
NSString * (^newImplementation)() = ^NSString *() {
NSString * (^newImplementation)(void) = ^NSString *() {
return swizzledDescription;
};

Expand All @@ -513,7 +513,7 @@ - (void)testSwizzlingClassMethodThatCallsSuper {
- (void)testSwizzlingAnInheritedInstanceMethodDoesntAffectTheIMPOfItsSuperclass {
NSObject *generalObject = [[NSObject alloc] init];
BOOL originalGeneralObjectValue = [generalObject isProxy];
BOOL (^newImplementation)() = ^BOOL() {
BOOL (^newImplementation)(void) = ^BOOL(void) {
return !originalGeneralObjectValue;
};

Expand All @@ -533,7 +533,7 @@ - (void)testSwizzlingAnInheritedInstanceMethodDoesntAffectTheIMPOfItsSuperclass
- (void)testSwizzlingADeeperInheritedInstanceMethodDoesntAffectTheIMPOfItsSuperclass {
TestObject *testObject = [[TestObject alloc] init];
BOOL originalTestObjectValue = [testObject isProxy];
BOOL (^newImplementation)() = ^BOOL() {
BOOL (^newImplementation)(void) = ^BOOL(void) {
return !originalTestObjectValue;
};

Expand All @@ -556,7 +556,7 @@ - (void)testSwizzlingAnInheritedClassMethodDoesntAffectTheIMPOfItsSuperclass {
// Fun fact, this won't work on +new. Swizzling +new causes a retain to not be placed correctly.
NSString *originalDescription = [TestObject description];
NSString *swizzledDescription = [originalDescription stringByAppendingString:@"SWIZZLED!"];
NSString * (^newImplementation)() = ^NSString *() {
NSString * (^newImplementation)(void) = ^NSString *() {
return swizzledDescription;
};

Expand All @@ -579,7 +579,7 @@ - (void)testSwizzlingAnInheritedClassMethodDoesntAffectTheIMPOfItsSuperclass {
- (void)testSwizzlingADeeperInheritedClassMethodDoesntAffectTheIMPOfItsSuperclass {
NSString *originalDescription = [TestObjectSubclass description];
NSString *swizzledDescription = [originalDescription stringByAppendingString:@"SWIZZLED!"];
NSString * (^newImplementation)() = ^NSString *() {
NSString * (^newImplementation)(void) = ^NSString *() {
return swizzledDescription;
};

Expand Down