Skip to content

Commit

Permalink
Merge pull request #371 from briancroom/print_pending_tests
Browse files Browse the repository at this point in the history
Pending tests should be printed when running under XCTest
  • Loading branch information
idoru committed Mar 22, 2016
2 parents 9ab7ca0 + 8c2b850 commit 1273d9b
Show file tree
Hide file tree
Showing 8 changed files with 153 additions and 48 deletions.
16 changes: 13 additions & 3 deletions Cedar.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -266,13 +266,16 @@
34ADD2EE19220F9300B057AC /* AnyInstanceConformingToProtocolArgument.h in Copy headers to framework */ = {isa = PBXBuildFile; fileRef = 34ADD2E41921F2F600B057AC /* AnyInstanceConformingToProtocolArgument.h */; };
34ADE41818F23C8E00BD1E99 /* NSMethodSignature+Cedar.m in Sources */ = {isa = PBXBuildFile; fileRef = 34ADE41618F23C8E00BD1E99 /* NSMethodSignature+Cedar.m */; };
34ADE41918F23E6B00BD1E99 /* NSMethodSignature+Cedar.m in Sources */ = {isa = PBXBuildFile; fileRef = 34ADE41618F23C8E00BD1E99 /* NSMethodSignature+Cedar.m */; };
34AF814E1C53339300DB5249 /* TestReporter.m in Sources */ = {isa = PBXBuildFile; fileRef = 34AF814D1C53339300DB5249 /* TestReporter.m */; };
34AF814F1C53A06500DB5249 /* TestReporter.m in Sources */ = {isa = PBXBuildFile; fileRef = 34AF814D1C53339300DB5249 /* TestReporter.m */; settings = {COMPILER_FLAGS = "-fobjc-arc"; }; };
34AF81501C53A06600DB5249 /* TestReporter.m in Sources */ = {isa = PBXBuildFile; fileRef = 34AF814D1C53339300DB5249 /* TestReporter.m */; settings = {COMPILER_FLAGS = "-fobjc-arc"; }; };
34C95F501C2DD7B30055F089 /* CDRNullabilityCompat.h in Headers */ = {isa = PBXBuildFile; fileRef = 34C95F4F1C2DD7B30055F089 /* CDRNullabilityCompat.h */; settings = {ATTRIBUTES = (Public, ); }; };
34C95F511C2DD7B30055F089 /* CDRNullabilityCompat.h in Headers */ = {isa = PBXBuildFile; fileRef = 34C95F4F1C2DD7B30055F089 /* CDRNullabilityCompat.h */; settings = {ATTRIBUTES = (Public, ); }; };
34C95F521C2DD7B30055F089 /* CDRNullabilityCompat.h in Headers */ = {isa = PBXBuildFile; fileRef = 34C95F4F1C2DD7B30055F089 /* CDRNullabilityCompat.h */; settings = {ATTRIBUTES = (Public, ); }; };
34C95F531C2DD7B30055F089 /* CDRNullabilityCompat.h in Headers */ = {isa = PBXBuildFile; fileRef = 34C95F4F1C2DD7B30055F089 /* CDRNullabilityCompat.h */; settings = {ATTRIBUTES = (Public, ); }; };
34C95F541C2DD7B30055F089 /* CDRNullabilityCompat.h in Copy headers to framework */ = {isa = PBXBuildFile; fileRef = 34C95F4F1C2DD7B30055F089 /* CDRNullabilityCompat.h */; };
34C95F551C2E57A90055F089 /* SwiftSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34DB67481C2B4D6A00206663 /* SwiftSpec.swift */; };
34C95F561C2F16900055F089 /* CDRXCTestSuiteSpec.mm in Sources */ = {isa = PBXBuildFile; fileRef = AE34724019C2259B005CA6F1 /* CDRXCTestSuiteSpec.mm */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };
34C95F561C2F16900055F089 /* CDRXCTestSuiteSpec.mm in Sources */ = {isa = PBXBuildFile; fileRef = AE34724019C2259B005CA6F1 /* CDRXCTestSuiteSpec.mm */; };
34D1819C1BC7F0E60087EC0D /* BlockMatcher.h in Headers */ = {isa = PBXBuildFile; fileRef = 346F64681B82D01700F64156 /* BlockMatcher.h */; settings = {ATTRIBUTES = (Public, ); }; };
34D1819D1BC7F0E70087EC0D /* BlockMatcher.h in Headers */ = {isa = PBXBuildFile; fileRef = 346F64681B82D01700F64156 /* BlockMatcher.h */; settings = {ATTRIBUTES = (Public, ); }; };
34D1819E1BC7F0FD0087EC0D /* BlockMatcherSpec.mm in Sources */ = {isa = PBXBuildFile; fileRef = 346F646D1B82D3C900F64156 /* BlockMatcherSpec.mm */; };
Expand Down Expand Up @@ -448,7 +451,7 @@
34D7C4831BB9C61A00E8E523 /* ObjectWithValueEquality.m in Sources */ = {isa = PBXBuildFile; fileRef = 9D28051818E2321D00887CC4 /* ObjectWithValueEquality.m */; };
34D7C4841BB9C61E00E8E523 /* FooSuperclass.m in Sources */ = {isa = PBXBuildFile; fileRef = AED10EBB18F46C0E00950904 /* FooSuperclass.m */; };
34D7C4851BB9C62400E8E523 /* DeallocNotifier.m in Sources */ = {isa = PBXBuildFile; fileRef = 343FAFE9190FDAEC0085AFEC /* DeallocNotifier.m */; };
34D7C4861BB9C65700E8E523 /* CDRXCTestSuiteSpec.mm in Sources */ = {isa = PBXBuildFile; fileRef = AE34724019C2259B005CA6F1 /* CDRXCTestSuiteSpec.mm */; };
34D7C4861BB9C65700E8E523 /* CDRXCTestSuiteSpec.mm in Sources */ = {isa = PBXBuildFile; fileRef = AE34724019C2259B005CA6F1 /* CDRXCTestSuiteSpec.mm */; settings = {COMPILER_FLAGS = "-fobjc-arc"; }; };
34D7C4871BB9C66000E8E523 /* CedarApplicationDelegateSpec.mm in Sources */ = {isa = PBXBuildFile; fileRef = AE7DD11117296CB20058EB3B /* CedarApplicationDelegateSpec.mm */; };
34D7C4881BB9C67100E8E523 /* WeakReferenceCompatibilitySpec.mm in Sources */ = {isa = PBXBuildFile; fileRef = AE5218D4175979D900A656BC /* WeakReferenceCompatibilitySpec.mm */; };
34D7C4891BB9C67400E8E523 /* CDRSpyiOSSpec.mm in Sources */ = {isa = PBXBuildFile; fileRef = 228F3FA617E3ECD10000C8AF /* CDRSpyiOSSpec.mm */; };
Expand Down Expand Up @@ -763,7 +766,7 @@
AE34723719C12534005CA6F1 /* FibonacciCalculator.m in Sources */ = {isa = PBXBuildFile; fileRef = E32861311604F287001FA77E /* FibonacciCalculator.m */; };
AE34723919C12588005CA6F1 /* SimpleKeyValueObserver.m in Sources */ = {isa = PBXBuildFile; fileRef = AE80788C183C71950078C608 /* SimpleKeyValueObserver.m */; };
AE34723D19C22547005CA6F1 /* CDRDefaultReporterSpec.mm in Sources */ = {isa = PBXBuildFile; fileRef = AEBCDD7E173ACD6700B42B58 /* CDRDefaultReporterSpec.mm */; };
AE34724619C225A1005CA6F1 /* CDRXCTestSuiteSpec.mm in Sources */ = {isa = PBXBuildFile; fileRef = AE34724019C2259B005CA6F1 /* CDRXCTestSuiteSpec.mm */; };
AE34724619C225A1005CA6F1 /* CDRXCTestSuiteSpec.mm in Sources */ = {isa = PBXBuildFile; fileRef = AE34724019C2259B005CA6F1 /* CDRXCTestSuiteSpec.mm */; settings = {COMPILER_FLAGS = "-fobjc-arc"; }; };
AE34724B19C37ECF005CA6F1 /* CDRXCTestCase.h in Headers */ = {isa = PBXBuildFile; fileRef = AE34724919C37ECF005CA6F1 /* CDRXCTestCase.h */; };
AE34724D19C37ECF005CA6F1 /* CDRXCTestCase.m in Sources */ = {isa = PBXBuildFile; fileRef = AE34724A19C37ECF005CA6F1 /* CDRXCTestCase.m */; };
AE34724E19C37ECF005CA6F1 /* CDRXCTestCase.m in Sources */ = {isa = PBXBuildFile; fileRef = AE34724A19C37ECF005CA6F1 /* CDRXCTestCase.m */; };
Expand Down Expand Up @@ -1427,6 +1430,8 @@
34ADD2E41921F2F600B057AC /* AnyInstanceConformingToProtocolArgument.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AnyInstanceConformingToProtocolArgument.h; sourceTree = "<group>"; };
34ADD2E51921F33800B057AC /* AnyInstanceConformingToProtocolArgument.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = AnyInstanceConformingToProtocolArgument.mm; sourceTree = "<group>"; };
34ADE41618F23C8E00BD1E99 /* NSMethodSignature+Cedar.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSMethodSignature+Cedar.m"; sourceTree = "<group>"; };
34AF814C1C53339300DB5249 /* TestReporter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TestReporter.h; sourceTree = "<group>"; };
34AF814D1C53339300DB5249 /* TestReporter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TestReporter.m; sourceTree = "<group>"; };
34C95F4F1C2DD7B30055F089 /* CDRNullabilityCompat.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CDRNullabilityCompat.h; sourceTree = "<group>"; };
34D1E67A18F7A2E6005161AD /* AnInstanceOf.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = AnInstanceOf.h; path = ../Comparators/AnInstanceOf.h; sourceTree = "<group>"; };
34D4B5C118F3ADFF00FB2C3B /* UIKitContainSpec.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = UIKitContainSpec.mm; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2504,6 +2509,8 @@
AED10EBB18F46C0E00950904 /* FooSuperclass.m */,
343FAFE8190FDAEC0085AFEC /* DeallocNotifier.h */,
343FAFE9190FDAEC0085AFEC /* DeallocNotifier.m */,
34AF814C1C53339300DB5249 /* TestReporter.h */,
34AF814D1C53339300DB5249 /* TestReporter.m */,
);
path = Support;
sourceTree = "<group>";
Expand Down Expand Up @@ -3506,6 +3513,7 @@
1F45A3D0180E4796003C1E36 /* CDRSymbolicatorSpec.mm in Sources */,
AE34723919C12588005CA6F1 /* SimpleKeyValueObserver.m in Sources */,
F78FDA1B1B43AB540054C768 /* SimpleIncrementer.m in Sources */,
34AF814F1C53A06500DB5249 /* TestReporter.m in Sources */,
AE34723419C124D6005CA6F1 /* ObjCHeadersSpec.mm in Sources */,
34322B0C1BA7471B00D0CFBD /* TestObservationHelper.m in Sources */,
AE34723D19C22547005CA6F1 /* CDRDefaultReporterSpec.mm in Sources */,
Expand Down Expand Up @@ -3766,6 +3774,7 @@
34D7C4861BB9C65700E8E523 /* CDRXCTestSuiteSpec.mm in Sources */,
34D7C4931BB9C67C00E8E523 /* BeSameInstanceAs_ARCSpec.mm in Sources */,
34D7C47F1BB9C60A00E8E523 /* SimpleIncrementer.m in Sources */,
34AF81501C53A06600DB5249 /* TestReporter.m in Sources */,
34D7C4B11BB9C6C400E8E523 /* SpecSpec.mm in Sources */,
34D7C47C1BB9C5FD00E8E523 /* ObjectWithProperty.m in Sources */,
34D1819E1BC7F0FD0087EC0D /* BlockMatcherSpec.mm in Sources */,
Expand Down Expand Up @@ -3907,6 +3916,7 @@
34757E261BA4A48E0047BC8D /* TestObservationHelper.m in Sources */,
346D1A971BBB37F400BECD4B /* SpecBundleApplicationTestsWithXCTest.m in Sources */,
345B1E8F1C31DA6E009BB77D /* XCTAssertSpec.swift in Sources */,
34AF814E1C53339300DB5249 /* TestReporter.m in Sources */,
34C95F561C2F16900055F089 /* CDRXCTestSuiteSpec.mm in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
4 changes: 3 additions & 1 deletion Source/Headers/Project/XCTest/NSInvocation+CDRXExample.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
@interface NSInvocation (CDRXExample)

@property (nonatomic, retain, setter=cdr_setDispatcher:) CDRReportDispatcher *cdr_dispatcher;
@property (nonatomic, retain, setter=cdr_setExample:) CDRExample *cdr_example;
@property (nonatomic, retain, setter=cdr_setExamples:) NSArray *cdr_examples;
@property (nonatomic, retain, setter=cdr_setSpecClassName:) NSString *cdr_specClassName;

- (void)cdr_addSupplementaryExample:(CDRExample *)example;

@end
41 changes: 30 additions & 11 deletions Source/XCTest/CDRSpec+XCTestSupport.m
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,15 @@ - (id)testSuiteWithRandomSeed:(unsigned int)seed dispatcher:(CDRReportDispatcher
NSArray *examples = [self allExamplesToRun];

NSMutableArray *testInvocations = [NSMutableArray array];
NSMutableArray *unusedPendingExamples = [NSMutableArray array];
for (CDRExample *example in examples) {
if (!example.isPending) {
if (example.isPending) {
if (testInvocations.count > 0) {
[[testInvocations lastObject] cdr_addSupplementaryExample:example];
} else {
[unusedPendingExamples addObject:example];
}
} else {
NSString *methodName = [namer methodNameForExample:example withClassName:NSStringFromClass([self class])];
SEL selector = NSSelectorFromString(methodName);
NSMethodSignature *methodSignature = [newXCTestSubclass instanceMethodSignatureForSelector:selector];
Expand All @@ -60,9 +67,11 @@ - (id)testSuiteWithRandomSeed:(unsigned int)seed dispatcher:(CDRReportDispatcher
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:methodSignature];
invocation.selector = selector;
invocation.cdr_dispatcher = dispatcher;
invocation.cdr_example = example;
invocation.cdr_examples = [unusedPendingExamples arrayByAddingObject:example];
invocation.cdr_specClassName = className;
[testInvocations addObject:invocation];

[unusedPendingExamples removeAllObjects];
}
}

Expand Down Expand Up @@ -109,13 +118,17 @@ - (NSArray *)allExamplesToRun {
return examples;
}

- (void)createTestMethodForSelector:(SEL)selector onClass:(Class)aClass {
IMP imp = imp_implementationWithBlock(^(id instance){
CDRExample *example = [[instance invocation] cdr_example];
static void testMethodImplementation(id instance, SEL _cmd) {
NSMutableSet *alreadyReportedExampleGroups = [NSMutableSet set];
CDRReportDispatcher *theDispatcher = [[instance invocation] cdr_dispatcher];

for (CDRExample *example in [[instance invocation] cdr_examples]) {
CDRExampleGroup *parentGroup = (CDRExampleGroup *)example.parent;
CDRReportDispatcher *theDispatcher = [[instance invocation] cdr_dispatcher];
while (![parentGroup isEqual:example.spec.rootGroup]) {
[theDispatcher runWillStartExampleGroup:parentGroup];
if (![alreadyReportedExampleGroups containsObject:parentGroup]) {
[theDispatcher runWillStartExampleGroup:parentGroup];
}

parentGroup = (CDRExampleGroup *)[parentGroup parent];
}

Expand All @@ -133,14 +146,20 @@ - (void)createTestMethodForSelector:(SEL)selector onClass:(Class)aClass {

parentGroup = (CDRExampleGroup *)example.parent;
while (![parentGroup isEqual:example.spec.rootGroup]) {
[theDispatcher runDidFinishExampleGroup:parentGroup];
if (![alreadyReportedExampleGroups containsObject:parentGroup]) {
[theDispatcher runDidFinishExampleGroup:parentGroup];
[alreadyReportedExampleGroups addObject:parentGroup];
}

parentGroup = (CDRExampleGroup *)[parentGroup parent];
}
});
Method m = class_getInstanceMethod([self class], @selector(defineBehaviors));
}
}

- (void)createTestMethodForSelector:(SEL)selector onClass:(Class)aClass {
Method m = class_getInstanceMethod([self class], @selector(defineBehaviors));
const char *encoding = method_getTypeEncoding(m);
class_addMethod(aClass, selector, imp, encoding);
class_addMethod(aClass, selector, (IMP)testMethodImplementation, encoding);
}

@end
3 changes: 2 additions & 1 deletion Source/XCTest/CDRXCTestCase.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ + (void)setTestInvocations:(NSArray *)array {
} while(0);

- (void)recordFailureWithDescription:(NSString *)description inFile:(NSString *)filename atLine:(NSUInteger)lineNumber expected:(BOOL)expected {
if (self.invocation.cdr_example.state == CDRExampleStateIncomplete) {
CDRExample *example = self.invocation.cdr_examples.firstObject;
if (example.state == CDRExampleStateIncomplete) {
[[CDRSpecFailure specFailureWithReason:description fileName:filename lineNumber:(int)lineNumber] raise];
} else {
super_recordFailure(description, filename, lineNumber, expected);
Expand Down
15 changes: 10 additions & 5 deletions Source/XCTest/NSInvocation+CDRXExample.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#import <objc/runtime.h>

const char *CDRXDispatcherKey;
const char *CDRXExampleKey;
const char *CDRXExamplesKey;
const char *CDRXSpecClassNameKey;


Expand All @@ -16,12 +16,12 @@ - (void)cdr_setDispatcher:(CDRReportDispatcher *)dispatcher {
objc_setAssociatedObject(self, &CDRXDispatcherKey, dispatcher, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

- (CDRExample *)cdr_example {
return objc_getAssociatedObject(self, &CDRXExampleKey);
- (NSArray *)cdr_examples {
return objc_getAssociatedObject(self, &CDRXExamplesKey);
}

- (void)cdr_setExample:(CDRExample *)example {
objc_setAssociatedObject(self, &CDRXExampleKey, example, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
- (void)cdr_setExamples:(NSArray *)examples {
objc_setAssociatedObject(self, &CDRXExamplesKey, examples, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

- (NSString *)cdr_specClassName {
Expand All @@ -32,4 +32,9 @@ - (void)cdr_setSpecClassName:(NSString *)specClassName {
objc_setAssociatedObject(self, &CDRXSpecClassNameKey, specClassName, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

- (void)cdr_addSupplementaryExample:(CDRExample *)example {
NSArray *existingExamples = self.cdr_examples ?: @[];
self.cdr_examples = [existingExamples arrayByAddingObject:example];
}

@end
17 changes: 17 additions & 0 deletions Spec/Support/TestReporter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#import <Foundation/Foundation.h>
#import "Cedar.h"
#import "CDRNullabilityCompat.h"

NS_ASSUME_NONNULL_BEGIN

@interface TestReporter : NSObject <CDRExampleReporter>

@property (nonatomic, readonly) NSArray *startedExamples;
@property (nonatomic, readonly) NSArray *finishedExamples;

@property (nonatomic, readonly) NSArray *startedExampleGroups;
@property (nonatomic, readonly) NSArray *finishedExampleGroups;

@end

NS_ASSUME_NONNULL_END
47 changes: 47 additions & 0 deletions Spec/Support/TestReporter.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#import "TestReporter.h"

#if !__has_feature(objc_arc)
#error This class must be compiled with ARC.
#endif

@implementation TestReporter {
NSMutableArray *_startedExamples;
NSMutableArray *_finishedExamples;
NSMutableArray *_startedExampleGroups;
NSMutableArray *_finishedExampleGroups;
}

- (instancetype)init {
if (self = [super init]) {
_startedExamples = [NSMutableArray array];
_finishedExamples = [NSMutableArray array];
_startedExampleGroups = [NSMutableArray array];
_finishedExampleGroups = [NSMutableArray array];
}
return self;
}

- (void)runWillStartWithGroups:(NSArray *)groups andRandomSeed:(unsigned int)seed {}
- (void)runDidComplete {}
- (int)result {
return 0;
}

- (void)runWillStartExample:(CDRExample *)example {
[_startedExamples addObject:example];
}
- (void)runDidFinishExample:(CDRExample *)example {
[_finishedExamples addObject:example];
}

- (void)runWillStartExampleGroup:(CDRExampleGroup *)exampleGroup {
[_startedExampleGroups addObject:exampleGroup];
}
- (void)runDidFinishExampleGroup:(CDRExampleGroup *)exampleGroup {
[_finishedExampleGroups addObject:exampleGroup];
}

- (void)runWillStartSpec:(CDRSpec *)spec {}
- (void)runDidFinishSpec:(CDRSpec *)spec {}

@end
Loading

0 comments on commit 1273d9b

Please sign in to comment.