-
-
Notifications
You must be signed in to change notification settings - Fork 603
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
36 changed files
with
634 additions
and
294 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
system |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# A sample Gemfile | ||
source "https://rubygems.org" | ||
|
||
gem 'cocoapods' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
GEM | ||
remote: https://rubygems.org/ | ||
specs: | ||
activesupport (4.2.6) | ||
i18n (~> 0.7) | ||
json (~> 1.7, >= 1.7.7) | ||
minitest (~> 5.1) | ||
thread_safe (~> 0.3, >= 0.3.4) | ||
tzinfo (~> 1.1) | ||
claide (0.9.1) | ||
cocoapods (0.39.0) | ||
activesupport (>= 4.0.2) | ||
claide (~> 0.9.1) | ||
cocoapods-core (= 0.39.0) | ||
cocoapods-downloader (~> 0.9.3) | ||
cocoapods-plugins (~> 0.4.2) | ||
cocoapods-search (~> 0.1.0) | ||
cocoapods-stats (~> 0.6.2) | ||
cocoapods-trunk (~> 0.6.4) | ||
cocoapods-try (~> 0.5.1) | ||
colored (~> 1.2) | ||
escape (~> 0.0.4) | ||
molinillo (~> 0.4.0) | ||
nap (~> 1.0) | ||
xcodeproj (~> 0.28.2) | ||
cocoapods-core (0.39.0) | ||
activesupport (>= 4.0.2) | ||
fuzzy_match (~> 2.0.4) | ||
nap (~> 1.0) | ||
cocoapods-downloader (0.9.3) | ||
cocoapods-plugins (0.4.2) | ||
nap | ||
cocoapods-search (0.1.0) | ||
cocoapods-stats (0.6.2) | ||
cocoapods-trunk (0.6.4) | ||
nap (>= 0.8, < 2.0) | ||
netrc (= 0.7.8) | ||
cocoapods-try (0.5.1) | ||
colored (1.2) | ||
escape (0.0.4) | ||
fuzzy_match (2.0.4) | ||
i18n (0.7.0) | ||
json (1.8.3) | ||
minitest (5.8.4) | ||
molinillo (0.4.4) | ||
nap (1.1.0) | ||
netrc (0.7.8) | ||
thread_safe (0.3.5) | ||
tzinfo (1.2.2) | ||
thread_safe (~> 0.1) | ||
xcodeproj (0.28.2) | ||
activesupport (>= 3) | ||
claide (~> 0.9.1) | ||
colored (~> 1.2) | ||
|
||
PLATFORMS | ||
ruby | ||
|
||
DEPENDENCIES | ||
cocoapods | ||
|
||
BUNDLED WITH | ||
1.11.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
78 changes: 78 additions & 0 deletions
78
Sources/Nimble/Adapters/ObjectiveC/XCTestObservationCenter+Register.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
#import "CurrentTestCaseTracker.h" | ||
#import <XCTest/XCTest.h> | ||
#import <objc/runtime.h> | ||
|
||
#pragma mark - Method Swizzling | ||
|
||
/// Swaps the implementations between two instance methods. | ||
/// | ||
/// @param class The class containing `originalSelector`. | ||
/// @param originalSelector Original method to replace. | ||
/// @param replacementSelector Replacement method. | ||
void swizzleSelectors(Class class, SEL originalSelector, SEL replacementSelector) { | ||
Method originalMethod = class_getInstanceMethod(class, originalSelector); | ||
Method replacementMethod = class_getInstanceMethod(class, replacementSelector); | ||
|
||
BOOL didAddMethod = | ||
class_addMethod(class, | ||
originalSelector, | ||
method_getImplementation(replacementMethod), | ||
method_getTypeEncoding(replacementMethod)); | ||
|
||
if (didAddMethod) { | ||
class_replaceMethod(class, | ||
replacementSelector, | ||
method_getImplementation(originalMethod), | ||
method_getTypeEncoding(originalMethod)); | ||
} else { | ||
method_exchangeImplementations(originalMethod, replacementMethod); | ||
} | ||
} | ||
|
||
#pragma mark - Private | ||
|
||
@interface XCTestObservationCenter (Private) | ||
- (void)_addLegacyTestObserver:(id)observer; | ||
@end | ||
|
||
@implementation XCTestObservationCenter (Register) | ||
|
||
/// Uses objc method swizzling to register `CurrentTestCaseTracker` as a test observer. This is necessary | ||
/// because Xcode 7.3 introduced timing issues where if a custom `XCTestObservation` is registered too early | ||
/// it suppresses all console output (generated by `XCTestLog`), breaking any tools that depend on this output. | ||
/// This approach waits to register our custom test observer until XCTest adds its first "legacy" observer, | ||
/// falling back to registering after the first normal observer if this private method ever changes. | ||
+ (void)load { | ||
if (class_getInstanceMethod([self class], @selector(_addLegacyTestObserver:))) { | ||
// Swizzle -_addLegacyTestObserver: | ||
swizzleSelectors([self class], @selector(_addLegacyTestObserver:), @selector(NMB_original__addLegacyTestObserver:)); | ||
} else { | ||
// Swizzle -addTestObserver:, only if -_addLegacyTestObserver: is not implemented | ||
swizzleSelectors([self class], @selector(addTestObserver:), @selector(NMB_original_addTestObserver:)); | ||
} | ||
} | ||
|
||
#pragma mark - Replacement Methods | ||
|
||
/// Registers `CurrentTestCaseTracker` as a test observer after `XCTestLog` has been added. | ||
- (void)NMB_original__addLegacyTestObserver:(id)observer { | ||
[self NMB_original__addLegacyTestObserver:observer]; | ||
|
||
static dispatch_once_t onceToken; | ||
dispatch_once(&onceToken, ^{ | ||
[self addTestObserver:[CurrentTestCaseTracker sharedInstance]]; | ||
}); | ||
} | ||
|
||
/// Registers `CurrentTestCaseTracker` as a test observer after `XCTestLog` has been added. | ||
/// This method is only used if `-_addLegacyTestObserver:` is not impelemented. (added in Xcode 7.3) | ||
- (void)NMB_original_addTestObserver:(id<XCTestObservation>)observer { | ||
[self NMB_original_addTestObserver:observer]; | ||
|
||
static dispatch_once_t onceToken; | ||
dispatch_once(&onceToken, ^{ | ||
[self NMB_original_addTestObserver:[CurrentTestCaseTracker sharedInstance]]; | ||
}); | ||
} | ||
|
||
@end |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import Foundation | ||
|
||
/// A Nimble matcher that succeeds when the actual expression evaluates to an | ||
/// error from the specified case. | ||
/// | ||
/// Errors are tried to be compared by their implementation of Equatable, | ||
/// otherwise they fallback to comparision by _domain and _code. | ||
public func matchError<T: ErrorType>(error: T) -> NonNilMatcherFunc<ErrorType> { | ||
return NonNilMatcherFunc { actualExpression, failureMessage in | ||
let actualError: ErrorType? = try actualExpression.evaluate() | ||
|
||
setFailureMessageForError(failureMessage, postfixMessageVerb: "match", actualError: actualError, error: error) | ||
return errorMatchesNonNilFieldsOrClosure(actualError, error: error) | ||
} | ||
} | ||
|
||
/// A Nimble matcher that succeeds when the actual expression evaluates to an | ||
/// error of the specified type | ||
public func matchError<T: ErrorType>(errorType: T.Type) -> NonNilMatcherFunc<ErrorType> { | ||
return NonNilMatcherFunc { actualExpression, failureMessage in | ||
let actualError: ErrorType? = try actualExpression.evaluate() | ||
|
||
setFailureMessageForError(failureMessage, postfixMessageVerb: "match", actualError: actualError, errorType: errorType) | ||
return errorMatchesNonNilFieldsOrClosure(actualError, errorType: errorType) | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.