-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Create testing infrastructure that simplifies catching exceptions in dispatch_queues #2226
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
6 commits
Select commit
Hold shift + click to select a range
edd7d41
Apply updated clang-format
mikehaney24 886dad8
Add a custom assert and use it instead of NSAssert
mikehaney24 ce19646
Define a shared unit test test class and change unit tests to use it
mikehaney24 b6be537
Add the GDLAssertHelper to be used by GDLAsserts
mikehaney24 59b1e91
Change copyright year, style, and only define the assert macro body i…
mikehaney24 c72d0c7
Remove rvm specification from travis (#2227)
paulb777 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,8 +5,6 @@ cache: | |
- bundler | ||
- cocoapods | ||
|
||
rvm: 2.3.1 | ||
|
||
jobs: | ||
include: | ||
- stage: checks | ||
|
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,36 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
#include "GDLAssert.h" | ||
|
||
GDLAssertionBlock GDLAssertionBlockToRunInsteadOfNSAssert(void) { | ||
// This class is only compiled in by unit tests, and this should fail quickly in optimized builds. | ||
Class GDLAssertClass = NSClassFromString(@"GDLAssertHelper"); | ||
if (__builtin_expect(!!GDLAssertClass, 0)) { | ||
SEL assertionBlockSEL = NSSelectorFromString(@"assertionBlock"); | ||
if (assertionBlockSEL) { | ||
IMP assertionBlockIMP = [GDLAssertClass methodForSelector:assertionBlockSEL]; | ||
if (assertionBlockIMP) { | ||
GDLAssertionBlock assertionBlock = | ||
((GDLAssertionBlock(*)(id, SEL))assertionBlockIMP)(GDLAssertClass, assertionBlockSEL); | ||
if (assertionBlock) { | ||
return assertionBlock; | ||
} | ||
} | ||
} | ||
} | ||
return NULL; | ||
} |
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
54 changes: 54 additions & 0 deletions
54
GoogleDataLogger/GoogleDataLogger/Classes/Private/GDLAssert.h
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,54 @@ | ||
/* | ||
* 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> | ||
|
||
/** A block type that could be run instead of NSAssert. No return type, no params. */ | ||
typedef void (^GDLAssertionBlock)(void); | ||
|
||
/** Returns the result of executing a soft-linked method present in unit tests that allows a block | ||
* to be run in lieu of a call to NSAssert. This helps ameliorate issues with catching exceptions | ||
* that occur on a dispatch_queue. | ||
* | ||
* @return A block that can be run instead of calling NSAssert, or nil. | ||
*/ | ||
FOUNDATION_EXTERN GDLAssertionBlock _Nullable GDLAssertionBlockToRunInsteadOfNSAssert(void); | ||
|
||
#if !defined(NS_BLOCK_ASSERTIONS) | ||
|
||
/** Asserts using NSAssert, unless a block was specified to be run instead. | ||
* | ||
* @param condition The condition you'd expect to be YES. | ||
*/ | ||
#define GDLAssert(condition, ...) \ | ||
do { \ | ||
if (__builtin_expect(!(condition), 0)) { \ | ||
GDLAssertionBlock assertionBlock = GDLAssertionBlockToRunInsteadOfNSAssert(); \ | ||
if (assertionBlock) { \ | ||
assertionBlock(); \ | ||
} else { \ | ||
NSAssert(condition, __VA_ARGS__); \ | ||
} \ | ||
} \ | ||
} while (0); | ||
|
||
#else | ||
|
||
#define GDLAssert(condition, ...) \ | ||
do { \ | ||
} 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* 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 <XCTest/XCTest.h> | ||
|
||
#import "GDLAssertHelper.h" | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
/** This class defines shared testing infrastructure across all unit tests in GoogleDataLogger. */ | ||
@interface GDLTestCase : XCTestCase | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_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.