Move Shim's XCTest helpers to their own file

Summary: title

Reviewed By: Nekitosss

Differential Revision: D48787833

fbshipit-source-id: c1e602b5ce0ab3f7f0831d3ffa2f025560b438ba
This commit is contained in:
Johnny Souza 2023-08-30 02:33:41 -07:00 коммит произвёл Facebook GitHub Bot
Родитель a61915828d
Коммит dc14728323
4 изменённых файлов: 80 добавлений и 42 удалений

Просмотреть файл

@ -11,6 +11,10 @@
7197B82D2A9E39CC00234737 /* XTSwizzle.h in Headers */ = {isa = PBXBuildFile; fileRef = 7197B82A2A9E39CC00234737 /* XTSwizzle.h */; };
7197B82E2A9E39CC00234737 /* XTSwizzle.m in Sources */ = {isa = PBXBuildFile; fileRef = 7197B82B2A9E39CC00234737 /* XTSwizzle.m */; };
7197B82F2A9E39CC00234737 /* XTSwizzle.m in Sources */ = {isa = PBXBuildFile; fileRef = 7197B82B2A9E39CC00234737 /* XTSwizzle.m */; };
7197B8382A9E3FD500234737 /* XCTestCaseHelpers.h in Headers */ = {isa = PBXBuildFile; fileRef = 7197B8362A9E3FD500234737 /* XCTestCaseHelpers.h */; };
7197B8392A9E3FD500234737 /* XCTestCaseHelpers.h in Headers */ = {isa = PBXBuildFile; fileRef = 7197B8362A9E3FD500234737 /* XCTestCaseHelpers.h */; };
7197B83A2A9E3FD500234737 /* XCTestCaseHelpers.m in Sources */ = {isa = PBXBuildFile; fileRef = 7197B8372A9E3FD500234737 /* XCTestCaseHelpers.m */; };
7197B83B2A9E3FD500234737 /* XCTestCaseHelpers.m in Sources */ = {isa = PBXBuildFile; fileRef = 7197B8372A9E3FD500234737 /* XCTestCaseHelpers.m */; };
71B9E0D9268C61B800D40A91 /* TestCrashShim.m in Sources */ = {isa = PBXBuildFile; fileRef = EED62EE620D1224C006E86E5 /* TestCrashShim.m */; };
EED62EDE20D12217006E86E5 /* XCTestPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = EED62EDB20D12217006E86E5 /* XCTestPrivate.h */; };
EED62EDF20D12217006E86E5 /* XCTestPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = EED62EDB20D12217006E86E5 /* XCTestPrivate.h */; };
@ -36,6 +40,8 @@
/* Begin PBXFileReference section */
7197B82A2A9E39CC00234737 /* XTSwizzle.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XTSwizzle.h; sourceTree = "<group>"; };
7197B82B2A9E39CC00234737 /* XTSwizzle.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = XTSwizzle.m; sourceTree = "<group>"; };
7197B8362A9E3FD500234737 /* XCTestCaseHelpers.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XCTestCaseHelpers.h; sourceTree = "<group>"; };
7197B8372A9E3FD500234737 /* XCTestCaseHelpers.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = XCTestCaseHelpers.m; sourceTree = "<group>"; };
AA017F411BD7776B00F45E9D /* libShimulator.dylib */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.dylib"; includeInIndex = 0; path = libShimulator.dylib; sourceTree = BUILT_PRODUCTS_DIR; };
AA56EAE21EEF08720062C2BC /* libMaculator.dylib */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.dylib"; includeInIndex = 0; path = libMaculator.dylib; sourceTree = BUILT_PRODUCTS_DIR; };
EED62ED820D12209006E86E5 /* Maculator.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Maculator.xcconfig; sourceTree = "<group>"; };
@ -110,6 +116,8 @@
EED62EDB20D12217006E86E5 /* XCTestPrivate.h */,
7197B82A2A9E39CC00234737 /* XTSwizzle.h */,
7197B82B2A9E39CC00234737 /* XTSwizzle.m */,
7197B8362A9E3FD500234737 /* XCTestCaseHelpers.h */,
7197B8372A9E3FD500234737 /* XCTestCaseHelpers.m */,
);
path = Tools;
sourceTree = "<group>";
@ -151,6 +159,7 @@
EED62EF120D12432006E86E5 /* FBDebugLog.h in Headers */,
EED62EE220D12242006E86E5 /* FBXCTestConstants.h in Headers */,
7197B82C2A9E39CC00234737 /* XTSwizzle.h in Headers */,
7197B8382A9E3FD500234737 /* XCTestCaseHelpers.h in Headers */,
EED62EDE20D12217006E86E5 /* XCTestPrivate.h in Headers */,
EED62EEF20D12432006E86E5 /* FBRuntimeTools.h in Headers */,
);
@ -164,6 +173,7 @@
EED62EF220D12432006E86E5 /* FBDebugLog.h in Headers */,
EED62EE320D12242006E86E5 /* FBXCTestConstants.h in Headers */,
7197B82D2A9E39CC00234737 /* XTSwizzle.h in Headers */,
7197B8392A9E3FD500234737 /* XCTestCaseHelpers.h in Headers */,
EED62EDF20D12217006E86E5 /* XCTestPrivate.h in Headers */,
EED62EF020D12432006E86E5 /* FBRuntimeTools.h in Headers */,
);
@ -297,6 +307,7 @@
EED62EF320D12432006E86E5 /* FBDebugLog.m in Sources */,
EED62EE720D1224C006E86E5 /* TestCrashShim.m in Sources */,
EED62EED20D12432006E86E5 /* FBRuntimeTools.m in Sources */,
7197B83A2A9E3FD500234737 /* XCTestCaseHelpers.m in Sources */,
EED62EE420D12242006E86E5 /* XCTestReporterShim.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
@ -310,6 +321,7 @@
EED62EFA20D1243E006E86E5 /* FBXCTestMain.m in Sources */,
EED62EF420D12432006E86E5 /* FBDebugLog.m in Sources */,
71B9E0D9268C61B800D40A91 /* TestCrashShim.m in Sources */,
7197B83B2A9E3FD500234737 /* XCTestCaseHelpers.m in Sources */,
EED62EE520D12242006E86E5 /* XCTestReporterShim.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;

Просмотреть файл

@ -12,6 +12,7 @@
#import <objc/runtime.h>
#import "FBXCTestConstants.h"
#import "XCTestCaseHelpers.h"
#import "XCTestPrivate.h"
#import "XTSwizzle.h"
@ -29,48 +30,6 @@ static FILE *__stderr;
static NSMutableArray<NSDictionary<NSString *, id> *> *__testExceptions = nil;
static int __testSuiteDepth = 0;
static void parseXCTestCase(XCTestCase *testCase, NSString **classNameOut, NSString **methodNameOut, NSString **testKeyOut)
{
NSString *className = NSStringFromClass(testCase.class);
NSString *methodName;
if ([testCase respondsToSelector:@selector(languageAgnosticTestMethodName)]) {
methodName = [testCase languageAgnosticTestMethodName];
} else {
methodName = NSStringFromSelector([testCase.invocation selector]);
}
NSString *testKey = [NSString stringWithFormat:@"-[%@ %@]", className, methodName];
if (classNameOut) {
*classNameOut = className;
}
if (methodNameOut) {
*methodNameOut = methodName;
}
if (testKeyOut) {
*testKeyOut = testKey;
}
}
static NSString *parseXCTestSuiteKey(XCTestSuite *suite)
{
NSString *testKey = nil;
for (id test in suite.tests) {
if (![test isKindOfClass:NSClassFromString(@"XCTestCase")]) {
return [suite name];
}
XCTestCase *testCase = test;
NSString *innerTestKey = nil;
parseXCTestCase(testCase, &innerTestKey, nil, nil);
if (!testKey) {
testKey = innerTestKey;
continue;
}
if (![innerTestKey isEqualToString:testKey]) {
return [suite name];
}
}
return testKey ?: [suite name];
}
NSDictionary<NSString *, id> *EventDictionaryWithNameAndContent(NSString *name, NSDictionary *content)
{
NSMutableDictionary<NSString *, id> *eventJSON = [NSMutableDictionary dictionaryWithDictionary:@{

Просмотреть файл

@ -0,0 +1,12 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
@class XCTestCase, XCTestSuite, NSString;
void parseXCTestCase(XCTestCase *testCase, NSString **classNameOut, NSString **methodNameOut, NSString **testKeyOut);
NSString *parseXCTestSuiteKey(XCTestSuite *suite);

Просмотреть файл

@ -0,0 +1,55 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import "XCTestCaseHelpers.h"
#import <Foundation/Foundation.h>
#import "XCTestPrivate.h"
void parseXCTestCase(XCTestCase *testCase, NSString **classNameOut, NSString **methodNameOut, NSString **testKeyOut)
{
NSString *className = NSStringFromClass(testCase.class);
NSString *methodName;
if ([testCase respondsToSelector:@selector(languageAgnosticTestMethodName)]) {
methodName = [testCase languageAgnosticTestMethodName];
} else {
methodName = NSStringFromSelector([testCase.invocation selector]);
}
NSString *testKey = [NSString stringWithFormat:@"-[%@ %@]", className, methodName];
if (classNameOut) {
*classNameOut = className;
}
if (methodNameOut) {
*methodNameOut = methodName;
}
if (testKeyOut) {
*testKeyOut = testKey;
}
}
NSString *parseXCTestSuiteKey(XCTestSuite *suite)
{
NSString *testKey = nil;
for (id test in suite.tests) {
if (![test isKindOfClass:NSClassFromString(@"XCTestCase")]) {
return [suite name];
}
XCTestCase *testCase = test;
NSString *innerTestKey = nil;
parseXCTestCase(testCase, &innerTestKey, nil, nil);
if (!testKey) {
testKey = innerTestKey;
continue;
}
if (![innerTestKey isEqualToString:testKey]) {
return [suite name];
}
}
return testKey ?: [suite name];
}