From 784f85ae9a475667b7afb726d0653701c196ed48 Mon Sep 17 00:00:00 2001 From: "gtm.daemon" Date: Thu, 28 Apr 2011 20:30:21 +0000 Subject: [Author: aharper] - Fix ASL logging to reference the correct formatter (and then replace with a new formatter). - Format ASL messages to include information that would normally be present in the standard formatter. - Allow ASL writers to pass a facility string. - Pretty up the function names in all logging, better matching NSAssert() names (as one example). - Don't throw if a logging filehandle is closed (SIGPIPE). Random exceptions from logging is bad, m'kay? R=thomasvl,dmaclach APPROVED=thomasvl --- Foundation/GTMLoggerTest.m | 46 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 39 insertions(+), 7 deletions(-) (limited to 'Foundation/GTMLoggerTest.m') diff --git a/Foundation/GTMLoggerTest.m b/Foundation/GTMLoggerTest.m index 940014f..0dc7689 100644 --- a/Foundation/GTMLoggerTest.m +++ b/Foundation/GTMLoggerTest.m @@ -348,6 +348,38 @@ return msg; } +- (void)testFunctionPrettifier { + GTMLogBasicFormatter *fmtr = [[[GTMLogBasicFormatter alloc] init] + autorelease]; + STAssertNotNil(fmtr, nil); + + // Nil, empty and whitespace + STAssertEqualObjects([fmtr prettyNameForFunc:nil], @"(unknown)", nil); + STAssertEqualObjects([fmtr prettyNameForFunc:@""], @"(unknown)", nil); + STAssertEqualObjects([fmtr prettyNameForFunc:@" \n\t"], @"(unknown)", nil); + + // C99 __func__ + STAssertEqualObjects([fmtr prettyNameForFunc:@"main"], @"main()", nil); + STAssertEqualObjects([fmtr prettyNameForFunc:@"main"], @"main()", nil); + STAssertEqualObjects([fmtr prettyNameForFunc:@" main "], @"main()", nil); + + // GCC Obj-C __func__ and __PRETTY_FUNCTION__ + STAssertEqualObjects([fmtr prettyNameForFunc:@"+[Foo bar]"], @"+[Foo bar]", + nil); + STAssertEqualObjects([fmtr prettyNameForFunc:@" +[Foo bar] "], @"+[Foo bar]", + nil); + STAssertEqualObjects([fmtr prettyNameForFunc:@"-[Foo baz]"], @"-[Foo baz]", + nil); + STAssertEqualObjects([fmtr prettyNameForFunc:@" -[Foo baz] "], @"-[Foo baz]", + nil); + + // GCC C++ __PRETTY_FUNCTION__ + STAssertEqualObjects([fmtr prettyNameForFunc:@"void a::sub(int)"], + @"void a::sub(int)", nil); + STAssertEqualObjects([fmtr prettyNameForFunc:@" void a::sub(int) "], + @"void a::sub(int)", nil); +} + - (void)testBasicFormatter { id fmtr = [[[GTMLogBasicFormatter alloc] init] autorelease]; STAssertNotNil(fmtr, nil); @@ -388,16 +420,16 @@ if ([GTMSystemVersion isSnowLeopardOrGreater]) { // E.g. 2009-10-26 22:26:25.086 otest-i386[53200/0xa0438500] [lvl=1] (no func) test kFormatBasePattern = - @"[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}\\.[0-9]{3} ((otest-i386)|(otest-x86_64)|(otest-ppc))\\[[0-9]+/0x[0-9a-f]+\\] \\[lvl=[0-3]\\] \\(no func\\) "; + @"[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}\\.[0-9]{3} ((otest-i386)|(otest-x86_64)|(otest-ppc))\\[[0-9]+/0x[0-9a-f]+\\] \\[lvl=[0-3]\\] \\(unknown\\) "; } else { // E.g. 2008-01-04 09:16:26.906 otest[5567/0xa07d0f60] [lvl=1] (no func) test kFormatBasePattern = - @"[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}\\.[0-9]{3} (otest)\\[[0-9]+/0x[0-9a-f]+\\] \\[lvl=[0-3]\\] \\(no func\\) "; + @"[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}\\.[0-9]{3} (otest)\\[[0-9]+/0x[0-9a-f]+\\] \\[lvl=[0-3]\\] \\(unknown\\) "; } #else // GTM_MACOS_SDK // E.g. 2008-01-04 09:16:26.906 otest[5567/0xa07d0f60] [lvl=1] (no func) test kFormatBasePattern = - @"[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}\\.[0-9]{3} (GTMiPhoneTest)\\[[0-9]+/0x[0-9a-f]+\\] \\[lvl=[0-3]\\] \\(no func\\) "; + @"[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}\\.[0-9]{3} (GTMiPhoneTest)\\[[0-9]+/0x[0-9a-f]+\\] \\[lvl=[0-3]\\] \\(unknown\\) "; #endif // GTM_MACOS_SDK NSString *msg = nil; @@ -405,27 +437,27 @@ msg = [self stringFromFormatter:fmtr level:kGTMLoggerLevelDebug format:@"test"]; - STAssertTrue([msg gtm_matchesPattern:[kFormatBasePattern stringByAppendingString:@"test"]], + STAssertTrue([msg gtm_matchesPattern:[kFormatBasePattern stringByAppendingString:@"test"]], @"msg: %@", msg); msg = [self stringFromFormatter:fmtr level:kGTMLoggerLevelError format:@"test %d", 1]; - STAssertTrue([msg gtm_matchesPattern:[kFormatBasePattern stringByAppendingString:@"test 1"]], + STAssertTrue([msg gtm_matchesPattern:[kFormatBasePattern stringByAppendingString:@"test 1"]], @"msg: %@", msg); msg = [self stringFromFormatter:fmtr level:kGTMLoggerLevelInfo format:@"test %@", @"hi"]; - STAssertTrue([msg gtm_matchesPattern:[kFormatBasePattern stringByAppendingString:@"test hi"]], + STAssertTrue([msg gtm_matchesPattern:[kFormatBasePattern stringByAppendingString:@"test hi"]], @"msg: %@", msg); msg = [self stringFromFormatter:fmtr level:kGTMLoggerLevelUnknown format:@"test"]; - STAssertTrue([msg gtm_matchesPattern:[kFormatBasePattern stringByAppendingString:@"test"]], + STAssertTrue([msg gtm_matchesPattern:[kFormatBasePattern stringByAppendingString:@"test"]], @"msg: %@", msg); } -- cgit v1.2.3