From df4f4cd1e50e7be6e4ea7fe3639c8986e1a8b0ff Mon Sep 17 00:00:00 2001 From: phineasla <63248715+phineasla@users.noreply.github.com> Date: Thu, 18 Apr 2024 00:25:17 +0700 Subject: [PATCH] Replace deprecated recordFailureWithDescription with recordIssue --- Expecta.xcodeproj/project.pbxproj | 77 ++++++++++++++--- .../xcschemes/Expecta-iOS.xcscheme | 22 ++--- .../xcshareddata/xcschemes/Expecta.xcscheme | 22 ++--- .../xcschemes/libExpecta.xcscheme | 22 ++--- Expecta/ExpectaSupport.m | 22 +++-- Tests/EXPFailTest.h | 15 +++- Tests/EXPFailTest.m | 83 +++++++++++++------ 7 files changed, 182 insertions(+), 81 deletions(-) diff --git a/Expecta.xcodeproj/project.pbxproj b/Expecta.xcodeproj/project.pbxproj index 2b4db0c..e632432 100644 --- a/Expecta.xcodeproj/project.pbxproj +++ b/Expecta.xcodeproj/project.pbxproj @@ -3,10 +3,14 @@ archiveVersion = 1; classes = { }; - objectVersion = 46; + objectVersion = 54; objects = { /* Begin PBXBuildFile section */ + 0E633CEF2BD0324D00346690 /* XCTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0E633CEE2BD0324D00346690 /* XCTest.framework */; }; + 0E633CF32BD0325500346690 /* XCTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0E633CF22BD0325500346690 /* XCTest.framework */; platformFilter = ios; }; + 0E633CF62BD03D2C00346690 /* XCTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0E633CEE2BD0324D00346690 /* XCTest.framework */; }; + 0E633CF72BD03D3500346690 /* XCTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0E633CF22BD0325500346690 /* XCTest.framework */; platformFilter = ios; }; 1137E3F6805E8DD7599ADCA8 /* EXPMatchers+beSupersetOfTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 54C6B1F5180CAD5100E13146 /* EXPMatchers+beSupersetOfTest.m */; }; 1137E875D17A9C593D6C71C3 /* EXPMatchers+beSupersetOfTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 54C6B1F5180CAD5100E13146 /* EXPMatchers+beSupersetOfTest.m */; }; 2546A95C16629D500078E044 /* EXPMatchers+raiseWithReason.h in Headers */ = {isa = PBXBuildFile; fileRef = 2546A95A16629D4F0078E044 /* EXPMatchers+raiseWithReason.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -490,6 +494,8 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + 0E633CEE2BD0324D00346690 /* XCTest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XCTest.framework; path = Platforms/MacOSX.platform/Developer/Library/Frameworks/XCTest.framework; sourceTree = DEVELOPER_DIR; }; + 0E633CF22BD0325500346690 /* XCTest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XCTest.framework; path = Platforms/iPhoneOS.platform/Developer/Library/Frameworks/XCTest.framework; sourceTree = DEVELOPER_DIR; }; 2546A95A16629D4F0078E044 /* EXPMatchers+raiseWithReason.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "EXPMatchers+raiseWithReason.h"; sourceTree = ""; }; 2546A95B16629D4F0078E044 /* EXPMatchers+raiseWithReason.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "EXPMatchers+raiseWithReason.m"; sourceTree = ""; }; 2546A96116629DF70078E044 /* EXPMatchers+raiseWithReasonTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "EXPMatchers+raiseWithReasonTest.m"; sourceTree = ""; }; @@ -637,6 +643,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 0E633CF32BD0325500346690 /* XCTest.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -644,6 +651,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 0E633CEF2BD0324D00346690 /* XCTest.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -659,6 +667,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 0E633CF72BD03D3500346690 /* XCTest.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -674,12 +683,22 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 0E633CF62BD03D2C00346690 /* XCTest.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 0E633CED2BD0324D00346690 /* Frameworks */ = { + isa = PBXGroup; + children = ( + 0E633CF22BD0325500346690 /* XCTest.framework */, + 0E633CEE2BD0324D00346690 /* XCTest.framework */, + ); + name = Frameworks; + sourceTree = ""; + }; 908379E41A8B9EE1009844DA /* Support */ = { isa = PBXGroup; children = ( @@ -694,6 +713,7 @@ E9ACDF3C13B2DDB00010F4D7 /* Expecta */, E9ACDF7213B2DEB70010F4D7 /* Tests */, E9ACDF0D13B2DD520010F4D7 /* Products */, + 0E633CED2BD0324D00346690 /* Frameworks */, ); sourceTree = ""; }; @@ -1232,6 +1252,7 @@ developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( + English, en, ); mainGroup = E9ACDF0113B2DD520010F4D7; @@ -1737,7 +1758,11 @@ GCC_PREFIX_HEADER = "$(SRCROOT)/Expecta/Expecta-Prefix.pch"; INFOPLIST_FILE = "Tests/Support/Test-Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); OTHER_LDFLAGS = ( "$(inherited)", "-framework", @@ -1758,7 +1783,11 @@ GCC_PREFIX_HEADER = "$(SRCROOT)/Expecta/Expecta-Prefix.pch"; INFOPLIST_FILE = "Tests/Support/Test-Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); OTHER_LDFLAGS = ( "$(inherited)", "-framework", @@ -1779,7 +1808,11 @@ GCC_PREFIX_HEADER = "$(SRCROOT)/Expecta/Expecta-Prefix.pch"; INFOPLIST_FILE = "Tests/Support/Test-Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); OTHER_LDFLAGS = ( "$(inherited)", "-framework", @@ -1807,7 +1840,11 @@ INFOPLIST_FILE = "$(SRCROOT)/Expecta/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); PRODUCT_BUNDLE_IDENTIFIER = "com.raingrove.expecta.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = Expecta; SDKROOT = iphoneos; @@ -1830,7 +1867,11 @@ INFOPLIST_FILE = "$(SRCROOT)/Expecta/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); PRODUCT_BUNDLE_IDENTIFIER = "com.raingrove.expecta.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = Expecta; SDKROOT = iphoneos; @@ -1853,7 +1894,11 @@ INFOPLIST_FILE = "$(SRCROOT)/Expecta/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); PRODUCT_BUNDLE_IDENTIFIER = "com.raingrove.expecta.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = Expecta; SDKROOT = iphoneos; @@ -1876,7 +1921,11 @@ INFOPLIST_FILE = "$(SRCROOT)/Expecta/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + "@loader_path/Frameworks", + ); MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_BUNDLE_IDENTIFIER = "com.raingrove.expecta.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = Expecta; @@ -1899,7 +1948,11 @@ INFOPLIST_FILE = "$(SRCROOT)/Expecta/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + "@loader_path/Frameworks", + ); MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_BUNDLE_IDENTIFIER = "com.raingrove.expecta.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = Expecta; @@ -1922,7 +1975,11 @@ INFOPLIST_FILE = "$(SRCROOT)/Expecta/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + "@loader_path/Frameworks", + ); MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_BUNDLE_IDENTIFIER = "com.raingrove.expecta.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = Expecta; diff --git a/Expecta.xcodeproj/xcshareddata/xcschemes/Expecta-iOS.xcscheme b/Expecta.xcodeproj/xcshareddata/xcschemes/Expecta-iOS.xcscheme index 92f6b24..05bf086 100644 --- a/Expecta.xcodeproj/xcshareddata/xcschemes/Expecta-iOS.xcscheme +++ b/Expecta.xcodeproj/xcshareddata/xcschemes/Expecta-iOS.xcscheme @@ -27,6 +27,15 @@ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" shouldUseLaunchSchemeArgsEnv = "YES"> + + + + @@ -39,17 +48,6 @@ - - - - - - - - + + + + @@ -39,17 +48,6 @@ - - - - - - - - + + + + @@ -53,17 +62,6 @@ - - - - - - - - +#import @interface NSObject (ExpectaXCTestRecordFailure) // suppress warning - (void)recordFailureWithDescription:(NSString *)description inFile:(NSString *)filename atLine:(NSUInteger)lineNumber expected:(BOOL)expected; +- (void)recordIssue:(XCTIssue *)issue; @end @@ -107,11 +109,21 @@ void EXPFail(id testCase, int lineNumber, const char *fileName, NSString *messag NSString *reason = [NSString stringWithFormat:@"%s:%d %@", fileName, lineNumber, message]; NSException *exception = [NSException exceptionWithName:@"Expecta Error" reason:reason userInfo:nil]; - if(testCase && [testCase respondsToSelector:@selector(recordFailureWithDescription:inFile:atLine:expected:)]){ - [testCase recordFailureWithDescription:message - inFile:@(fileName) - atLine:lineNumber - expected:NO]; + if(testCase && [testCase respondsToSelector:@selector(recordIssue:)]) { + XCTSourceCodeLocation *location = [[XCTSourceCodeLocation alloc] initWithFilePath:@(fileName) lineNumber:lineNumber]; + XCTSourceCodeContext *context = [[XCTSourceCodeContext alloc] initWithLocation:location]; + XCTIssue *issue = [[XCTIssue alloc] initWithType:XCTIssueTypeAssertionFailure + compactDescription:message + detailedDescription:nil + sourceCodeContext:context + associatedError:nil + attachments:@[]]; + [testCase recordIssue:issue]; + } else if(testCase && [testCase respondsToSelector:@selector(recordFailureWithDescription:inFile:atLine:expected:)]){ + [testCase recordFailureWithDescription:message + inFile:@(fileName) + atLine:lineNumber + expected:NO]; } else { [exception raise]; } diff --git a/Tests/EXPFailTest.h b/Tests/EXPFailTest.h index 9b1f2d4..18b84d4 100644 --- a/Tests/EXPFailTest.h +++ b/Tests/EXPFailTest.h @@ -15,7 +15,7 @@ @end -// Test case class with failWithException: method +// Test case class with recordFailureWithDescription:inFile:atLine:expected: method @interface TestCaseClassWithRecordFailureMethod : TestCaseClassWithoutFailMethod { NSString *_description; NSString *_fileName; @@ -30,4 +30,15 @@ - (void)recordFailureWithDescription:(NSString *)description inFile:(NSString *)filename atLine:(NSUInteger)lineNumber expected:(BOOL)expected; -@end \ No newline at end of file +@end + +// Test case class with recordIssue: method +@interface TestCaseClassWithRecordIssueMethod : TestCaseClassWithoutFailMethod { + XCTIssue *_issue; +} + +@property (nonatomic, strong) XCTIssue *issue; + +- (void)recordIssue:(XCTIssue *)issue; + +@end diff --git a/Tests/EXPFailTest.m b/Tests/EXPFailTest.m index 1bb45e4..770a427 100644 --- a/Tests/EXPFailTest.m +++ b/Tests/EXPFailTest.m @@ -2,34 +2,38 @@ #import "EXPFailTest.h" @interface EXPExpectFailTest : XCTestCase -@property (nonatomic, copy) NSString *fileName; -@property (nonatomic, copy) NSString *errorDescription; +@property (nonatomic, strong) XCTIssue *issue; @property (assign) NSUInteger lineNumber; @end @implementation EXPExpectFailTest // This test is dependent on the LOC with the failure on -static NSInteger EXPFailTestLine = 28; +static NSInteger EXPFailTestLine = 25; -- (void)recordFailureWithDescription:(NSString *)description inFile:(NSString *)filePath atLine:(NSUInteger)lineNumber expected:(BOOL)expected +- (void) recordIssue:(XCTIssue *)issue { - if (lineNumber != EXPFailTestLine) { - [super recordFailureWithDescription:description inFile:filePath atLine:lineNumber expected:expected]; - } else { - self.fileName = filePath; - self.lineNumber = lineNumber; - self.errorDescription = description; - } + if (issue.sourceCodeContext.location.lineNumber != EXPFailTestLine) { + [super recordIssue:issue]; + } else { + self.issue = issue; + } } - (void)test_ExpectFailToFail { - failure(@"Expect Fail to Fail"); - - assertEqualObjects(self.errorDescription, @"Expect Fail to Fail"); - assertTrue([self.fileName hasSuffix:@"EXPFailTest.m"]); - assertEqualObjects(@(self.lineNumber), @(EXPFailTestLine)); + failure(@"Expect Fail to Fail"); + + assertEquals(self.issue.type, XCTIssueTypeAssertionFailure); + assertEqualObjects(self.issue.compactDescription, @"Expect Fail to Fail"); + assertNil(self.issue.detailedDescription); + assertNil(self.issue.detailedDescription); + assertNil(self.issue.associatedError); + assertEquals(self.issue.attachments.count, 0); + XCTSourceCodeContext *context = self.issue.sourceCodeContext; + XCTSourceCodeLocation *location = context.location; + assertTrue([location.fileURL.path hasSuffix:@"EXPFailTest.m"]); + assertEquals(location.lineNumber, EXPFailTestLine); } @end @@ -77,6 +81,18 @@ - (void)recordFailureWithDescription:(NSString *)description inFile:(NSString *) self.expected = expected; } +@end + +@implementation TestCaseClassWithRecordIssueMethod + +@synthesize + issue=_issue; + +- (void)recordIssue:(XCTIssue *)issue +{ + self.issue = issue; +} + @end @interface EXPFailTest : XCTestCase @@ -98,16 +114,33 @@ - (void)test_EXPFailWithTestCaseClassThatDoesNotHaveFailureMethod { - (void)test_EXPFailWithTestCaseClassThatHasFailureMethod { // it calls recordFailureWithDescription:inFile:atLine:expected: method - TestCaseClassWithRecordFailureMethod *testCase = [TestCaseClassWithRecordFailureMethod new]; - assertNil(testCase.description); - assertNil(testCase.fileName); - [testCase fail]; - assertEqualObjects(testCase.description, @"epic fail"); - assertEqualObjects(testCase.fileName, @"test.m"); - assertEqualObjects(@(testCase.lineNumber), @777); - assertEquals(testCase.expected, NO); - [testCase release]; + TestCaseClassWithRecordFailureMethod *testCase = [TestCaseClassWithRecordFailureMethod new]; + assertNil(testCase.description); + assertNil(testCase.fileName); + [testCase fail]; + assertEqualObjects(testCase.description, @"epic fail"); + assertEqualObjects(testCase.fileName, @"test.m"); + assertEqualObjects(@(testCase.lineNumber), @777); + assertEquals(testCase.expected, NO); + [testCase release]; } +- (void)test_EXPFailWithTestCaseClassThatHasRecordIssueMethod { + // it calls recordIssue: + TestCaseClassWithRecordIssueMethod *testCase = [TestCaseClassWithRecordIssueMethod new]; + assertNil(testCase.issue); + [testCase fail]; + XCTIssue* issue = testCase.issue; + assertEquals(issue.type, XCTIssueTypeAssertionFailure); + assertEqualObjects(issue.compactDescription, @"epic fail"); + assertNil(issue.detailedDescription); + assertNil(issue.associatedError); + assertEquals(issue.attachments.count, 0); + XCTSourceCodeContext *context = issue.sourceCodeContext; + XCTSourceCodeLocation *location = context.location; + assertTrue([location.fileURL.path hasSuffix:@"test.m"]); + assertEquals(location.lineNumber, 777); + [testCase release]; +} @end