diff options
author | Dave MacLachlan <dmaclach@gmail.com> | 2019-05-20 11:14:31 -0700 |
---|---|---|
committer | Thomas Van Lenten <thomasvl@google.com> | 2019-05-20 15:25:46 -0400 |
commit | 80704a61eab151018384000d4e83f7f512ee55f5 (patch) | |
tree | 5066a3de5840d57a7a89f359bc3b74f9e507a1a2 | |
parent | 6aa93248c389686805fbbc8260580f9fbeb3cb95 (diff) |
Add XCTAssertAsserts
XCTAssertAsserts is for testing if NSAssert or NSParameterAssert is called.
It is a no-op if NS_BLOCK_ASSERTIONS is defined.
Update project to match "Xcode" standard with regards to having assertions off in release.
-rw-r--r-- | GTM.xcodeproj/project.pbxproj | 1 | ||||
-rw-r--r-- | GTMiPhone.xcodeproj/project.pbxproj | 1 | ||||
-rw-r--r-- | UnitTesting/GTMSenTestCase.h | 16 | ||||
-rw-r--r-- | UnitTesting/GTMSenTestCaseTest.m | 15 |
4 files changed, 33 insertions, 0 deletions
diff --git a/GTM.xcodeproj/project.pbxproj b/GTM.xcodeproj/project.pbxproj index 148019d..438943c 100644 --- a/GTM.xcodeproj/project.pbxproj +++ b/GTM.xcodeproj/project.pbxproj @@ -1407,6 +1407,7 @@ CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; GCC_NO_COMMON_BLOCKS = YES; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; diff --git a/GTMiPhone.xcodeproj/project.pbxproj b/GTMiPhone.xcodeproj/project.pbxproj index 5974e05..995fe81 100644 --- a/GTMiPhone.xcodeproj/project.pbxproj +++ b/GTMiPhone.xcodeproj/project.pbxproj @@ -823,6 +823,7 @@ CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; GCC_NO_COMMON_BLOCKS = YES; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; diff --git a/UnitTesting/GTMSenTestCase.h b/UnitTesting/GTMSenTestCase.h index dad549c..1034830 100644 --- a/UnitTesting/GTMSenTestCase.h +++ b/UnitTesting/GTMSenTestCase.h @@ -350,6 +350,22 @@ }) #endif // XCTAssertNotEqualCStrings +/*! + * @define XCTAssertAsserts(expression, ...) + * Generates a failure when ((\a expression) does not assert. + * If NS_BLOCK_ASSERTIONS is enabled, this test will always pass. + * @param expression An expression. + * @param ... An optional supplementary description of the failure. A literal NSString, optionally + with string format specifiers. This parameter can be completely omitted. + */ +#ifndef NS_BLOCK_ASSERTIONS + #define XCTAssertAsserts(expression, ...) \ + _XCTPrimitiveAssertThrowsSpecificNamed(self, expression, @#expression, NSException, \ + NSInternalInconsistencyException, __VA_ARGS__) +#else + #define XCTAssertAsserts(expression, ...) +#endif + #else // GTM_USING_XCTEST // Generates a failure when a1 != noErr diff --git a/UnitTesting/GTMSenTestCaseTest.m b/UnitTesting/GTMSenTestCaseTest.m index 33055ad..edaa180 100644 --- a/UnitTesting/GTMSenTestCaseTest.m +++ b/UnitTesting/GTMSenTestCaseTest.m @@ -80,3 +80,18 @@ static int gZzCheckCalls_ = 0; } @end + +@interface GTMSenTestCase : GTMTestCase +@end + +@implementation GTMSenTestCase +- (void)funcThatAsserts { + NSAssert(nil, @"Should be nil"); +} + +- (void)testXCTAssertAsserts { + XCTAssertAsserts([self funcThatAsserts]); +} + +@end + |