Skip to content

Instantly share code, notes, and snippets.

@landonf
Created February 19, 2015 18:42
Show Gist options
  • Save landonf/90bf6b9af3c9337a096a to your computer and use it in GitHub Desktop.
Save landonf/90bf6b9af3c9337a096a to your computer and use it in GitHub Desktop.
/*
* Minimal compatibility shims to support existing tests written against the SenTestCase (aka OCUnit) API. This
* allows us to support Apple's new XCTest framework without polluting existing test cases with spurious changes.
*
* The APIs are nearly identical, and can be aliased directly.
*/
#import <XCTest/XCTest.h>
@compatibility_alias SenTestCase XCTestCase;
@compatibility_alias SenTestSuite XCTestSuite;
#define STAssertNil(a1, description, ...) XCTAssertNil(a1, description, ##__VA_ARGS__)
#define STAssertNotNil(a1, description, ...) XCTAssertNotNil(a1, description, ##__VA_ARGS__)
#define STAssertTrue(expression, description, ...) XCTAssertTrue(expression, description, ##__VA_ARGS__)
#define STAssertFalse(expression, description, ...) XCTAssertFalse(expression, description, ##__VA_ARGS__)
#define STAssertEqualObjects(a1, a2, description, ...) XCTAssertEqualObjects(a1, a2, description, ##__VA_ARGS__)
#define STAssertEquals(a1, a2, description, ...) XCTAssertEqual(a1, a2, description, ##__VA_ARGS__)
#define STAssertEqualsWithAccuracy(left, right, accuracy, description, ...) XCTAssertEqualsWithAccuracy(left, right, accuracy, description, ##__VA_ARGS__)
#define STAssertThrows(expression, description, ...) XCTAssertThrows(expression, description, ##__VA_ARGS__)
#define STAssertThrowsSpecific(expression, specificException, description, ...) XCTAssertThrowsSpecific(expression, specificException, description, ##__VA_ARGS__)
#define STAssertThrowsSpecificNamed(expr, specificException, aName, description, ...) XCTAssertThrowsSpecificNamed(expr, specificException, aName, description, ##__VA_ARGS__)
#define STAssertNoThrow(expression, description, ...) XCTAssertNoThrow(expression, description, ##__VA_ARGS__)
#define STAssertNoThrowSpecific(expression, specificException, description, ...) XCTAssertNoThrowSpecific(expression, specificException, description, ##__VA_ARGS__)
#define STAssertNoThrowSpecificNamed(expr, specificException, aName, description, ...) XCTAssertNoThrowSpecificNamed(expr, specificException, aName, description, ##__VA_ARGS__)
#define STFail(description, ...) XCTFail(description, ##__VA_ARGS__)
#define STAssertTrueNoThrow(expression, description, ...) XCTAssertTrueNoThrow(expression, description, ##__VA_ARGS__)
#define STAssertFalseNoThrow(expression, description, ...) XCTAssertFalseNoThrow(expression, description, ##__VA_ARGS__)
/* The following assertions re-implement extensions that were provided by Google's GTM library, which were used throughout the PLCrashReporter tests */
#define STAssertNotEquals(a1, a2, description, ...) XCTAssertNotEqual(a1, a2, description, ##__VA_ARGS__)
#define STAssertEqualStrings(a1, a2, description, ...) XCTAssertEqualObjects(a1, a2, description, ##__VA_ARGS__)
#define STAssertLessThan(a1, a2, description, ...) XCTAssertLessThan(a1, a2, description, ##__VA_ARGS__)
#define STAssertGreaterThan(a1, a2, description, ...) XCTAssertGreaterThan(a1, a2, description, ##__VA_ARGS__)
#define STAssertEqualCStrings(a1, a2, description, ...) do { \
if (strcmp(a1, a2) != 0) { \
NSString *msg = [NSString stringWithFormat: description, ##__VA_ARGS__]; \
XCTFail(@"%s == %s: %@", "" #a1, "" #a2, msg); \
} \
} while(0)
#define STAssertNotEqualCStrings(a1, a2, description, ...) do { \
if (strcmp(a1, a2) == 0) { \
NSString *msg = [NSString stringWithFormat: description, ##__VA_ARGS__]; \
XCTFail(@"%s != %s: %@", "" #a1, "" #a2, msg); \
} \
} while(0)
#define STAssertNotNULL(a1, description, ...) do { \
const void *expressionValue = a1; \
if (expressionValue == NULL) { \
NSString *msg = [NSString stringWithFormat: description, ##__VA_ARGS__]; \
XCTFail(@"%s != NULL: %@", "" #a1, msg); \
} \
} while(0)
#define STAssertNULL(a1, description, ...) do { \
const void *expressionValue = a1; \
if (expressionValue != NULL) { \
NSString *msg = [NSString stringWithFormat: description, ##__VA_ARGS__]; \
XCTFail(@"%s == NULL: %@", "" #a1, msg); \
} \
} while(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment