Force swift module prefix in test identifiers

Summary:
Swift tests' names used to be reported with their Swift module prefix: e.g. `MyModule.MyClass/test1`

However new protocols drop the module prefix in Xcode 14.3 when `ubiquitous test identifiers` IDE Capability is specified. Module prefix is completely gone in Xcode 15.0. (affecting only App and UI tests)

These changes reintroduce the module prefix.

Reviewed By: Nekitosss

Differential Revision: D48787832

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

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

@ -8,12 +8,15 @@
#import "FBXCTestMain.h"
#import <dlfcn.h>
#import <objc/message.h>
#import <objc/runtime.h>
#import "FBDebugLog.h"
#import "FBRuntimeTools.h"
#import "FBXCTestConstants.h"
#import "XCTestCaseHelpers.h"
#import "XCTestPrivate.h"
#import "XTSwizzle.h"
#include "TargetConditionals.h"
@ -96,11 +99,32 @@ void FBDeployBlockWhenAppLoads(void(^mainBlock)()) {
}];
}
/// Construct an XCTTestIdentifier using the same logic used to list the tests.
/// The identifier will contain the swift module prefix for tests written in swift,
/// as they used to in Xcode versions prior to 15.0
static id XCTestCase__xctTestIdentifier(id self, SEL sel)
{
NSString *classNameOut = nil;
NSString *methodNameOut = nil;
NSString *testKeyOut = nil;
parseXCTestCase(self, &classNameOut, &methodNameOut, &testKeyOut);
Class XCTTestIdentifier_class = objc_lookUpClass("XCTTestIdentifier");
return [[XCTTestIdentifier_class alloc] initWithStringRepresentation:[NSString stringWithFormat:@"%@/%@", classNameOut, methodNameOut] preserveModulePrefix:YES];
}
BOOL FBXCTestMain()
{
if (!FBLoadXCTestIfNeeded()) {
exit(TestShimExitCodeXCTestFailedLoading);
}
XTSwizzleSelectorForFunction(
objc_getClass("XCTestCase"),
@selector(_xctTestIdentifier),
(IMP)XCTestCase__xctTestIdentifier
);
NSString *configurationPath = NSProcessInfo.processInfo.environment[@"XCTestConfigurationFilePath"];
if (!configurationPath) {
NSLog(@"Failed to load XCTest as XCTestConfigurationFilePath environment variable is empty");

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

@ -185,6 +185,54 @@ struct __va_list_tag {
- (instancetype)initWithSelector:(SEL)arg1;
- (instancetype)initWithInvocation:(id)arg1;
- (instancetype)init;
- (id)_xctTestIdentifier;
@end
@interface XCTTestIdentifier : NSObject <NSCopying, NSSecureCoding>
{
}
+ (_Bool)supportsSecureCoding;
+ (id)allocWithZone:(struct _NSZone *)arg1;
+ (id)bundleIdentifier;
+ (id)identifierForClass:(Class)arg1;
+ (id)leafIdentifierWithComponents:(id)arg1;
+ (id)containerIdentifierWithComponents:(id)arg1;
+ (id)containerIdentifierWithComponent:(id)arg1;
- (Class)classForCoder;
- (void)encodeWithCoder:(id)arg1;
- (id)initWithCoder:(id)arg1;
@property(readonly) unsigned long long options;
- (id)componentAtIndex:(unsigned long long)arg1;
@property(readonly) unsigned long long componentCount;
@property(readonly) NSArray *components;
- (id)initWithComponents:(id)arg1 options:(unsigned long long)arg2;
- (id)initWithStringRepresentation:(id)arg1 preserveModulePrefix:(_Bool)arg2;
- (id)initWithStringRepresentation:(id)arg1;
- (id)initWithClassName:(id)arg1;
- (id)initWithClassName:(id)arg1 methodName:(id)arg2;
- (id)initWithClassAndMethodComponents:(id)arg1;
- (id)initWithComponents:(id)arg1 isContainer:(_Bool)arg2;
- (id)copyWithZone:(struct _NSZone *)arg1;
@property(readonly) XCTTestIdentifier *swiftMethodCounterpart;
@property(readonly) XCTTestIdentifier *firstComponentIdentifier;
@property(readonly) XCTTestIdentifier *parentIdentifier;
- (id)_identifierString;
@property(readonly) NSString *identifierString;
@property(readonly) NSString *displayName;
@property(readonly) NSString *lastComponentDisplayName;
@property(readonly) NSString *lastComponent;
@property(readonly) NSString *firstComponent;
@property(readonly) _Bool representsBundle;
@property(readonly) _Bool isLeaf;
@property(readonly) _Bool isContainer;
- (unsigned long long)hash;
- (_Bool)isEqual:(id)arg1;
- (id)debugDescription;
- (id)description;
@property(readonly) _Bool isSwiftMethod;
@property(readonly) _Bool usesClassAndMethodSemantics;
@end