Skip to content

Commit 4f4d683

Browse files
authored
Fix Swizzler test warnings (#2144)
1 parent 9eedf74 commit 4f4d683

File tree

3 files changed

+29
-22
lines changed

3 files changed

+29
-22
lines changed

GoogleUtilities/Example/Tests/Swizzler/GULAppDelegateSwizzlerTest.m

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,8 @@ - (BOOL)application:(UIApplication *)application
181181

182182
- (BOOL)application:(UIApplication *)application
183183
continueUserActivity:(NSUserActivity *)userActivity
184-
restorationHandler:(void (^)(NSArray *__nullable restorableObjects))restorationHandler {
184+
restorationHandler:(void (^)(NSArray<id<UIUserActivityRestoring>> *__nullable
185+
restorableObjects))restorationHandler {
185186
_userActivity = userActivity;
186187
return YES;
187188
}
@@ -261,7 +262,7 @@ - (void)testHandleBackgroundSessionMethod {
261262

262263
UIApplication *currentApplication = [UIApplication sharedApplication];
263264
NSString *sessionID = @"123";
264-
void (^nilHandler)() = nil;
265+
void (^nilHandler)(void) = nil;
265266
[realAppDelegate application:currentApplication
266267
handleEventsForBackgroundURLSession:sessionID
267268
completionHandler:nilHandler];
@@ -274,8 +275,11 @@ - (void)testHandleBackgroundSessionMethod {
274275

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

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

305309
// Try to unregister an empty string. Should not remove anything.
310+
#pragma clang diagnostic push
311+
#pragma clang diagnostic ignored "-Wnonnull"
306312
XCTAssertThrows([GULAppDelegateSwizzler unregisterAppDelegateInterceptorWithID:nil],
307313
@"Should not unregister nil interceptorID");
308314
XCTAssertEqual([GULAppDelegateSwizzler interceptors].count, 1);

GoogleUtilities/Example/Tests/Swizzler/GULSwizzlerInheritedMethodsSwizzlingTest.m

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,16 @@ - (void)testSwizzlingAndUnswizzlingInheritedInstanceMethodsForSuperclassesWorksA
110110
NSString *swizzledPollutedTestObjectSubclassSubclassDescription =
111111
[originalPollutedTestObjectSubclassSubclassDescription stringByAppendingString:@"SWIZZLED!"];
112112

113-
NSString * (^newImplementationPollutedTestObject)() = ^NSString *(id _self) {
113+
NSString * (^newImplementationPollutedTestObject)(NSString *) = ^NSString *(id _self) {
114114
return swizzledPollutedTestObjectDescription;
115115
};
116116

117-
NSString * (^newImplementationPollutedTestObjectSubclass)() = ^NSString *(id _self) {
117+
NSString * (^newImplementationPollutedTestObjectSubclass)(NSString *) = ^NSString *(id _self) {
118118
return swizzledPollutedTestObjectSubclassDescription;
119119
};
120120

121-
NSString * (^newImplementationPollutedTestObjectSubclassSubclass)() = ^NSString *(id _self) {
121+
NSString * (^newImplementationPollutedTestObjectSubclassSubclass)(NSString *) =
122+
^NSString *(id _self) {
122123
return swizzledPollutedTestObjectSubclassSubclassDescription;
123124
};
124125

GoogleUtilities/Example/Tests/Swizzler/GULSwizzlerTest.m

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ @implementation GULSwizzlerTest
6969
- (void)testOriginalImpInstanceMethod {
7070
Method method = class_getInstanceMethod([NSObject class], @selector(description));
7171
IMP originalImp = method_getImplementation(method);
72-
NSString * (^newImplementation)() = ^NSString *() {
72+
NSString * (^newImplementation)(void) = ^NSString *() {
7373
return @"nonsense";
7474
};
7575

@@ -155,7 +155,7 @@ - (void)testOriginalImpCallThrough {
155155
- (void)testOriginalImpClassMethod {
156156
Method method = class_getInstanceMethod([NSObject class], @selector(description));
157157
IMP originalImp = method_getImplementation(method);
158-
NSString * (^newImplementation)() = ^NSString *() {
158+
NSString * (^newImplementation)(void) = ^NSString *() {
159159
return @"nonsense";
160160
};
161161

@@ -179,7 +179,7 @@ - (void)testOriginalImpInstanceAndClassImpsAreDifferent {
179179
IMP instanceImp = method_getImplementation(instanceMethod);
180180
IMP classImp = method_getImplementation(classMethod);
181181

182-
NSString * (^newImplementation)() = ^NSString *() {
182+
NSString * (^newImplementation)(void) = ^NSString *() {
183183
return @"nonsense";
184184
};
185185

@@ -208,7 +208,7 @@ - (void)testOriginalImpInstanceAndClassImpsAreDifferent {
208208
/** Tests swizzling an instance method. */
209209
- (void)testSwizzleInstanceMethod {
210210
NSString *swizzledDescription = @"Not what you expected!";
211-
NSString * (^newImplementation)() = ^NSString *() {
211+
NSString * (^newImplementation)(void) = ^NSString *() {
212212
return swizzledDescription;
213213
};
214214

@@ -224,7 +224,7 @@ - (void)testSwizzleInstanceMethod {
224224
/** Tests swizzling a class method. */
225225
- (void)testSwizzleClassMethod {
226226
NSString *swizzledDescription = @"Swizzled class description";
227-
NSString * (^newImplementation)() = ^NSString *() {
227+
NSString * (^newImplementation)(void) = ^NSString *() {
228228
return swizzledDescription;
229229
};
230230

@@ -241,7 +241,7 @@ - (void)testUnswizzleInstanceMethod {
241241
NSObject *object = [[NSObject alloc] init];
242242
NSString *originalDescription = [object description];
243243
NSString *swizzledDescription = @"Swizzled description";
244-
NSString * (^newImplementation)() = ^NSString *() {
244+
NSString * (^newImplementation)(void) = ^NSString *() {
245245
return swizzledDescription;
246246
};
247247

@@ -260,7 +260,7 @@ - (void)testUnswizzleInstanceMethod {
260260
- (void)testUnswizzleClassMethod {
261261
NSString *originalDescription = [NSObject description];
262262
NSString *swizzledDescription = @"Swizzled class description";
263-
NSString * (^newImplementation)() = ^NSString *() {
263+
NSString * (^newImplementation)(void) = ^NSString *() {
264264
return swizzledDescription;
265265
};
266266

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

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

@@ -310,7 +310,7 @@ - (void)testSwizzlingAnInstanceMethodDoesntSwizzleAClassMethod {
310310
- (void)testSwizzlingSuperclassInstanceMethod {
311311
NSObject *generalObject = [[NSObject alloc] init];
312312
BOOL generalObjectIsProxyValue = [generalObject isProxy];
313-
BOOL (^newImplementation)() = ^BOOL() {
313+
BOOL (^newImplementation)(void) = ^BOOL() {
314314
return !generalObjectIsProxyValue;
315315
};
316316

@@ -325,7 +325,7 @@ - (void)testSwizzlingSuperclassInstanceMethod {
325325
/** Tests swizzling a superclass's class method. */
326326
- (void)testSwizzlingSuperclassClassMethod {
327327
NSString *swizzledDescription = @"Swizzled class description";
328-
NSString * (^newImplementation)() = ^NSString *() {
328+
NSString * (^newImplementation)(void) = ^NSString *() {
329329
return swizzledDescription;
330330
};
331331

@@ -344,7 +344,7 @@ - (void)testSwizzlingInstanceMethodThatCallsSuper {
344344
TestObject *testObject = [[TestObject alloc] init];
345345
NSString *originalDescription = [testObject description];
346346
NSString *swizzledDescription = [originalDescription stringByAppendingString:@"SWIZZLED!"];
347-
NSString * (^newImplementation)() = ^NSString *() {
347+
NSString * (^newImplementation)(void) = ^NSString *() {
348348
return swizzledDescription;
349349
};
350350

@@ -492,7 +492,7 @@ - (void)testSwizzlingInstanceMethodIsEffectiveOnMultipleInstancesOfSameClass {
492492
- (void)testSwizzlingClassMethodThatCallsSuper {
493493
NSString *originalDescription = [TestObject description];
494494
NSString *swizzledDescription = @"Swizzled class description";
495-
NSString * (^newImplementation)() = ^NSString *() {
495+
NSString * (^newImplementation)(void) = ^NSString *() {
496496
return swizzledDescription;
497497
};
498498

@@ -513,7 +513,7 @@ - (void)testSwizzlingClassMethodThatCallsSuper {
513513
- (void)testSwizzlingAnInheritedInstanceMethodDoesntAffectTheIMPOfItsSuperclass {
514514
NSObject *generalObject = [[NSObject alloc] init];
515515
BOOL originalGeneralObjectValue = [generalObject isProxy];
516-
BOOL (^newImplementation)() = ^BOOL() {
516+
BOOL (^newImplementation)(void) = ^BOOL(void) {
517517
return !originalGeneralObjectValue;
518518
};
519519

@@ -533,7 +533,7 @@ - (void)testSwizzlingAnInheritedInstanceMethodDoesntAffectTheIMPOfItsSuperclass
533533
- (void)testSwizzlingADeeperInheritedInstanceMethodDoesntAffectTheIMPOfItsSuperclass {
534534
TestObject *testObject = [[TestObject alloc] init];
535535
BOOL originalTestObjectValue = [testObject isProxy];
536-
BOOL (^newImplementation)() = ^BOOL() {
536+
BOOL (^newImplementation)(void) = ^BOOL(void) {
537537
return !originalTestObjectValue;
538538
};
539539

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

@@ -579,7 +579,7 @@ - (void)testSwizzlingAnInheritedClassMethodDoesntAffectTheIMPOfItsSuperclass {
579579
- (void)testSwizzlingADeeperInheritedClassMethodDoesntAffectTheIMPOfItsSuperclass {
580580
NSString *originalDescription = [TestObjectSubclass description];
581581
NSString *swizzledDescription = [originalDescription stringByAppendingString:@"SWIZZLED!"];
582-
NSString * (^newImplementation)() = ^NSString *() {
582+
NSString * (^newImplementation)(void) = ^NSString *() {
583583
return swizzledDescription;
584584
};
585585

0 commit comments

Comments
 (0)