From 5b9fc43f5bc840ea1badd96744f9dae50ce039b1 Mon Sep 17 00:00:00 2001 From: Thomas Van Lenten Date: Fri, 5 Aug 2016 13:57:29 -0400 Subject: Remove the direct dependency on SenTestFailureException. --- UnitTesting/GTMUnitTestDevLog.h | 33 +++++++++++++++++++-------------- UnitTesting/GTMUnitTestDevLog.m | 9 ++++++--- 2 files changed, 25 insertions(+), 17 deletions(-) (limited to 'UnitTesting') diff --git a/UnitTesting/GTMUnitTestDevLog.h b/UnitTesting/GTMUnitTestDevLog.h index f80743a..2be231e 100644 --- a/UnitTesting/GTMUnitTestDevLog.h +++ b/UnitTesting/GTMUnitTestDevLog.h @@ -1,14 +1,14 @@ // // GTMUnitTestDevLog.h -// +// // Copyright 2008 Google Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); you may not // use this file except in compliance with the License. You may obtain a copy // of the License at -// +// // http://www.apache.org/licenses/LICENSE-2.0 -// +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the @@ -25,7 +25,7 @@ // to find unexpected logs in your output when running unittests. // In your unittests you tell GTMUnitTestDevLog what messages you expect your // test to spit out, and it will cause any that don't match to appear as errors -// in your unittest run output. You can match on exact strings or standard +// in your unittest run output. You can match on exact strings or standard // regexps. // Set GTM_SHOW_UNITTEST_DEVLOGS in the environment to show the logs that that // are expected and encountered. Otherwise they aren't display to keep the @@ -33,8 +33,8 @@ @interface GTMUnitTestDevLog : NSObject // Log a message -+ (void)log:(NSString*)format, ... NS_FORMAT_FUNCTION(1,2); -+ (void)log:(NSString*)format args:(va_list)args NS_FORMAT_FUNCTION(1,0); ++ (void)log:(NSString*)format, ... NS_FORMAT_FUNCTION(1, 2); ++ (void)log:(NSString*)format args:(va_list)args NS_FORMAT_FUNCTION(1, 0); // Turn tracking on/off + (void)enableTracking; @@ -43,24 +43,25 @@ // Note that you are expecting a string that has an exact match. No need to // escape any pattern characters. -+ (void)expectString:(NSString *)format, ... NS_FORMAT_FUNCTION(1,2); ++ (void)expectString:(NSString *)format, ... NS_FORMAT_FUNCTION(1, 2); // Note that you are expecting a pattern. Pattern characters that you want // exact matches on must be escaped. See [GTMRegex escapedPatternForString]. // Patterns match across newlines (kGTMRegexOptionSupressNewlineSupport) making // it easier to match output from the descriptions of NS collection types such // as NSArray and NSDictionary. -+ (void)expectPattern:(NSString *)format, ... NS_FORMAT_FUNCTION(1,2); ++ (void)expectPattern:(NSString *)format, ... NS_FORMAT_FUNCTION(1, 2); // Note that you are expecting exactly 'n' strings -+ (void)expect:(NSUInteger)n - casesOfString:(NSString *)format, ... NS_FORMAT_FUNCTION(2,3); ++ (void)expect:(NSUInteger)n + casesOfString:(NSString *)format, ... NS_FORMAT_FUNCTION(2, 3); // Note that you are expecting exactly 'n' patterns -+ (void)expect:(NSUInteger)n - casesOfPattern:(NSString*)format, ... NS_FORMAT_FUNCTION(2,3); -+ (void)expect:(NSUInteger)n - casesOfPattern:(NSString*)format args:(va_list)args NS_FORMAT_FUNCTION(2,0); ++ (void)expect:(NSUInteger)n + casesOfPattern:(NSString*)format, ... NS_FORMAT_FUNCTION(2, 3); ++ (void)expect:(NSUInteger)n + casesOfPattern:(NSString*)format + args:(va_list)args NS_FORMAT_FUNCTION(2, 0); // Call when you want to verify that you have matched all the logs you expect // to match. If your unittests inherit from GTMTestcase (like they should) you @@ -77,3 +78,7 @@ // ie-the expect requests don't count in release builds. @interface GTMUnitTestDevLogDebug : GTMUnitTestDevLog @end + +// The name of the exception that is raised when GTMUnitTestDevLog +// finds a problem. +GTM_EXTERN NSString *const GTMLogFailureException; diff --git a/UnitTesting/GTMUnitTestDevLog.m b/UnitTesting/GTMUnitTestDevLog.m index fd90396..7a12bb0 100644 --- a/UnitTesting/GTMUnitTestDevLog.m +++ b/UnitTesting/GTMUnitTestDevLog.m @@ -61,6 +61,8 @@ static inline void GTMInstallDebugAssertOutputHandler(void) {}; static inline void GTMUninstallDebugAssertOutputHandler(void) {}; #endif // GTM_IPHONE_SDK +NSString *const GTMLogFailureException = @"GTMLogFailureException"; + @interface GTMUnttestDevLogAssertionHandler : NSAssertionHandler @end @@ -182,12 +184,13 @@ static BOOL gTrackingEnabled = NO; [patterns removeObjectAtIndex:0]; } if (logError) { + if (regex) { - [NSException raise:SenTestFailureException + [NSException raise:GTMLogFailureException format:@"Unexpected log: %@\nExpected: %@", logString, regex]; } else { - [NSException raise:SenTestFailureException + [NSException raise:GTMLogFailureException format:@"Unexpected log: %@", logString]; } } else { @@ -262,7 +265,7 @@ casesOfPattern:(NSString*)format if ([patterns count] > 0) { NSMutableArray *patternsCopy = [[patterns copy] autorelease]; [self resetExpectedLogs]; - [NSException raise:SenTestFailureException + [NSException raise:GTMLogFailureException format:@"Logs still expected %@", patternsCopy]; } } -- cgit v1.2.3