Skip to content

Instantly share code, notes, and snippets.

@ScottPetit
Created March 4, 2014 19:20
Show Gist options
  • Save ScottPetit/9353635 to your computer and use it in GitHub Desktop.
Save ScottPetit/9353635 to your computer and use it in GitHub Desktop.
#define SPY_XCODE_COLORS "XcodeColors"
#define SPY_XCODE_COLORS_ESCAPE @"\033["
#define SPY_XCODE_COLORS_RESET SPY_XCODE_COLORS_ESCAPE @";" // Clear any foreground or background color
@interface SPYTestLog ()
{
BOOL _testCaseDidStop;
BOOL _testCaseDidSucceed;
}
- (BOOL)hasXcodeColors;
@end
@implementation SPYTestLog
- (void)testCaseDidStop:(XCTestRun *)testRun
{
_testCaseDidStop = YES;
_testCaseDidSucceed = [testRun hasSucceeded];
[super testCaseDidStop:testRun];
_testCaseDidStop = NO;
}
- (void)testLogWithFormat:(NSString *)format arguments:(va_list)arguments
{
if (_testCaseDidStop && _testCaseDidSucceed && [self hasXcodeColors])
{
format = [[SPY_XCODE_COLORS_ESCAPE @"fg127,175,27;" stringByAppendingString:format] stringByAppendingString:SPY_XCODE_COLORS_RESET];
}
else if (_testCaseDidStop && !_testCaseDidSucceed && [self hasXcodeColors])
{
format = [[SPY_XCODE_COLORS_ESCAPE @"fg240,35,17;" stringByAppendingString:format] stringByAppendingString:SPY_XCODE_COLORS_RESET];
}
[super testLogWithFormat:format arguments:arguments];
}
#pragma mark - Private
- (BOOL)hasXcodeColors
{
char *xcode_colors = getenv(SPY_XCODE_COLORS);
return (xcode_colors && (strcmp(xcode_colors, "YES") == 0));
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment