Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate tests from OCUnit to XCTest #11

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>ru.rabovik.${PRODUCT_NAME:rfc1034identifier}</string>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
Expand Down

This file was deleted.

2 changes: 0 additions & 2 deletions RSSwizzleTests/RSSwizzleTests-OSX/en.lproj/InfoPlist.strings

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>ru.rabovik.${PRODUCT_NAME:rfc1034identifier}</string>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
Expand Down
10 changes: 0 additions & 10 deletions RSSwizzleTests/RSSwizzleTests-iOS/RSSwizzleTests-iOS-Prefix.pch

This file was deleted.

2 changes: 0 additions & 2 deletions RSSwizzleTests/RSSwizzleTests-iOS/en.lproj/InfoPlist.strings

This file was deleted.

471 changes: 245 additions & 226 deletions RSSwizzleTests/RSSwizzleTests.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
34 changes: 17 additions & 17 deletions RSSwizzleTests/RSSwizzleTests/RSSwizzleTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//
//

#import <SenTestingKit/SenTestingKit.h>
#import <XCTest/XCTest.h>
#import "RSTestsLog.h"
#import "RSSwizzle.h"
#import <objc/runtime.h>
Expand Down Expand Up @@ -80,7 +80,7 @@ static void swizzleNumber(Class classToSwizzle, int(^transformationBlock)(int)){

#pragma mark - TESTS -

@interface RSSwizzleTests : SenTestCase @end
@interface RSSwizzleTests : XCTestCase @end

@implementation RSSwizzleTests

Expand Down Expand Up @@ -165,7 +165,7 @@ -(void)testCalcSwizzling
{
RSSwizzleTestClass_D *object = [RSSwizzleTestClass_D new];
int res = [object calc:2];
STAssertTrue(res == ((2 * (-1) * 3) + 17) * 5 * 11 - 20, @"%d",res);
XCTAssertTrue(res == ((2 * (-1) * 3) + 17) * 5 * 11 - 20, @"%d",res);
}

#pragma mark - String Swizzling
Expand All @@ -183,7 +183,7 @@ -(void)testStringSwizzling{
return [res stringByAppendingString:@"DEF"];
}), RSSwizzleModeAlways, NULL);

STAssertTrue([[a string] isEqualToString:@"ABCDEF"], nil);
XCTAssertTrue([[a string] isEqualToString:@"ABCDEF"]);
}

#pragma mark - Class Swizzling
Expand All @@ -198,9 +198,9 @@ -(void)testClassSwizzling{
return @([result doubleValue]* 2.);
}));

STAssertEqualObjects(@(2.), [RSSwizzleTestClass_A sumFloat:0.5 withDouble:1.5 ], nil);
STAssertEqualObjects(@(4.), [RSSwizzleTestClass_B sumFloat:0.5 withDouble:1.5 ], nil);
STAssertEqualObjects(@(4.), [RSSwizzleTestClass_C sumFloat:0.5 withDouble:1.5 ], nil);
XCTAssertEqualObjects(@(2.), [RSSwizzleTestClass_A sumFloat:0.5 withDouble:1.5 ]);
XCTAssertEqualObjects(@(4.), [RSSwizzleTestClass_B sumFloat:0.5 withDouble:1.5 ]);
XCTAssertEqualObjects(@(4.), [RSSwizzleTestClass_C sumFloat:0.5 withDouble:1.5 ]);
}

#pragma mark - Test Assertions
Expand All @@ -214,12 +214,12 @@ -(void)testThrowsOnSwizzlingNonexistentMethod{
originalIMP(self,selector);
};
};
STAssertThrows([RSSwizzle
XCTAssertThrows([RSSwizzle
swizzleInstanceMethod:selector
inClass:[RSSwizzleTestClass_A class]
newImpFactory:factoryBlock
mode:RSSwizzleModeAlways
key:NULL], nil);
key:NULL]);
}

-(void)testThrowsOnSwizzlingWithIncorrectImpType{
Expand All @@ -229,40 +229,40 @@ -(void)testThrowsOnSwizzlingWithIncorrectImpType{
{
return ^(__unsafe_unretained id self){};
};
STAssertThrows([RSSwizzle
XCTAssertThrows([RSSwizzle
swizzleInstanceMethod:@selector(methodReturningBOOL)
inClass:[RSSwizzleTestClass_A class]
newImpFactory:voidNoArgFactory
mode:RSSwizzleModeAlways
key:NULL], nil);
key:NULL]);
// Different arguments count
STAssertThrows([RSSwizzle
XCTAssertThrows([RSSwizzle
swizzleInstanceMethod:@selector(methodWithArgument:)
inClass:[RSSwizzleTestClass_A class]
newImpFactory:voidNoArgFactory
mode:RSSwizzleModeAlways
key:NULL], nil);
key:NULL]);
// Different arguments type
RSSwizzleImpFactoryBlock voidIntArgFactory =
^id(RSSwizzleInfo *swizzleInfo)
{
return ^int(__unsafe_unretained id self){ return 0; };
};
STAssertThrows([RSSwizzle
XCTAssertThrows([RSSwizzle
swizzleInstanceMethod:@selector(methodWithArgument:)
inClass:[RSSwizzleTestClass_A class]
newImpFactory:voidIntArgFactory
mode:RSSwizzleModeAlways
key:NULL], nil);
key:NULL]);
}

-(void)testThrowsOnPassingIncorrectImpFactory{
STAssertThrows([RSSwizzle
XCTAssertThrows([RSSwizzle
swizzleInstanceMethod:@selector(methodWithArgument:)
inClass:[RSSwizzleTestClass_A class]
newImpFactory:^id(id x){ return nil; }
mode:RSSwizzleModeAlways
key:NULL], nil);
key:NULL]);
}
#endif

Expand Down
6 changes: 4 additions & 2 deletions RSSwizzleTests/RSSwizzleTests/RSTestsLog.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#import <Foundation/Foundation.h>

@interface RSTestsLog : NSObject
+(void)log:(NSString *)string;
+(void)clear;
+(BOOL)is:(NSString *)compareString;
+(NSString *)logString;
@end

#define ASSERT_LOG_IS(STRING) STAssertTrue([RSTestsLog is:STRING], @"LOG IS @\"%@\" INSTEAD",[RSTestsLog logString])
#define ASSERT_LOG_IS(STRING) XCTAssertTrue([RSTestsLog is:STRING], @"LOG IS @\"%@\" INSTEAD",[RSTestsLog logString])
#define CLEAR_LOG() ([RSTestsLog clear])
#define RSTestsLog(STRING) [RSTestsLog log:STRING]
#define RSTestsLog(STRING) [RSTestsLog log:STRING]
6 changes: 3 additions & 3 deletions RSSwizzleTests/RSSwizzleTests/RSTestsLog.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#import "RSTestsLog.h"
#import <SenTestingKit/SenTestingKit.h>
#import <XCTest/XCTest.h>

@implementation RSTestsLog

Expand All @@ -24,7 +24,7 @@ +(NSString *)logString{
@end


@interface RSTestsLogTests : SenTestCase @end
@interface RSTestsLogTests : XCTestCase @end

@implementation RSTestsLogTests

Expand All @@ -33,7 +33,7 @@ - (void)testLog{
RSTestsLog(@"A");
RSTestsLog(@"B");
RSTestsLog(@"C");
STAssertTrue([[RSTestsLog logString] isEqualToString:@"ABC"], @"%@",[RSTestsLog logString]);
XCTAssertTrue([[RSTestsLog logString] isEqualToString:@"ABC"], @"%@",[RSTestsLog logString]);
}

-(void)testAssertLogIs{
Expand Down