Skip to content
Open
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
2 changes: 0 additions & 2 deletions SenTestingKitAsync.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
F6B78911169B545C00034660 /* libSenTestingKitAsynciOS.a in Frameworks */ = {isa = PBXBuildFile; fileRef = F6B788F8169B545C00034660 /* libSenTestingKitAsynciOS.a */; };
F6B78917169B545C00034660 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = F6B78915169B545C00034660 /* InfoPlist.strings */; };
F6B7891A169B545C00034660 /* SenTestingKitAsyncTests.m in Sources */ = {isa = PBXBuildFile; fileRef = F6B78919169B545C00034660 /* SenTestingKitAsyncTests.m */; };
F6B78927169B608400034660 /* SenTestingKitAsync.m in Sources */ = {isa = PBXBuildFile; fileRef = F6B78902169B545C00034660 /* SenTestingKitAsync.m */; };
F6F77D4F1712EAA9008727C6 /* SenTestingKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F6B7890A169B545C00034660 /* SenTestingKit.framework */; };
F6F77D7D1712F334008727C6 /* SenTestingKitAsyncTests.m in Sources */ = {isa = PBXBuildFile; fileRef = F6B78919169B545C00034660 /* SenTestingKitAsyncTests.m */; };
F6F77D7F1712F655008727C6 /* SenTestingKitAsync.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = F6B78900169B545C00034660 /* SenTestingKitAsync.h */; };
Expand Down Expand Up @@ -363,7 +362,6 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
F6B78927169B608400034660 /* SenTestingKitAsync.m in Sources */,
F6B7891A169B545C00034660 /* SenTestingKitAsyncTests.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
52 changes: 26 additions & 26 deletions SenTestingKitAsync/SenTestingKitAsync.m
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ + (void)load;
method_getImplementation(oldMethod),
method_getTypeEncoding(oldMethod));
}

Method newMethod = class_getInstanceMethod([self class], @selector(asyncFailWithException:));
if (newMethod) {
class_replaceMethod(objc_getClass(class_getName(self)),
Expand All @@ -92,27 +92,27 @@ + (void)load;
- (void)performTest:(SenTestRun *)aRun withCompletionHandler:(SenTestCompletionHandler)aCompletionHandler;
{
__unsafe_unretained SenTestCase *weak = self;

__block NSException *exception = nil;

[weak setValue:aRun forKey:@"run"];
[weak setUp];

[self setUpWithCompletionHandler:^{

[aRun start];

if ([NSStringFromSelector([[weak invocation] selector]) hasSuffix:@"Async"]) {
weak.testRun = aRun;
weak.completionHandler = aCompletionHandler;

@try {
[[weak invocation] invoke];
}
@catch (NSException *anException) {
exception = anException;
}

if (exception != nil) {
[aRun stop];
[weak tearDownWithCompletionHandler:^{
Expand All @@ -124,27 +124,27 @@ - (void)performTest:(SenTestRun *)aRun withCompletionHandler:(SenTestCompletionH
weak.completionHandler = nil;
}];
}

} else {
@try {
[[weak invocation] invoke];
}
@catch (NSException *anException) {
exception = anException;
}

[aRun stop];



[weak tearDownWithCompletionHandler:^{
[weak tearDown];

if (exception != nil) {
[weak performSelector:@selector(logException:) withObject:exception];
}

[aRun stop]; // this has to be called *after* we call logException otherwise the exception won't be logged

[weak setValue:nil forKey:@"run"];
aCompletionHandler(aRun);

aCompletionHandler(aRun);
}];
}
}];
Expand All @@ -160,19 +160,19 @@ - (void)asyncFailWithException:(NSException *)anException;
SenTestCompletionHandler aCompletionHandler = self.completionHandler;
self.completionHandler = nil;
dispatch_async(dispatch_get_main_queue(), ^{

SenTestRun *testRun = self.testRun;
self.testRun = nil;

if (anException != nil) {
[self performSelector:@selector(logException:) withObject:anException];
}

[testRun stop];
[self tearDownWithCompletionHandler:^{
[self tearDown];
[self setValue:nil forKey:@"run"];

aCompletionHandler(testRun);
}];
});
Expand Down Expand Up @@ -207,9 +207,9 @@ - (void)performTest:(SenTestRun *)aTestRun withCompletionHandler:(SenTestComplet
{
[self setUp];
[aTestRun start];

NSEnumerator *testEnumerator = [[self valueForKey:@"tests"] objectEnumerator];

[self performTestRun:aTestRun
withTestEnumerator:testEnumerator
completionHandler:aCompletionHandler];
Expand All @@ -220,7 +220,7 @@ - (void)performTestRun:(SenTestRun *)aTestRun
completionHandler:(SenTestCompletionHandler)aCompletionHandler
{
SenTest *aTest = [aTestEnumerator nextObject];

if (aTest) {
[aTest runWithCompletionHandler:^(SenTestRun *run) {
[(SenTestSuiteRun *)aTestRun addTestRun:run];
Expand Down Expand Up @@ -258,16 +258,16 @@ + (void)runTestsAsync:(id)ignored;
@autoreleasepool {
[[NSBundle allFrameworks] makeObjectsPerformSelector:@selector(principalClass)];
[SenTestObserver class];

NSRunLoop *mainRunLoop = [NSRunLoop mainRunLoop];

dispatch_async(dispatch_get_main_queue(), ^{
[[self specifiedTestSuite] runWithCompletionHandler:^(SenTestRun *run) {
BOOL hasFailed = [run hasSucceeded];
exit((int)hasFailed);
}];
});

[mainRunLoop run];
}
}
Expand Down
17 changes: 17 additions & 0 deletions SenTestingKitAsyncTests/SenTestingKitAsyncTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,21 @@ - (void)testFailImmediatelyAsync
STFail(@"Fail immediately.");
}

- (void)testFailIfException
{
NSAssert(NO, @"");
STFail(@"this should fail");
}

- (void)testFailIfExceptionAsync
{
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
NSAssert(NO, @"");
STFail(@"this should fail");
});

STFailAfter(3, @"timed out");
}

@end