From c01c7277151558fe0ee97262f09b569d1f0c9d59 Mon Sep 17 00:00:00 2001 From: Cristian Kocza Date: Thu, 8 May 2014 18:56:51 +0300 Subject: [PATCH 1/2] Fixed KWMessagePattern not matching class arguments. --- Kiwi.xcodeproj/project.pbxproj | 4 ++-- NonARC/KWMessagePattern.m | 2 +- Tests/KWFunctionalTests.m | 12 ++++++++++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/Kiwi.xcodeproj/project.pbxproj b/Kiwi.xcodeproj/project.pbxproj index d7cf5544..56b5c4d7 100755 --- a/Kiwi.xcodeproj/project.pbxproj +++ b/Kiwi.xcodeproj/project.pbxproj @@ -340,7 +340,7 @@ 9F982D9216A802920030A0B1 /* KWIntercept.h in Headers */ = {isa = PBXBuildFile; fileRef = 9F982C9316A802920030A0B1 /* KWIntercept.h */; }; 9F982D9316A802920030A0B1 /* KWIntercept.h in Headers */ = {isa = PBXBuildFile; fileRef = 9F982C9316A802920030A0B1 /* KWIntercept.h */; }; 9F982D9416A802920030A0B1 /* KWIntercept.m in Sources */ = {isa = PBXBuildFile; fileRef = 9F982C9416A802920030A0B1 /* KWIntercept.m */; }; - 9F982D9516A802920030A0B1 /* KWIntercept.m in Sources */ = {isa = PBXBuildFile; fileRef = 9F982C9416A802920030A0B1 /* KWIntercept.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; + 9F982D9516A802920030A0B1 /* KWIntercept.m in Sources */ = {isa = PBXBuildFile; fileRef = 9F982C9416A802920030A0B1 /* KWIntercept.m */; }; 9F982D9616A802920030A0B1 /* KWInvocationCapturer.h in Headers */ = {isa = PBXBuildFile; fileRef = 9F982C9516A802920030A0B1 /* KWInvocationCapturer.h */; }; 9F982D9716A802920030A0B1 /* KWInvocationCapturer.h in Headers */ = {isa = PBXBuildFile; fileRef = 9F982C9516A802920030A0B1 /* KWInvocationCapturer.h */; }; 9F982D9816A802920030A0B1 /* KWInvocationCapturer.m in Sources */ = {isa = PBXBuildFile; fileRef = 9F982C9616A802920030A0B1 /* KWInvocationCapturer.m */; settings = {COMPILER_FLAGS = ""; }; }; @@ -436,7 +436,7 @@ 9F982DF216A802920030A0B1 /* KWStub.h in Headers */ = {isa = PBXBuildFile; fileRef = 9F982CC316A802920030A0B1 /* KWStub.h */; }; 9F982DF316A802920030A0B1 /* KWStub.h in Headers */ = {isa = PBXBuildFile; fileRef = 9F982CC316A802920030A0B1 /* KWStub.h */; }; 9F982DF416A802920030A0B1 /* KWStub.m in Sources */ = {isa = PBXBuildFile; fileRef = 9F982CC416A802920030A0B1 /* KWStub.m */; }; - 9F982DF516A802920030A0B1 /* KWStub.m in Sources */ = {isa = PBXBuildFile; fileRef = 9F982CC416A802920030A0B1 /* KWStub.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; + 9F982DF516A802920030A0B1 /* KWStub.m in Sources */ = {isa = PBXBuildFile; fileRef = 9F982CC416A802920030A0B1 /* KWStub.m */; }; 9F982DFA16A802920030A0B1 /* KWUserDefinedMatcher.h in Headers */ = {isa = PBXBuildFile; fileRef = 9F982CC716A802920030A0B1 /* KWUserDefinedMatcher.h */; }; 9F982DFB16A802920030A0B1 /* KWUserDefinedMatcher.h in Headers */ = {isa = PBXBuildFile; fileRef = 9F982CC716A802920030A0B1 /* KWUserDefinedMatcher.h */; }; 9F982DFC16A802920030A0B1 /* KWUserDefinedMatcher.m in Sources */ = {isa = PBXBuildFile; fileRef = 9F982CC816A802920030A0B1 /* KWUserDefinedMatcher.m */; settings = {COMPILER_FLAGS = ""; }; }; diff --git a/NonARC/KWMessagePattern.m b/NonARC/KWMessagePattern.m index 11d2a748..9310e11d 100644 --- a/NonARC/KWMessagePattern.m +++ b/NonARC/KWMessagePattern.m @@ -74,7 +74,7 @@ + (id)messagePatternFromInvocation:(NSInvocation *)anInvocation { void* argumentDataBuffer = malloc(KWObjCTypeLength(type)); [anInvocation getMessageArgument:argumentDataBuffer atIndex:i]; id object = nil; - if(*(id*)argumentDataBuffer != [KWAny any] && !KWObjCTypeIsObject(type)) { + if(*(id*)argumentDataBuffer != [KWAny any] && !KWObjCTypeIsObject(type) && !KWObjCTypeIsClass(type)) { NSData *data = [anInvocation messageArgumentDataAtIndex:i]; object = [KWValue valueWithBytes:[data bytes] objCType:type]; } else { diff --git a/Tests/KWFunctionalTests.m b/Tests/KWFunctionalTests.m index d5993c3d..14ebad0f 100644 --- a/Tests/KWFunctionalTests.m +++ b/Tests/KWFunctionalTests.m @@ -273,6 +273,18 @@ @interface KWExampleSuiteBuilder () SPEC_END +SPEC_BEGIN(FunctionalMatchers) + +describe(@"receive matcher",^{ + it(@"Recognizes params with classes",^{ + NSMutableArray *array = [NSMutableArray array]; + [[[array should] receive] isKindOfClass:[NSArray class]]; + [array isKindOfClass:[NSArray class]]; + }); +}); + +SPEC_END + #if KW_TESTS_ENABLED @interface KWFunctionalTests : SenTestCase @end From 788c0b7dee3bb9a53d3204289c3e819391e41d1b Mon Sep 17 00:00:00 2001 From: Cristian Kocza Date: Thu, 8 May 2014 19:39:49 +0300 Subject: [PATCH 2/2] KWFormatter: don't try to enumerate class objects conforming to NSEnumberable --- Classes/Core/KWFormatter.m | 3 ++- Tests/KWFormatterTest.m | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Classes/Core/KWFormatter.m b/Classes/Core/KWFormatter.m index f12917e2..e0ce8fd9 100644 --- a/Classes/Core/KWFormatter.m +++ b/Classes/Core/KWFormatter.m @@ -5,6 +5,7 @@ // #import "KWFormatter.h" +#import @implementation KWFormatter @@ -18,7 +19,7 @@ + (NSString *)formatObject:(id)anObject { else if ([anObject isKindOfClass:[NSDictionary class]]) return [anObject description]; // NSDictionary conforms to NSFastEnumeration - else if ([anObject conformsToProtocol:@protocol(NSFastEnumeration)]) + else if ([anObject conformsToProtocol:@protocol(NSFastEnumeration)] && !class_isMetaClass(object_getClass(anObject))) return [self formattedCollection:anObject]; return [anObject description]; diff --git a/Tests/KWFormatterTest.m b/Tests/KWFormatterTest.m index 0065a649..0c9a3941 100644 --- a/Tests/KWFormatterTest.m +++ b/Tests/KWFormatterTest.m @@ -32,6 +32,14 @@ - (void)testFormatsDictionariesWithKeysAndValuesMultiline { STAssertEqualObjects([sampleDict description], [KWFormatter formatObject:sampleDict], @"Dictionaries should be not treated as NSEnumerable"); } +- (void)testClassObjects{ + STAssertEqualObjects([KWFormatter formatObject:[NSNumber class]], @"NSNumber", @"Classes should get outputted with their name"); +} + +- (void)testTreatsNSEnumerableClassObjectAsClass{ + STAssertNoThrow([KWFormatter formatObject:[NSArray class]], @"Enumerable classes should not be threated as their instances"); +} + @end #endif // #if KW_TESTS_ENABLED