aboutsummaryrefslogtreecommitdiff
path: root/Foundation/GTMLoggerTest.m
diff options
context:
space:
mode:
authorGravatar gtm.daemon <gtm.daemon@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3>2011-04-28 20:30:21 +0000
committerGravatar gtm.daemon <gtm.daemon@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3>2011-04-28 20:30:21 +0000
commit784f85ae9a475667b7afb726d0653701c196ed48 (patch)
treecc258f8f11881c38875e3edc8bc8ef699ef24857 /Foundation/GTMLoggerTest.m
parente27ef9a94628853e1ab7dd9cf7ac883d96596dda (diff)
[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
Diffstat (limited to 'Foundation/GTMLoggerTest.m')
-rw-r--r--Foundation/GTMLoggerTest.m46
1 files changed, 39 insertions, 7 deletions
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<GTMLogFormatter> 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);
}