Skip to content

Commit

Permalink
Annotate nullability
Browse files Browse the repository at this point in the history
  • Loading branch information
jonreid committed Nov 24, 2016
1 parent 69b1c1c commit 2865f4b
Show file tree
Hide file tree
Showing 154 changed files with 517 additions and 142 deletions.
6 changes: 5 additions & 1 deletion Source/Core/HCAssertThat.h
Expand Up @@ -5,6 +5,8 @@

@protocol HCMatcher;

NS_ASSUME_NONNULL_BEGIN

/*!
* @header
* Assertion macros for using matchers in testing frameworks.
Expand Down Expand Up @@ -38,7 +40,7 @@ FOUNDATION_EXPORT void HC_assertThatWithLocation(id testCase, id actual, id <HCM
#endif


typedef id (^HCFutureValue)();
typedef _Nonnull id (^HCFutureValue)();

FOUNDATION_EXPORT void HC_assertWithTimeoutAndLocation(id testCase, NSTimeInterval timeout,
HCFutureValue actualBlock, id <HCMatcher> matcher,
Expand Down Expand Up @@ -90,3 +92,5 @@ FOUNDATION_EXPORT void HC_assertWithTimeoutAndLocation(id testCase, NSTimeInterv
* @discussion Helper function to let you describe mismatches the way <tt>assertThat</tt> does.
*/
FOUNDATION_EXPORT NSString *HCDescribeMismatch(id <HCMatcher> matcher, id actual);

NS_ASSUME_NONNULL_END
4 changes: 4 additions & 0 deletions Source/Core/HCBaseDescription.h
Expand Up @@ -5,6 +5,8 @@
#import <OCHamcrest/HCDescription.h>


NS_ASSUME_NONNULL_BEGIN

/*!
* @abstract Base class for all HCDescription implementations.
*/
Expand All @@ -23,3 +25,5 @@
- (void)append:(NSString *)str;

@end

NS_ASSUME_NONNULL_END
2 changes: 1 addition & 1 deletion Source/Core/HCBaseDescription.m
Expand Up @@ -14,7 +14,7 @@ @implementation HCBaseDescription
return self;
}

