-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Transition from NSAssert to GDTAssert in all GDT libraries #3768
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* Copyright 2019 Google | ||
* | ||
* 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 License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
#import <GoogleDataTransport/GDTConsoleLogger.h> | ||
|
||
/** A block type that could be run instead of normal assertion logging. No return type, no params. | ||
*/ | ||
typedef void (^GDTAssertionBlock)(void); | ||
|
||
/** Returns the result of executing a soft-linked method present in unit tests that allows a block | ||
* to be run instead of normal assertion logging. This helps ameliorate issues with catching | ||
* exceptions that occur on a dispatch_queue. | ||
* | ||
* @return A block that can be run instead of normal assert printing. | ||
*/ | ||
FOUNDATION_EXPORT GDTAssertionBlock _Nullable GDTAssertionBlockToRunInstead(void); | ||
|
||
#if defined(NS_BLOCK_ASSERTIONS) | ||
|
||
#define GDTAssert(condition, ...) \ | ||
do { \ | ||
} while (0); | ||
|
||
#define GDTFatalAssert(condition, ...) \ | ||
do { \ | ||
} while (0); | ||
|
||
#else // defined(NS_BLOCK_ASSERTIONS) | ||
|
||
/** Asserts using a console log, unless a block was specified to be run instead. | ||
* | ||
* @param condition The condition you'd expect to be YES. | ||
*/ | ||
#define GDTAssert(condition, ...) \ | ||
do { \ | ||
if (__builtin_expect(!(condition), 0)) { \ | ||
GDTAssertionBlock assertionBlock = GDTAssertionBlockToRunInstead(); \ | ||
if (assertionBlock) { \ | ||
assertionBlock(); \ | ||
} else { \ | ||
__PRAGMA_PUSH_NO_EXTRA_ARG_WARNINGS \ | ||
NSString *__assert_file__ = [NSString stringWithUTF8String:__FILE__]; \ | ||
__assert_file__ = __assert_file__ ? __assert_file__ : @"<Unknown File>"; \ | ||
GDTLogError(GDTMCEGeneralError, @"Assertion failed (%@:%d): %s,", __assert_file__, \ | ||
__LINE__, ##__VA_ARGS__); \ | ||
__PRAGMA_POP_NO_EXTRA_ARG_WARNINGS \ | ||
} \ | ||
} \ | ||
} while (0); | ||
|
||
/** Asserts by logging to the console and throwing an exception if NS_BLOCK_ASSERTIONS is not | ||
* defined. | ||
* | ||
* @param condition The condition you'd expect to be YES. | ||
*/ | ||
#define GDTFatalAssert(condition, ...) \ | ||
do { \ | ||
__PRAGMA_PUSH_NO_EXTRA_ARG_WARNINGS \ | ||
if (__builtin_expect(!(condition), 0)) { \ | ||
NSString *__assert_file__ = [NSString stringWithUTF8String:__FILE__]; \ | ||
__assert_file__ = __assert_file__ ? __assert_file__ : @"<Unknown File>"; \ | ||
GDTLogError(GDTMCEFatalAssertion, \ | ||
@"Fatal assertion encountered, please open an issue at " \ | ||
"https://github.com/firebase/firebase-ios-sdk/issues " \ | ||
"(%@:%d): %s,", \ | ||
__assert_file__, __LINE__, ##__VA_ARGS__); \ | ||
[[NSAssertionHandler currentHandler] handleFailureInMethod:_cmd \ | ||
object:self \ | ||
file:__assert_file__ \ | ||
lineNumber:__LINE__ \ | ||
description:@"%@", ##__VA_ARGS__]; \ | ||
} \ | ||
__PRAGMA_POP_NO_EXTRA_ARG_WARNINGS \ | ||
} while (0); | ||
|
||
#endif // defined(NS_BLOCK_ASSERTIONS) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright 2019 Google | ||
* | ||
* 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 License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#undef NS_BLOCK_ASSERTIONS | ||
|
||
#import <XCTest/XCTest.h> | ||
|
||
#import <GoogleDataTransport/GDTAssert.h> | ||
|
||
@interface GDTAssertNotBlockedTest : XCTestCase | ||
|
||
@end | ||
|
||
@implementation GDTAssertNotBlockedTest | ||
|
||
/** Tests that asserting is innocuous and doesn't throw. */ | ||
- (void)testNonFatallyAssertingDoesntThrow { | ||
GDTAssert(NO, @"test assertion"); | ||
} | ||
|
||
/** Tests that fatally asserting throws. */ | ||
- (void)testFatallyAssertingThrows { | ||
void (^assertionBlock)(void) = ^{ | ||
GDTFatalAssert(NO, @"test assertion") | ||
}; | ||
XCTAssertThrows(assertionBlock()); | ||
} | ||
@end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.