From 80704a61eab151018384000d4e83f7f512ee55f5 Mon Sep 17 00:00:00 2001 From: Dave MacLachlan Date: Mon, 20 May 2019 11:14:31 -0700 Subject: 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. --- GTM.xcodeproj/project.pbxproj | 1 + GTMiPhone.xcodeproj/project.pbxproj | 1 + UnitTesting/GTMSenTestCase.h | 16 ++++++++++++++++ UnitTesting/GTMSenTestCaseTest.m | 15 +++++++++++++++ 4 files changed, 33 insertions(+) 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 + -- cgit v1.2.3