- (id <HCDescription>)appendDescriptionOf:(id)value
- (id <HCDescription>)appendDescriptionOf:(nullable id)value
{
if (value == nil)
[self append:@"nil"];
Expand Down
4 changes: 4 additions & 0 deletions Source/Core/HCBaseMatcher.h
Expand Up @@ -7,6 +7,8 @@
#define HC_ABSTRACT_METHOD [self subclassResponsibility:_cmd]


NS_ASSUME_NONNULL_BEGIN

/*!
* @abstract Base class for all HCMatcher implementations.
* @discussion Simple matchers can just subclass HCBaseMatcher and implement <code>-matches:</code>
Expand All @@ -19,3 +21,5 @@
- (void)subclassResponsibility:(SEL)command;

@end

NS_ASSUME_NONNULL_END
6 changes: 3 additions & 3 deletions Source/Core/HCBaseMatcher.m
Expand Up @@ -13,21 +13,21 @@ - (NSString *)description
return [HCStringDescription stringFrom:self];
}

- (BOOL)matches:(id)item
- (BOOL)matches:(nullable id)item
{
HC_ABSTRACT_METHOD;
return NO;
}

- (BOOL)matches:(id)item describingMismatchTo:(id <HCDescription>)mismatchDescription
- (BOOL)matches:(nullable id)item describingMismatchTo:(id <HCDescription>)mismatchDescription
{
BOOL matchResult = [self matches:item];
if (!matchResult)
[self describeMismatchOf:item to:mismatchDescription];
return matchResult;
}

- (void)describeMismatchOf:(id)item to:(id <HCDescription>)mismatchDescription
- (void)describeMismatchOf:(nullable id)item to:(nullable id <HCDescription>)mismatchDescription
{
[[mismatchDescription appendText:@"was "] appendDescriptionOf:item];
}
Expand Down
6 changes: 5 additions & 1 deletion Source/Core/HCDescription.h
Expand Up @@ -4,6 +4,8 @@
#import <Foundation/Foundation.h>


NS_ASSUME_NONNULL_BEGIN

/*!
* @abstract A description of an HCMatcher.
* @discussion An HCMatcher will describe itself to a description which can later be used for reporting.
Expand All @@ -21,7 +23,7 @@
* @discussion If the value implements the HCSelfDescribing protocol, then it will be used.
* @return <code>self</code>, for chaining.
*/
- (id <HCDescription>)appendDescriptionOf:(id)value;
- (id <HCDescription>)appendDescriptionOf:(nullable id)value;

/*!
* @abstract Appends a list of objects to the description.
Expand All @@ -33,3 +35,5 @@
end:(NSString *)end;

@end

NS_ASSUME_NONNULL_END
4 changes: 4 additions & 0 deletions Source/Core/HCDiagnosingMatcher.h
Expand Up @@ -4,6 +4,8 @@
#import <OCHamcrest/HCBaseMatcher.h>


NS_ASSUME_NONNULL_BEGIN

/*!
* @abstract Base class for matchers that generate mismatch descriptions during the matching.
* @discussion Some matching algorithms have several "no match" paths. It helps to make the mismatch
Expand All @@ -13,3 +15,5 @@
*/
@interface HCDiagnosingMatcher : HCBaseMatcher
@end

NS_ASSUME_NONNULL_END
6 changes: 3 additions & 3 deletions Source/Core/HCDiagnosingMatcher.m
Expand Up @@ -6,18 +6,18 @@

@implementation HCDiagnosingMatcher

- (BOOL)matches:(id)item
- (BOOL)matches:(nullable id)item
{
return [self matches:item describingMismatchTo:nil];
}

- (BOOL)matches:(id)item describingMismatchTo:(id <HCDescription>)mismatchDescription
- (BOOL)matches:(nullable id)item describingMismatchTo:(id <HCDescription>)mismatchDescription
{
HC_ABSTRACT_METHOD;
return NO;
}

- (void)describeMismatchOf:(id)item to:(id <HCDescription>)mismatchDescription
- (void)describeMismatchOf:(nullable id)item to:(nullable id <HCDescription>)mismatchDescription
{
[self matches:item describingMismatchTo:mismatchDescription];
}
Expand Down
10 changes: 7 additions & 3 deletions Source/Core/HCMatcher.h
Expand Up @@ -4,6 +4,8 @@
#import "HCSelfDescribing.h"


NS_ASSUME_NONNULL_BEGIN

/*!
* @abstract A matcher over acceptable values.
* @discussion A matcher is able to describe itself to give feedback when it fails.
Expand All @@ -19,15 +21,15 @@
* @param item The object against which the matcher is evaluated.
* @return <code>YES</code> if item matches, otherwise <code>NO</code>.
*/
- (BOOL)matches:(id)item;
- (BOOL)matches:(nullable id)item;

/*!
* @abstract Evaluates the matcher for argument item.
* @param item The object against which the matcher is evaluated.
* @param mismatchDescription The description to be built or appended to if item does not match.
* @return <code>YES</code> if item matches, otherwise <code>NO</code>.
*/
- (BOOL)matches:(id)item describingMismatchTo:(id <HCDescription>)mismatchDescription;
- (BOOL)matches:(nullable id)item describingMismatchTo:(nullable id <HCDescription>)mismatchDescription;

/*!
* @abstract Generates a description of why the matcher has not accepted the item.
Expand All @@ -38,6 +40,8 @@
*
* This method assumes that <code>matches:item</code> is false, but will not check this.
*/
- (void)describeMismatchOf:(id)item to:(id <HCDescription>)mismatchDescription;
- (void)describeMismatchOf:(nullable id)item to:(nullable id <HCDescription>)mismatchDescription;

@end

NS_ASSUME_NONNULL_END
4 changes: 4 additions & 0 deletions Source/Core/HCSelfDescribing.h
Expand Up @@ -6,6 +6,8 @@
#import "HCDescription.h" // Convenience header


NS_ASSUME_NONNULL_BEGIN

/*!
* @abstract The ability of an object to describe itself.
*/
Expand All @@ -20,3 +22,5 @@
- (void)describeTo:(id <HCDescription>)description;

@end

NS_ASSUME_NONNULL_END
4 changes: 4 additions & 0 deletions Source/Core/HCStringDescription.h
Expand Up @@ -6,6 +6,8 @@
@protocol HCSelfDescribing;


NS_ASSUME_NONNULL_BEGIN

/*!
* @abstract An HCDescription that is stored as a string.
*/
Expand All @@ -32,3 +34,5 @@
- (instancetype)init NS_DESIGNATED_INITIALIZER;

@end

NS_ASSUME_NONNULL_END
4 changes: 4 additions & 0 deletions Source/Core/Helpers/HCCollect.h
Expand Up @@ -8,6 +8,8 @@
@protocol HCMatcher;


NS_ASSUME_NONNULL_BEGIN

/*!
* @abstract Returns an array of values from a variable-length comma-separated list terminated
* by <code>nil</code>.
Expand All @@ -20,3 +22,5 @@ FOUNDATION_EXPORT NSArray * HCCollectItems(id item, va_list args);
* matchers.
*/
FOUNDATION_EXPORT NSArray<id <HCMatcher>> * HCWrapIntoMatchers(NSArray *items);

NS_ASSUME_NONNULL_END
4 changes: 4 additions & 0 deletions Source/Core/Helpers/HCInvocationMatcher.h
Expand Up @@ -4,6 +4,8 @@
#import <OCHamcrest/HCBaseMatcher.h>


NS_ASSUME_NONNULL_BEGIN

/*!
* @abstract Supporting class for matching a feature of an object.
* @discussion Tests whether the result of passing the specified invocation to the value satisfies
Expand Down Expand Up @@ -39,3 +41,5 @@
- (NSString *)stringFromSelector;

@end

NS_ASSUME_NONNULL_END
4 changes: 2 additions & 2 deletions Source/Core/Helpers/HCInvocationMatcher.m
Expand Up @@ -17,7 +17,7 @@ - (instancetype)initWithInvocation:(NSInvocation *)anInvocation matching:(id <HC
return self;
}

- (BOOL)matches:(id)item
- (BOOL)matches:(nullable id)item
{
if ([self invocationNotSupportedForItem:item])
return NO;
Expand All @@ -38,7 +38,7 @@ - (id)invokeOn:(id)item
return result;
}

- (void)describeMismatchOf:(id)item to:(id <HCDescription>)mismatchDescription
- (void)describeMismatchOf:(nullable id)item to:(nullable id <HCDescription>)mismatchDescription
{
if ([self invocationNotSupportedForItem:item])
[super describeMismatchOf:item to:mismatchDescription];
Expand Down
4 changes: 4 additions & 0 deletions Source/Core/Helpers/HCRequireNonNilObject.h
Expand Up @@ -4,7 +4,11 @@
#import <Foundation/Foundation.h>


NS_ASSUME_NONNULL_BEGIN

/*!
* @abstract Throws an NSException if <em>obj</em> is <code>nil</code>.
*/
FOUNDATION_EXPORT void HCRequireNonNilObject(id obj);

NS_ASSUME_NONNULL_END
4 changes: 4 additions & 0 deletions Source/Core/Helpers/HCRunloopRunner.h
Expand Up @@ -4,6 +4,8 @@
#import <Foundation/Foundation.h>


NS_ASSUME_NONNULL_BEGIN

/*!
* @abstract Runs runloop until fulfilled, or timeout is reached.
* @discussion Based on http://bou.io/CTTRunLoopRunUntil.html
Expand All @@ -15,3 +17,5 @@
- (void)runUntilFulfilledOrTimeout:(CFTimeInterval)timeout;

@end

NS_ASSUME_NONNULL_END
6 changes: 5 additions & 1 deletion Source/Core/Helpers/HCWrapInMatcher.h
Expand Up @@ -6,8 +6,12 @@
@protocol HCMatcher;


NS_ASSUME_NONNULL_BEGIN

/*!
* @abstract Wraps argument in a matcher, if necessary.
* @return The argument as-is if it is already a matcher, otherwise wrapped in an <em>equalTo</em> matcher.
*/
FOUNDATION_EXPORT id <HCMatcher> HCWrapInMatcher(id matcherOrValue);
FOUNDATION_EXPORT id <HCMatcher> HCWrapInMatcher(_Nullable id matcherOrValue);

NS_ASSUME_NONNULL_END
5 changes: 1 addition & 4 deletions Source/Core/Helpers/HCWrapInMatcher.m
Expand Up @@ -6,11 +6,8 @@
#import "HCIsEqual.h"


id <HCMatcher> HCWrapInMatcher(id matcherOrValue)
id <HCMatcher> HCWrapInMatcher(_Nullable id matcherOrValue)
{
if (!matcherOrValue)
return nil;

if ([matcherOrValue conformsToProtocol:@protocol(HCMatcher)])
return matcherOrValue;
return HC_equalTo(matcherOrValue);
Expand Down
4 changes: 4 additions & 0 deletions Source/Core/Helpers/NSInvocation+OCHamcrest.h
Expand Up @@ -4,10 +4,14 @@
#import <Foundation/Foundation.h>


NS_ASSUME_NONNULL_BEGIN

@interface NSInvocation (OCHamcrest)

+ (NSInvocation *)och_invocationWithTarget:(id)target selector:(SEL)selector;
+ (NSInvocation *)och_invocationOnObjectOfType:(Class)aClass selector:(SEL)selector;
- (id)och_invoke;

@end

NS_ASSUME_NONNULL_END
8 changes: 6 additions & 2 deletions Source/Core/Helpers/ReturnValueGetters/HCBoolReturnGetter.h
Expand Up @@ -4,9 +4,13 @@
#import "HCReturnValueGetter.h"


NS_ASSUME_NONNULL_BEGIN

@interface HCBoolReturnGetter : HCReturnValueGetter

- (instancetype)initWithSuccessor:(HCReturnValueGetter *)successor NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithType:(char const *)handlerType successor:(HCReturnValueGetter *)successor NS_UNAVAILABLE;
- (instancetype)initWithSuccessor:(nullable HCReturnValueGetter *)successor NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithType:(char const *)handlerType successor:(nullable HCReturnValueGetter *)successor NS_UNAVAILABLE;

@end

NS_ASSUME_NONNULL_END
Expand Up @@ -6,7 +6,7 @@

@implementation HCBoolReturnGetter

- (instancetype)initWithSuccessor:(HCReturnValueGetter *)successor
- (instancetype)initWithSuccessor:(nullable HCReturnValueGetter *)successor
{
self = [super initWithType:@encode(BOOL) successor:successor];
return self;
Expand Down
8 changes: 6 additions & 2 deletions Source/Core/Helpers/ReturnValueGetters/HCCharReturnGetter.h
Expand Up @@ -4,9 +4,13 @@
#import "HCReturnValueGetter.h"


NS_ASSUME_NONNULL_BEGIN

@interface HCCharReturnGetter : HCReturnValueGetter

- (instancetype)initWithSuccessor:(HCReturnValueGetter *)successor NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithType:(char const *)handlerType successor:(HCReturnValueGetter *)successor NS_UNAVAILABLE;
- (instancetype)initWithSuccessor:(nullable HCReturnValueGetter *)successor NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithType:(char const *)handlerType successor:(nullable HCReturnValueGetter *)successor NS_UNAVAILABLE;

@end

NS_ASSUME_NONNULL_END
Expand Up @@ -6,7 +6,7 @@

@implementation HCCharReturnGetter

- (instancetype)initWithSuccessor:(HCReturnValueGetter *)successor
- (instancetype)initWithSuccessor:(nullable HCReturnValueGetter *)successor
{
self = [super initWithType:@encode(char) successor:successor];
return self;
Expand Down
8 changes: 6 additions & 2 deletions Source/Core/Helpers/ReturnValueGetters/HCDoubleReturnGetter.h
Expand Up @@ -4,9 +4,13 @@
#import "HCReturnValueGetter.h"


NS_ASSUME_NONNULL_BEGIN

@interface HCDoubleReturnGetter : HCReturnValueGetter

- (instancetype)initWithSuccessor:(HCReturnValueGetter *)successor NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithType:(char const *)handlerType successor:(HCReturnValueGetter *)successor NS_UNAVAILABLE;
- (instancetype)initWithSuccessor:(nullable HCReturnValueGetter *)successor NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithType:(char const *)handlerType successor:(nullable HCReturnValueGetter *)successor NS_UNAVAILABLE;

@end

NS_ASSUME_NONNULL_END

0 comments on commit 2865f4b

Please sign in to comment.