├── .gitignore ├── Assertions.xcodeproj ├── project.pbxproj └── project.xcworkspace │ └── contents.xcworkspacedata ├── Assertions ├── AppDelegate.swift ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── Info.plist ├── ProgrammerAssertions.swift └── ProgrammerAssertionsExampleDivide.swift ├── AssertionsTests ├── Info.plist ├── ProgrammerAssertionsExampleTests.swift └── XCTestCase+ProgrammerAssertions.swift ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | build/ 4 | *.pbxuser 5 | !default.pbxuser 6 | *.mode1v3 7 | !default.mode1v3 8 | *.mode2v3 9 | !default.mode2v3 10 | *.perspectivev3 11 | !default.perspectivev3 12 | xcuserdata 13 | *.xccheckout 14 | *.moved-aside 15 | DerivedData 16 | *.hmap 17 | *.ipa 18 | *.xcuserstate 19 | 20 | # CocoaPods 21 | # 22 | # We recommend against adding the Pods directory to your .gitignore. However 23 | # you should judge for yourself, the pros and cons are mentioned at: 24 | # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control 25 | # 26 | #Pods/ 27 | -------------------------------------------------------------------------------- /Assertions.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 548AAC121C271584003BC389 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 548AAC111C271584003BC389 /* AppDelegate.swift */; }; 11 | 548AAC141C271584003BC389 /* ProgrammerAssertionsExampleDivide.swift in Sources */ = {isa = PBXBuildFile; fileRef = 548AAC131C271584003BC389 /* ProgrammerAssertionsExampleDivide.swift */; }; 12 | 548AAC171C271584003BC389 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 548AAC151C271584003BC389 /* Main.storyboard */; }; 13 | 548AAC191C271584003BC389 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 548AAC181C271584003BC389 /* Assets.xcassets */; }; 14 | 548AAC1C1C271584003BC389 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 548AAC1A1C271584003BC389 /* LaunchScreen.storyboard */; }; 15 | 548AAC2A1C271594003BC389 /* ProgrammerAssertionsExampleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 548AAC291C271594003BC389 /* ProgrammerAssertionsExampleTests.swift */; }; 16 | 548AAC321C2715AC003BC389 /* XCTestCase+ProgrammerAssertions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 548AAC311C2715AC003BC389 /* XCTestCase+ProgrammerAssertions.swift */; }; 17 | 548AAC341C2715C2003BC389 /* ProgrammerAssertions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 548AAC331C2715C2003BC389 /* ProgrammerAssertions.swift */; }; 18 | /* End PBXBuildFile section */ 19 | 20 | /* Begin PBXContainerItemProxy section */ 21 | 548AAC2C1C271594003BC389 /* PBXContainerItemProxy */ = { 22 | isa = PBXContainerItemProxy; 23 | containerPortal = 548AAC061C271584003BC389 /* Project object */; 24 | proxyType = 1; 25 | remoteGlobalIDString = 548AAC0D1C271584003BC389; 26 | remoteInfo = Assertions; 27 | }; 28 | /* End PBXContainerItemProxy section */ 29 | 30 | /* Begin PBXFileReference section */ 31 | 548AAC0E1C271584003BC389 /* Assertions.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Assertions.app; sourceTree = BUILT_PRODUCTS_DIR; }; 32 | 548AAC111C271584003BC389 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 33 | 548AAC131C271584003BC389 /* ProgrammerAssertionsExampleDivide.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProgrammerAssertionsExampleDivide.swift; sourceTree = ""; }; 34 | 548AAC161C271584003BC389 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 35 | 548AAC181C271584003BC389 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 36 | 548AAC1B1C271584003BC389 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 37 | 548AAC1D1C271584003BC389 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 38 | 548AAC271C271594003BC389 /* AssertionsTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = AssertionsTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 39 | 548AAC291C271594003BC389 /* ProgrammerAssertionsExampleTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProgrammerAssertionsExampleTests.swift; sourceTree = ""; }; 40 | 548AAC2B1C271594003BC389 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 41 | 548AAC311C2715AC003BC389 /* XCTestCase+ProgrammerAssertions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "XCTestCase+ProgrammerAssertions.swift"; sourceTree = ""; }; 42 | 548AAC331C2715C2003BC389 /* ProgrammerAssertions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ProgrammerAssertions.swift; sourceTree = ""; }; 43 | /* End PBXFileReference section */ 44 | 45 | /* Begin PBXFrameworksBuildPhase section */ 46 | 548AAC0B1C271584003BC389 /* Frameworks */ = { 47 | isa = PBXFrameworksBuildPhase; 48 | buildActionMask = 2147483647; 49 | files = ( 50 | ); 51 | runOnlyForDeploymentPostprocessing = 0; 52 | }; 53 | 548AAC241C271594003BC389 /* Frameworks */ = { 54 | isa = PBXFrameworksBuildPhase; 55 | buildActionMask = 2147483647; 56 | files = ( 57 | ); 58 | runOnlyForDeploymentPostprocessing = 0; 59 | }; 60 | /* End PBXFrameworksBuildPhase section */ 61 | 62 | /* Begin PBXGroup section */ 63 | 548AAC051C271584003BC389 = { 64 | isa = PBXGroup; 65 | children = ( 66 | 548AAC101C271584003BC389 /* Assertions */, 67 | 548AAC281C271594003BC389 /* AssertionsTests */, 68 | 548AAC0F1C271584003BC389 /* Products */, 69 | ); 70 | sourceTree = ""; 71 | }; 72 | 548AAC0F1C271584003BC389 /* Products */ = { 73 | isa = PBXGroup; 74 | children = ( 75 | 548AAC0E1C271584003BC389 /* Assertions.app */, 76 | 548AAC271C271594003BC389 /* AssertionsTests.xctest */, 77 | ); 78 | name = Products; 79 | sourceTree = ""; 80 | }; 81 | 548AAC101C271584003BC389 /* Assertions */ = { 82 | isa = PBXGroup; 83 | children = ( 84 | 548AAC331C2715C2003BC389 /* ProgrammerAssertions.swift */, 85 | 548AAC131C271584003BC389 /* ProgrammerAssertionsExampleDivide.swift */, 86 | 548AAC361C283F39003BC389 /* AppDelegate */, 87 | 548AAC351C283F2B003BC389 /* Resources */, 88 | ); 89 | path = Assertions; 90 | sourceTree = ""; 91 | }; 92 | 548AAC281C271594003BC389 /* AssertionsTests */ = { 93 | isa = PBXGroup; 94 | children = ( 95 | 548AAC311C2715AC003BC389 /* XCTestCase+ProgrammerAssertions.swift */, 96 | 548AAC291C271594003BC389 /* ProgrammerAssertionsExampleTests.swift */, 97 | 548AAC371C283F4A003BC389 /* Resources */, 98 | ); 99 | path = AssertionsTests; 100 | sourceTree = ""; 101 | }; 102 | 548AAC351C283F2B003BC389 /* Resources */ = { 103 | isa = PBXGroup; 104 | children = ( 105 | 548AAC151C271584003BC389 /* Main.storyboard */, 106 | 548AAC181C271584003BC389 /* Assets.xcassets */, 107 | 548AAC1A1C271584003BC389 /* LaunchScreen.storyboard */, 108 | 548AAC1D1C271584003BC389 /* Info.plist */, 109 | ); 110 | name = Resources; 111 | sourceTree = ""; 112 | }; 113 | 548AAC361C283F39003BC389 /* AppDelegate */ = { 114 | isa = PBXGroup; 115 | children = ( 116 | 548AAC111C271584003BC389 /* AppDelegate.swift */, 117 | ); 118 | name = AppDelegate; 119 | sourceTree = ""; 120 | }; 121 | 548AAC371C283F4A003BC389 /* Resources */ = { 122 | isa = PBXGroup; 123 | children = ( 124 | 548AAC2B1C271594003BC389 /* Info.plist */, 125 | ); 126 | name = Resources; 127 | sourceTree = ""; 128 | }; 129 | /* End PBXGroup section */ 130 | 131 | /* Begin PBXNativeTarget section */ 132 | 548AAC0D1C271584003BC389 /* Assertions */ = { 133 | isa = PBXNativeTarget; 134 | buildConfigurationList = 548AAC201C271584003BC389 /* Build configuration list for PBXNativeTarget "Assertions" */; 135 | buildPhases = ( 136 | 548AAC0A1C271584003BC389 /* Sources */, 137 | 548AAC0B1C271584003BC389 /* Frameworks */, 138 | 548AAC0C1C271584003BC389 /* Resources */, 139 | ); 140 | buildRules = ( 141 | ); 142 | dependencies = ( 143 | ); 144 | name = Assertions; 145 | productName = Assertions; 146 | productReference = 548AAC0E1C271584003BC389 /* Assertions.app */; 147 | productType = "com.apple.product-type.application"; 148 | }; 149 | 548AAC261C271594003BC389 /* AssertionsTests */ = { 150 | isa = PBXNativeTarget; 151 | buildConfigurationList = 548AAC2E1C271594003BC389 /* Build configuration list for PBXNativeTarget "AssertionsTests" */; 152 | buildPhases = ( 153 | 548AAC231C271594003BC389 /* Sources */, 154 | 548AAC241C271594003BC389 /* Frameworks */, 155 | 548AAC251C271594003BC389 /* Resources */, 156 | ); 157 | buildRules = ( 158 | ); 159 | dependencies = ( 160 | 548AAC2D1C271594003BC389 /* PBXTargetDependency */, 161 | ); 162 | name = AssertionsTests; 163 | productName = AssertionsTests; 164 | productReference = 548AAC271C271594003BC389 /* AssertionsTests.xctest */; 165 | productType = "com.apple.product-type.bundle.unit-test"; 166 | }; 167 | /* End PBXNativeTarget section */ 168 | 169 | /* Begin PBXProject section */ 170 | 548AAC061C271584003BC389 /* Project object */ = { 171 | isa = PBXProject; 172 | attributes = { 173 | LastSwiftUpdateCheck = 0720; 174 | LastUpgradeCheck = 0720; 175 | ORGANIZATIONNAME = mohamede1945; 176 | TargetAttributes = { 177 | 548AAC0D1C271584003BC389 = { 178 | CreatedOnToolsVersion = 7.2; 179 | }; 180 | 548AAC261C271594003BC389 = { 181 | CreatedOnToolsVersion = 7.2; 182 | TestTargetID = 548AAC0D1C271584003BC389; 183 | }; 184 | }; 185 | }; 186 | buildConfigurationList = 548AAC091C271584003BC389 /* Build configuration list for PBXProject "Assertions" */; 187 | compatibilityVersion = "Xcode 3.2"; 188 | developmentRegion = English; 189 | hasScannedForEncodings = 0; 190 | knownRegions = ( 191 | en, 192 | Base, 193 | ); 194 | mainGroup = 548AAC051C271584003BC389; 195 | productRefGroup = 548AAC0F1C271584003BC389 /* Products */; 196 | projectDirPath = ""; 197 | projectRoot = ""; 198 | targets = ( 199 | 548AAC0D1C271584003BC389 /* Assertions */, 200 | 548AAC261C271594003BC389 /* AssertionsTests */, 201 | ); 202 | }; 203 | /* End PBXProject section */ 204 | 205 | /* Begin PBXResourcesBuildPhase section */ 206 | 548AAC0C1C271584003BC389 /* Resources */ = { 207 | isa = PBXResourcesBuildPhase; 208 | buildActionMask = 2147483647; 209 | files = ( 210 | 548AAC1C1C271584003BC389 /* LaunchScreen.storyboard in Resources */, 211 | 548AAC191C271584003BC389 /* Assets.xcassets in Resources */, 212 | 548AAC171C271584003BC389 /* Main.storyboard in Resources */, 213 | ); 214 | runOnlyForDeploymentPostprocessing = 0; 215 | }; 216 | 548AAC251C271594003BC389 /* Resources */ = { 217 | isa = PBXResourcesBuildPhase; 218 | buildActionMask = 2147483647; 219 | files = ( 220 | ); 221 | runOnlyForDeploymentPostprocessing = 0; 222 | }; 223 | /* End PBXResourcesBuildPhase section */ 224 | 225 | /* Begin PBXSourcesBuildPhase section */ 226 | 548AAC0A1C271584003BC389 /* Sources */ = { 227 | isa = PBXSourcesBuildPhase; 228 | buildActionMask = 2147483647; 229 | files = ( 230 | 548AAC141C271584003BC389 /* ProgrammerAssertionsExampleDivide.swift in Sources */, 231 | 548AAC341C2715C2003BC389 /* ProgrammerAssertions.swift in Sources */, 232 | 548AAC121C271584003BC389 /* AppDelegate.swift in Sources */, 233 | ); 234 | runOnlyForDeploymentPostprocessing = 0; 235 | }; 236 | 548AAC231C271594003BC389 /* Sources */ = { 237 | isa = PBXSourcesBuildPhase; 238 | buildActionMask = 2147483647; 239 | files = ( 240 | 548AAC2A1C271594003BC389 /* ProgrammerAssertionsExampleTests.swift in Sources */, 241 | 548AAC321C2715AC003BC389 /* XCTestCase+ProgrammerAssertions.swift in Sources */, 242 | ); 243 | runOnlyForDeploymentPostprocessing = 0; 244 | }; 245 | /* End PBXSourcesBuildPhase section */ 246 | 247 | /* Begin PBXTargetDependency section */ 248 | 548AAC2D1C271594003BC389 /* PBXTargetDependency */ = { 249 | isa = PBXTargetDependency; 250 | target = 548AAC0D1C271584003BC389 /* Assertions */; 251 | targetProxy = 548AAC2C1C271594003BC389 /* PBXContainerItemProxy */; 252 | }; 253 | /* End PBXTargetDependency section */ 254 | 255 | /* Begin PBXVariantGroup section */ 256 | 548AAC151C271584003BC389 /* Main.storyboard */ = { 257 | isa = PBXVariantGroup; 258 | children = ( 259 | 548AAC161C271584003BC389 /* Base */, 260 | ); 261 | name = Main.storyboard; 262 | sourceTree = ""; 263 | }; 264 | 548AAC1A1C271584003BC389 /* LaunchScreen.storyboard */ = { 265 | isa = PBXVariantGroup; 266 | children = ( 267 | 548AAC1B1C271584003BC389 /* Base */, 268 | ); 269 | name = LaunchScreen.storyboard; 270 | sourceTree = ""; 271 | }; 272 | /* End PBXVariantGroup section */ 273 | 274 | /* Begin XCBuildConfiguration section */ 275 | 548AAC1E1C271584003BC389 /* Debug */ = { 276 | isa = XCBuildConfiguration; 277 | buildSettings = { 278 | ALWAYS_SEARCH_USER_PATHS = NO; 279 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 280 | CLANG_CXX_LIBRARY = "libc++"; 281 | CLANG_ENABLE_MODULES = YES; 282 | CLANG_ENABLE_OBJC_ARC = YES; 283 | CLANG_WARN_BOOL_CONVERSION = YES; 284 | CLANG_WARN_CONSTANT_CONVERSION = YES; 285 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 286 | CLANG_WARN_EMPTY_BODY = YES; 287 | CLANG_WARN_ENUM_CONVERSION = YES; 288 | CLANG_WARN_INT_CONVERSION = YES; 289 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 290 | CLANG_WARN_UNREACHABLE_CODE = YES; 291 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 292 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 293 | COPY_PHASE_STRIP = NO; 294 | DEBUG_INFORMATION_FORMAT = dwarf; 295 | ENABLE_STRICT_OBJC_MSGSEND = YES; 296 | ENABLE_TESTABILITY = YES; 297 | GCC_C_LANGUAGE_STANDARD = gnu99; 298 | GCC_DYNAMIC_NO_PIC = NO; 299 | GCC_NO_COMMON_BLOCKS = YES; 300 | GCC_OPTIMIZATION_LEVEL = 0; 301 | GCC_PREPROCESSOR_DEFINITIONS = ( 302 | "DEBUG=1", 303 | "$(inherited)", 304 | ); 305 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 306 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 307 | GCC_WARN_UNDECLARED_SELECTOR = YES; 308 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 309 | GCC_WARN_UNUSED_FUNCTION = YES; 310 | GCC_WARN_UNUSED_VARIABLE = YES; 311 | IPHONEOS_DEPLOYMENT_TARGET = 9.2; 312 | MTL_ENABLE_DEBUG_INFO = YES; 313 | ONLY_ACTIVE_ARCH = YES; 314 | SDKROOT = iphoneos; 315 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 316 | }; 317 | name = Debug; 318 | }; 319 | 548AAC1F1C271584003BC389 /* Release */ = { 320 | isa = XCBuildConfiguration; 321 | buildSettings = { 322 | ALWAYS_SEARCH_USER_PATHS = NO; 323 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 324 | CLANG_CXX_LIBRARY = "libc++"; 325 | CLANG_ENABLE_MODULES = YES; 326 | CLANG_ENABLE_OBJC_ARC = YES; 327 | CLANG_WARN_BOOL_CONVERSION = YES; 328 | CLANG_WARN_CONSTANT_CONVERSION = YES; 329 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 330 | CLANG_WARN_EMPTY_BODY = YES; 331 | CLANG_WARN_ENUM_CONVERSION = YES; 332 | CLANG_WARN_INT_CONVERSION = YES; 333 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 334 | CLANG_WARN_UNREACHABLE_CODE = YES; 335 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 336 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 337 | COPY_PHASE_STRIP = NO; 338 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 339 | ENABLE_NS_ASSERTIONS = NO; 340 | ENABLE_STRICT_OBJC_MSGSEND = YES; 341 | GCC_C_LANGUAGE_STANDARD = gnu99; 342 | GCC_NO_COMMON_BLOCKS = YES; 343 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 344 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 345 | GCC_WARN_UNDECLARED_SELECTOR = YES; 346 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 347 | GCC_WARN_UNUSED_FUNCTION = YES; 348 | GCC_WARN_UNUSED_VARIABLE = YES; 349 | IPHONEOS_DEPLOYMENT_TARGET = 9.2; 350 | MTL_ENABLE_DEBUG_INFO = NO; 351 | SDKROOT = iphoneos; 352 | VALIDATE_PRODUCT = YES; 353 | }; 354 | name = Release; 355 | }; 356 | 548AAC211C271584003BC389 /* Debug */ = { 357 | isa = XCBuildConfiguration; 358 | buildSettings = { 359 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 360 | INFOPLIST_FILE = Assertions/Info.plist; 361 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 362 | PRODUCT_BUNDLE_IDENTIFIER = com.mohamede1945.Assertions; 363 | PRODUCT_NAME = "$(TARGET_NAME)"; 364 | }; 365 | name = Debug; 366 | }; 367 | 548AAC221C271584003BC389 /* Release */ = { 368 | isa = XCBuildConfiguration; 369 | buildSettings = { 370 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 371 | INFOPLIST_FILE = Assertions/Info.plist; 372 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 373 | PRODUCT_BUNDLE_IDENTIFIER = com.mohamede1945.Assertions; 374 | PRODUCT_NAME = "$(TARGET_NAME)"; 375 | }; 376 | name = Release; 377 | }; 378 | 548AAC2F1C271594003BC389 /* Debug */ = { 379 | isa = XCBuildConfiguration; 380 | buildSettings = { 381 | BUNDLE_LOADER = "$(TEST_HOST)"; 382 | INFOPLIST_FILE = AssertionsTests/Info.plist; 383 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 384 | PRODUCT_BUNDLE_IDENTIFIER = com.mohamede1945.AssertionsTests; 385 | PRODUCT_NAME = "$(TARGET_NAME)"; 386 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Assertions.app/Assertions"; 387 | }; 388 | name = Debug; 389 | }; 390 | 548AAC301C271594003BC389 /* Release */ = { 391 | isa = XCBuildConfiguration; 392 | buildSettings = { 393 | BUNDLE_LOADER = "$(TEST_HOST)"; 394 | INFOPLIST_FILE = AssertionsTests/Info.plist; 395 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 396 | PRODUCT_BUNDLE_IDENTIFIER = com.mohamede1945.AssertionsTests; 397 | PRODUCT_NAME = "$(TARGET_NAME)"; 398 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Assertions.app/Assertions"; 399 | }; 400 | name = Release; 401 | }; 402 | /* End XCBuildConfiguration section */ 403 | 404 | /* Begin XCConfigurationList section */ 405 | 548AAC091C271584003BC389 /* Build configuration list for PBXProject "Assertions" */ = { 406 | isa = XCConfigurationList; 407 | buildConfigurations = ( 408 | 548AAC1E1C271584003BC389 /* Debug */, 409 | 548AAC1F1C271584003BC389 /* Release */, 410 | ); 411 | defaultConfigurationIsVisible = 0; 412 | defaultConfigurationName = Release; 413 | }; 414 | 548AAC201C271584003BC389 /* Build configuration list for PBXNativeTarget "Assertions" */ = { 415 | isa = XCConfigurationList; 416 | buildConfigurations = ( 417 | 548AAC211C271584003BC389 /* Debug */, 418 | 548AAC221C271584003BC389 /* Release */, 419 | ); 420 | defaultConfigurationIsVisible = 0; 421 | defaultConfigurationName = Release; 422 | }; 423 | 548AAC2E1C271594003BC389 /* Build configuration list for PBXNativeTarget "AssertionsTests" */ = { 424 | isa = XCConfigurationList; 425 | buildConfigurations = ( 426 | 548AAC2F1C271594003BC389 /* Debug */, 427 | 548AAC301C271594003BC389 /* Release */, 428 | ); 429 | defaultConfigurationIsVisible = 0; 430 | defaultConfigurationName = Release; 431 | }; 432 | /* End XCConfigurationList section */ 433 | }; 434 | rootObject = 548AAC061C271584003BC389 /* Project object */; 435 | } 436 | -------------------------------------------------------------------------------- /Assertions.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Assertions/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // Assertions 4 | // 5 | // Created by Mohamed Afifi on 12/20/15. 6 | // Copyright © 2015 mohamede1945. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 17 | return true 18 | } 19 | } 20 | 21 | -------------------------------------------------------------------------------- /Assertions/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /Assertions/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /Assertions/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /Assertions/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /Assertions/ProgrammerAssertions.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ProgrammerAssertions.swift 3 | // Assertions 4 | // 5 | // Created by Mohamed Afifi on 12/20/15. 6 | // Copyright © 2015 mohamede1945. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | 12 | /// ### IMPORTANT HOW TO USE ### 13 | /// 1. Drop `ProgrammerAssertions.swift` to the target of your app or framework under test. Just besides your source code. 14 | /// 2. Drop `XCTestCase+ProgrammerAssertions.swift` to your test target. Just besides your test cases. 15 | /// 3. Use `assert`, `assertionFailure`, `precondition`, `preconditionFailure` and `fatalError` normally as you always do. 16 | /// 4. Unit test them with the new methods `expectAssert`, `expectAssertionFailure`, `expectPrecondition`, `expectPreconditionFailure` and `expectFatalError`. 17 | /// 18 | /// This file is an overriden implementation of Swift assertions functions. 19 | /// For a complete project example see 20 | 21 | 22 | /// drop-in replacements 23 | 24 | public func assert(@autoclosure condition: () -> Bool, @autoclosure _ message: () -> String = "", file: StaticString = #file, line: UInt = #line) { 25 | Assertions.assertClosure(condition(), message(), file, line) 26 | } 27 | 28 | public func assertionFailure(@autoclosure message: () -> String = "", file: StaticString = #file, line: UInt = #line) { 29 | Assertions.assertionFailureClosure(message(), file, line) 30 | } 31 | 32 | public func precondition(@autoclosure condition: () -> Bool, @autoclosure _ message: () -> String = "", file: StaticString = #file, line: UInt = #line) { 33 | Assertions.preconditionClosure(condition(), message(), file, line) 34 | } 35 | 36 | @noreturn public func preconditionFailure(@autoclosure message: () -> String = "", file: StaticString = #file, line: UInt = #line) { 37 | Assertions.preconditionFailureClosure(message(), file, line) 38 | runForever() 39 | } 40 | 41 | @noreturn public func fatalError(@autoclosure message: () -> String = "", file: StaticString = #file, line: UInt = #line) { 42 | Assertions.fatalErrorClosure(message(), file, line) 43 | runForever() 44 | } 45 | 46 | /// Stores custom assertions closures, by default it points to Swift functions. But test target can override them. 47 | public class Assertions { 48 | 49 | public static var assertClosure = swiftAssertClosure 50 | public static var assertionFailureClosure = swiftAssertionFailureClosure 51 | public static var preconditionClosure = swiftPreconditionClosure 52 | public static var preconditionFailureClosure = swiftPreconditionFailureClosure 53 | public static var fatalErrorClosure = swiftFatalErrorClosure 54 | 55 | public static let swiftAssertClosure = { Swift.assert($0, $1, file: $2, line: $3) } 56 | public static let swiftAssertionFailureClosure = { Swift.assertionFailure($0, file: $1, line: $2) } 57 | public static let swiftPreconditionClosure = { Swift.precondition($0, $1, file: $2, line: $3) } 58 | public static let swiftPreconditionFailureClosure = { Swift.preconditionFailure($0, file: $1, line: $2) } 59 | public static let swiftFatalErrorClosure = { Swift.fatalError($0, file: $1, line: $2) } 60 | } 61 | 62 | /// This is a `noreturn` function that runs forever and doesn't return. 63 | /// Used by assertions with `@noreturn`. 64 | @noreturn private func runForever() { 65 | repeat { 66 | NSRunLoop.currentRunLoop().run() 67 | } while (true) 68 | } 69 | -------------------------------------------------------------------------------- /Assertions/ProgrammerAssertionsExampleDivide.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ProgrammerAssertionsExampleDivide.swift 3 | // Assertions 4 | // 5 | // Created by Mohamed Afifi on 12/20/15. 6 | // Copyright © 2015 mohamede1945. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | /// ### IMPORTANT HOW TO USE ### 12 | /// 1. Drop `ProgrammerAssertions.swift` to the target of your app or framework under test. Just besides your source code. 13 | /// 2. Drop `XCTestCase+ProgrammerAssertions.swift` to your test target. Just besides your test cases. 14 | /// 3. Use `assert`, `assertionFailure`, `precondition`, `preconditionFailure` and `fatalError` normally as you always do. 15 | /// 4. Unit test them with the new methods `expectAssert`, `expectAssertionFailure`, `expectPrecondition`, `expectPreconditionFailure` and `expectFatalError`. 16 | /// 17 | /// This file is just an example of how to use the functions. Normally as you would do previously. 18 | /// For a complete project example see 19 | 20 | func divideAssert(x: Float, by y: Float) -> Float { 21 | 22 | assert(y != 0, "Zero division") 23 | 24 | return x / y 25 | } 26 | 27 | func divideAssertionFailure(x: Float, by y: Float) -> Float { 28 | 29 | guard y != 0 else { 30 | assertionFailure("Zero division") 31 | return Float.infinity 32 | } 33 | 34 | return x / y 35 | } 36 | 37 | 38 | func dividePrecondition(x: Float, by y: Float) -> Float { 39 | 40 | precondition(y != 0, "Zero division") 41 | 42 | return x / y 43 | } 44 | 45 | func dividePreconditionFailure(x: Float, by y: Float) -> Float { 46 | 47 | guard y != 0 else { 48 | preconditionFailure("Zero division") 49 | } 50 | 51 | return x / y 52 | } 53 | 54 | func divideFatalError(x: Float, by y: Float) -> Float { 55 | 56 | guard y != 0 else { 57 | fatalError("Zero division") 58 | } 59 | 60 | return x / y 61 | } -------------------------------------------------------------------------------- /AssertionsTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /AssertionsTests/ProgrammerAssertionsExampleTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ProgrammerAssertionsExampleTests.swift 3 | // AssertionsTests 4 | // 5 | // Created by Mohamed Afifi on 12/20/15. 6 | // Copyright © 2015 mohamede1945. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | @testable import Assertions 11 | 12 | 13 | /// ### IMPORTANT HOW TO USE ### 14 | /// 1. Drop `ProgrammerAssertions.swift` to the target of your app or framework under test. Just besides your source code. 15 | /// 2. Drop `XCTestCase+ProgrammerAssertions.swift` to your test target. Just besides your test cases. 16 | /// 3. Use `assert`, `assertionFailure`, `precondition`, `preconditionFailure` and `fatalError` normally as you always do. 17 | /// 4. Unit test them with the new methods `expectAssert`, `expectAssertionFailure`, `expectPrecondition`, `expectPreconditionFailure` and `expectFatalError`. 18 | /// 19 | /// This file is just an example of how to unit test the functions. 20 | /// When you run tests, you should expect many of them to fail. This is normally, because the test cases tests the error message produced by expectXXX methods. 21 | /// For a complete project example see 22 | 23 | class AssertionsTestsExample: XCTestCase { 24 | 25 | // assert tests 26 | 27 | func testAssertNotCalled() { 28 | expectAssert("Zero division") { 29 | } 30 | } 31 | 32 | func testAssertTrueCondition() { 33 | expectAssert("Zero division") { 34 | divideAssert(1, by: 1) 35 | } 36 | } 37 | 38 | func testAssertNoMessage() { 39 | expectAssert() { 40 | divideAssert(1, by: 0) 41 | } 42 | } 43 | 44 | func testAssertErrorIncorrectMessage() { 45 | expectAssert("Invalid") { 46 | divideAssert(1, by: 0) 47 | } 48 | } 49 | 50 | func testAssertCorrectMessage() { 51 | expectAssert("Zero division") { 52 | divideAssert(1, by: 0) 53 | } 54 | } 55 | 56 | // expectionFailure tests 57 | 58 | func testAssertionFailureNotCalled() { 59 | expectAssertionFailure("Zero division") { 60 | divideAssertionFailure(1, by: 1) 61 | } 62 | } 63 | 64 | func testAssertionFailureNoMessage() { 65 | expectAssertionFailure() { 66 | divideAssertionFailure(1, by: 0) 67 | } 68 | } 69 | 70 | func testAssertionFailureErrorIncorrectMessage() { 71 | expectAssertionFailure("Invalid") { 72 | divideAssertionFailure(1, by: 0) 73 | } 74 | } 75 | 76 | func testAssertionFailureCorrectMessage() { 77 | expectAssertionFailure("Zero division") { 78 | divideAssertionFailure(1, by: 0) 79 | } 80 | } 81 | 82 | 83 | // precondition tests 84 | 85 | func testPreconditionNotCalled() { 86 | expectPrecondition("Zero division") { 87 | } 88 | } 89 | 90 | func testPreconditionTrueCondition() { 91 | expectPrecondition("Zero division") { 92 | dividePrecondition(1, by: 1) 93 | } 94 | } 95 | 96 | func testPreconditionNoMessage() { 97 | expectPrecondition() { 98 | dividePrecondition(1, by: 0) 99 | } 100 | } 101 | 102 | func testPreconditionErrorIncorrectMessage() { 103 | expectPrecondition("Invalid") { 104 | dividePrecondition(1, by: 0) 105 | } 106 | } 107 | 108 | func testPreconditionCorrectMessage() { 109 | expectPrecondition("Zero division") { 110 | dividePrecondition(1, by: 0) 111 | } 112 | } 113 | 114 | 115 | // preconditionFailure tests 116 | 117 | func testPreconditionFailureNotCalled() { 118 | expectPreconditionFailure("Zero division") { 119 | dividePreconditionFailure(1, by: 1) 120 | } 121 | } 122 | 123 | func testPreconditionFailureNoMessage() { 124 | expectPreconditionFailure() { 125 | dividePreconditionFailure(1, by: 0) 126 | } 127 | } 128 | 129 | func testPreconditionFailureErrorIncorrectMessage() { 130 | expectPreconditionFailure("Invalid") { 131 | dividePreconditionFailure(1, by: 0) 132 | } 133 | } 134 | 135 | func testPreconditionFailureCorrectMessage() { 136 | expectPreconditionFailure("Zero division") { 137 | dividePreconditionFailure(1, by: 0) 138 | } 139 | } 140 | 141 | // fatalError tests 142 | 143 | func testFatalErrorNotCalled() { 144 | expectFatalError("Zero division!") { 145 | divideFatalError(1, by: 1) 146 | } 147 | } 148 | 149 | func testFatalErrorNoMessage() { 150 | expectFatalError() { 151 | divideFatalError(1, by: 0) 152 | } 153 | } 154 | 155 | func testFatalErrorIncorrectMessage() { 156 | expectFatalError("Invalid") { 157 | divideFatalError(1, by: 0) 158 | } 159 | } 160 | 161 | func testFatalCorrectMessage() { 162 | expectFatalError("Zero division") { 163 | divideFatalError(1, by: 0) 164 | } 165 | } 166 | } 167 | -------------------------------------------------------------------------------- /AssertionsTests/XCTestCase+ProgrammerAssertions.swift: -------------------------------------------------------------------------------- 1 | // 2 | // XCTestCase+ProgrammerAssertions.swift 3 | // Assertions 4 | // 5 | // Created by Mohamed Afifi on 12/20/15. 6 | // Copyright © 2015 mohamede1945. All rights reserved. 7 | // 8 | 9 | /// ### IMPORTANT HOW TO USE ### 10 | /// 1. Drop `ProgrammerAssertions.swift` to the target of your app or framework under test. Just besides your source code. 11 | /// 2. Drop `XCTestCase+ProgrammerAssertions.swift` to your test target. Just besides your test cases. 12 | /// 3. Use `assert`, `assertionFailure`, `precondition`, `preconditionFailure` and `fatalError` normally as you always do. 13 | /// 4. Unit test them with the new methods `expectAssert`, `expectAssertionFailure`, `expectPrecondition`, `expectPreconditionFailure` and `expectFatalError`. 14 | /// 15 | /// This file is the unit test assertions. 16 | /// For a complete project example see 17 | 18 | import Foundation 19 | import XCTest 20 | @testable import Assertions 21 | 22 | private let noReturnFailureWaitTime = 0.1 23 | 24 | public extension XCTestCase { 25 | 26 | /** 27 | Expects an `assert` to be called with a false condition. 28 | If `assert` not called or the assert's condition is true, the test case will fail. 29 | 30 | - parameter expectedMessage: The expected message to be asserted to the one passed to the `assert`. If nil, then ignored. 31 | - parameter file: The file name that called the method. 32 | - parameter line: The line number that called the method. 33 | - parameter testCase: The test case to be executed that expected to fire the assertion method. 34 | */ 35 | public func expectAssert( 36 | expectedMessage: String? = nil, 37 | file: StaticString = #file, 38 | line: UInt = #line, 39 | testCase: () -> Void 40 | ) { 41 | 42 | expectAssertionReturnFunction("assert", file: file, line: line, function: { (caller) -> () in 43 | 44 | Assertions.assertClosure = { condition, message, _, _ in 45 | caller(condition, message) 46 | } 47 | 48 | }, expectedMessage: expectedMessage, testCase: testCase) { () -> () in 49 | Assertions.assertClosure = Assertions.swiftAssertClosure 50 | } 51 | } 52 | 53 | /** 54 | Expects an `assertionFailure` to be called. 55 | If `assertionFailure` not called, the test case will fail. 56 | 57 | - parameter expectedMessage: The expected message to be asserted to the one passed to the `assertionFailure`. If nil, then ignored. 58 | - parameter file: The file name that called the method. 59 | - parameter line: The line number that called the method. 60 | - parameter testCase: The test case to be executed that expected to fire the assertion method. 61 | */ 62 | public func expectAssertionFailure( 63 | expectedMessage: String? = nil, 64 | file: StaticString = #file, 65 | line: UInt = #line, 66 | testCase: () -> Void 67 | ) { 68 | 69 | expectAssertionReturnFunction("assertionFailure", file: file, line: line, function: { (caller) -> () in 70 | 71 | Assertions.assertionFailureClosure = { message, _, _ in 72 | caller(false, message) 73 | } 74 | 75 | }, expectedMessage: expectedMessage, testCase: testCase) { () -> () in 76 | Assertions.assertionFailureClosure = Assertions.swiftAssertionFailureClosure 77 | } 78 | } 79 | 80 | /** 81 | Expects an `precondition` to be called with a false condition. 82 | If `precondition` not called or the precondition's condition is true, the test case will fail. 83 | 84 | - parameter expectedMessage: The expected message to be asserted to the one passed to the `precondition`. If nil, then ignored. 85 | - parameter file: The file name that called the method. 86 | - parameter line: The line number that called the method. 87 | - parameter testCase: The test case to be executed that expected to fire the assertion method. 88 | */ 89 | public func expectPrecondition( 90 | expectedMessage: String? = nil, 91 | file: StaticString = #file, 92 | line: UInt = #line, 93 | testCase: () -> Void 94 | ) { 95 | 96 | expectAssertionReturnFunction("precondition", file: file, line: line, function: { (caller) -> () in 97 | 98 | Assertions.preconditionClosure = { condition, message, _, _ in 99 | caller(condition, message) 100 | } 101 | 102 | }, expectedMessage: expectedMessage, testCase: testCase) { () -> () in 103 | Assertions.preconditionClosure = Assertions.swiftPreconditionClosure 104 | } 105 | } 106 | 107 | /** 108 | Expects an `preconditionFailure` to be called. 109 | If `preconditionFailure` not called, the test case will fail. 110 | 111 | - parameter expectedMessage: The expected message to be asserted to the one passed to the `preconditionFailure`. If nil, then ignored. 112 | - parameter file: The file name that called the method. 113 | - parameter line: The line number that called the method. 114 | - parameter testCase: The test case to be executed that expected to fire the assertion method. 115 | */ 116 | public func expectPreconditionFailure( 117 | expectedMessage: String? = nil, 118 | file: StaticString = #file, 119 | line: UInt = #line, 120 | testCase: () -> Void 121 | ) { 122 | 123 | expectAssertionNoReturnFunction("preconditionFailure", file: file, line: line, function: { (caller) -> () in 124 | 125 | Assertions.preconditionFailureClosure = { message, _, _ in 126 | caller(message) 127 | } 128 | 129 | }, expectedMessage: expectedMessage, testCase: testCase) { () -> () in 130 | Assertions.preconditionFailureClosure = Assertions.swiftPreconditionFailureClosure 131 | } 132 | } 133 | 134 | /** 135 | Expects an `fatalError` to be called. 136 | If `fatalError` not called, the test case will fail. 137 | 138 | - parameter expectedMessage: The expected message to be asserted to the one passed to the `fatalError`. If nil, then ignored. 139 | - parameter file: The file name that called the method. 140 | - parameter line: The line number that called the method. 141 | - parameter testCase: The test case to be executed that expected to fire the assertion method. 142 | */ 143 | public func expectFatalError( 144 | expectedMessage: String? = nil, 145 | file: StaticString = #file, 146 | line: UInt = #line, 147 | testCase: () -> Void) { 148 | 149 | expectAssertionNoReturnFunction("fatalError", file: file, line: line, function: { (caller) -> () in 150 | 151 | Assertions.fatalErrorClosure = { message, _, _ in 152 | caller(message) 153 | } 154 | 155 | }, expectedMessage: expectedMessage, testCase: testCase) { () -> () in 156 | Assertions.fatalErrorClosure = Assertions.swiftFatalErrorClosure 157 | } 158 | } 159 | 160 | // MARK:- Private Methods 161 | 162 | private func expectAssertionReturnFunction( 163 | functionName: String, 164 | file: StaticString, 165 | line: UInt, 166 | function: (caller: (Bool, String) -> Void) -> Void, 167 | expectedMessage: String? = nil, 168 | testCase: () -> Void, 169 | cleanUp: () -> () 170 | ) { 171 | 172 | let expectation = expectationWithDescription(functionName + "-Expectation") 173 | var assertion: (condition: Bool, message: String)? = nil 174 | 175 | function { (condition, message) -> Void in 176 | assertion = (condition, message) 177 | expectation.fulfill() 178 | } 179 | 180 | // perform on the same thread since it will return 181 | testCase() 182 | 183 | waitForExpectationsWithTimeout(0) { _ in 184 | 185 | defer { 186 | // clean up 187 | cleanUp() 188 | } 189 | 190 | guard let assertion = assertion else { 191 | XCTFail(functionName + " is expected to be called.", file: file, line: line) 192 | return 193 | } 194 | 195 | XCTAssertFalse(assertion.condition, functionName + " condition expected to be false", file: file, line: line) 196 | 197 | if let expectedMessage = expectedMessage { 198 | // assert only if not nil 199 | XCTAssertEqual(assertion.message, expectedMessage, functionName + " called with incorrect message.", file: file, line: line) 200 | } 201 | } 202 | } 203 | 204 | private func expectAssertionNoReturnFunction( 205 | functionName: String, 206 | file: StaticString, 207 | line: UInt, 208 | function: (caller: (String) -> Void) -> Void, 209 | expectedMessage: String? = nil, 210 | testCase: () -> Void, 211 | cleanUp: () -> () 212 | ) { 213 | 214 | let expectation = expectationWithDescription(functionName + "-Expectation") 215 | var assertionMessage: String? = nil 216 | 217 | function { (message) -> Void in 218 | assertionMessage = message 219 | expectation.fulfill() 220 | } 221 | 222 | // act, perform on separate thead because a call to function runs forever 223 | dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0), testCase) 224 | 225 | waitForExpectationsWithTimeout(noReturnFailureWaitTime) { _ in 226 | 227 | defer { 228 | // clean up 229 | cleanUp() 230 | } 231 | 232 | guard let assertionMessage = assertionMessage else { 233 | XCTFail(functionName + " is expected to be called.", file: file, line: line) 234 | return 235 | } 236 | 237 | if let expectedMessage = expectedMessage { 238 | // assert only if not nil 239 | XCTAssertEqual(assertionMessage, expectedMessage, functionName + " called with incorrect message.", file: file, line: line) 240 | } 241 | } 242 | } 243 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Mohamed Afifi 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AssertionsTestingExample 2 | 3 | ## This library is deprecated. You can use https://github.com/mattgallagher/CwlPreconditionTesting instead. 4 | 5 | Finally, you can achieve 100% coverage. Previously, you couldn't because you cannot test `assert`, `assertionFailure`, `precondition`, `preconditionFailure` and `fatalError`. But now with every easy steps you can test them. 6 | 7 | This is an example app to show you how to do it. When you test `command + U` the app. You will find many test cases fail. This is intentional, to show that `expectAssert` for example fails the test case with a proper error message when the assert function is not called. 8 | 9 | When you go to the coverage, you finally can see that we have **100%** coverage. 10 | 11 | ### HOW TO USE ### 12 | 1. Drop `ProgrammerAssertions.swift` to the target of your app or framework under test. Just besides your source code. 13 | 2. Drop `XCTestCase+ProgrammerAssertions.swift` to your test target. Just besides your test cases. 14 | 3. Use `assert`, `assertionFailure`, `precondition`, `preconditionFailure` and `fatalError` normally as you always do. 15 | 4. Unit test them with the new methods `expectAssert`, `expectAssertionFailure`, `expectPrecondition`, `expectPreconditionFailure` and `expectFatalError`. 16 | 17 | For example: 18 | If you have a function that does a division like the following: 19 | 20 | ```swift 21 | func divideFatalError(x: Float, by y: Float) -> Float { 22 | 23 | guard y != 0 else { 24 | fatalError("Zero division") 25 | } 26 | 27 | return x / y 28 | } 29 | ``` 30 | 31 | You can test the 0 division with the following code. 32 | ```swift 33 | func testFatalCorrectMessage() { 34 | expectFatalError("Zero division") { 35 | divideFatalError(1, by: 0) 36 | } 37 | } 38 | ``` 39 | 40 | Or if you don't want to test the message, you simply do. 41 | ```swift 42 | func testFatalErrorNoMessage() { 43 | expectFatalError() { 44 | divideFatalError(1, by: 0) 45 | } 46 | } 47 | ``` 48 | 49 | 50 | ## Attributions 51 | 52 | Thanks to [nschum](http://stackoverflow.com/users/168939/nschum) and [Ken Ko](http://stackoverflow.com/users/3406736/ken-ko) they have the credit for creating these reusable files. I just added very few stuff. 53 | 54 | 55 | ## Author 56 | 57 | Mohamed Afifi, mohamede1945@gmail.com 58 | 59 | ## License 60 | 61 | AssertionsTestingExample is available under the MIT license. See the LICENSE file for more info. 62 | --------------------------------------------------------------------------------