diff options
Diffstat (limited to 'platform/darwin/test/MGLTestAssertionHandler.m')
-rw-r--r-- | platform/darwin/test/MGLTestAssertionHandler.m | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/platform/darwin/test/MGLTestAssertionHandler.m b/platform/darwin/test/MGLTestAssertionHandler.m new file mode 100644 index 0000000000..4b504427b5 --- /dev/null +++ b/platform/darwin/test/MGLTestAssertionHandler.m @@ -0,0 +1,77 @@ +#import "MGLTestAssertionHandler.h" + +@implementation MGLTestAssertionHandler + +- (instancetype)initWithTestCase:(XCTestCase *)testCase { + if ((self = [super init])) { + _testCase = testCase; + } + return self; +} + +- (void)handleFailureInMethod:(SEL)selector + object:(id)object + file:(NSString *)fileName + lineNumber:(NSInteger)line + description:(NSString *)format, ... +{ + va_list args; + va_start(args, format); + NSString *description = [[NSString alloc] initWithFormat:format arguments:args]; + va_end(args); + + NSString *condition = [NSString stringWithFormat: + @"`[%@ %@]`", + object, NSStringFromSelector(selector) + ]; + + if (self.testCase && self.shouldFail) { + _XCTPreformattedFailureHandler(self.testCase, + YES, + fileName, + line, + condition, + description + ); + } + else { + NSLog(@"Assertion Failure: %@:%lu: %@ - %@", + fileName, + line, + condition, + description); + } +} + +- (void)handleFailureInFunction:(NSString *)functionName + file:(NSString *)fileName + lineNumber:(NSInteger)line + description:(NSString *)format, ... +{ + va_list args; + va_start(args, format); + NSString *description = [[NSString alloc] initWithFormat:format arguments:args]; + va_end(args); + + NSString *condition = [NSString stringWithFormat: + @"`%@`", + functionName]; + + if (self.testCase && self.shouldFail) { + _XCTPreformattedFailureHandler(self.testCase, + YES, + fileName, + line, + condition, + description); + } + else { + NSLog(@"Assertion Failure: %@:%lu: %@ - %@", + fileName, + line, + condition, + description); + } +} +@end + |