Skip to content

Commit

Permalink
fix: SentryUIViewControllerSwizzlingTests (#3089)
Browse files Browse the repository at this point in the history
Fixed SentryUIViewControllerSwizzlingTests because it broke with latest swift/xcode updates
  • Loading branch information
brustolin authored Jun 7, 2023
1 parent 31ac438 commit 60dd0f5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
24 changes: 22 additions & 2 deletions Sources/Sentry/SentryNSProcessInfoWrapper.mm
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
#import "SentryNSProcessInfoWrapper.h"

@implementation SentryNSProcessInfoWrapper
@implementation SentryNSProcessInfoWrapper {
#if TEST
NSString *_executablePath;
}
- (void)setProcessPath:(NSString *)path
{
_executablePath = path;
}
# define EXECUTABLE_PATH _executablePath;

- (instancetype)init
{
self = [super init];
_executablePath = NSBundle.mainBundle.bundlePath;
return self;
}

#else
}
# define EXECUTABLE_PATH NSBundle.mainBundle.executablePath;
#endif

+ (SentryNSProcessInfoWrapper *)shared
{
Expand All @@ -17,7 +37,7 @@ - (NSString *)processDirectoryPath

- (NSString *)processPath
{
return NSBundle.mainBundle.executablePath;
return EXECUTABLE_PATH;
}

- (NSUInteger)processorCount
Expand Down
4 changes: 4 additions & 0 deletions Sources/Sentry/include/SentryNSProcessInfoWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ NS_ASSUME_NONNULL_BEGIN
@property (nullable, nonatomic, readonly) NSString *processPath;
@property (readonly) NSUInteger processorCount;

#if TEST
- (void)setProcessPath:(NSString *)path;
#endif

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ class SentryUIViewControllerSwizzlingTests: XCTestCase {
}

func testViewControllerWithLoadView_TransactionBoundToScope() {
let d = class_getImageName(type(of: self))!
fixture.processInfoWrapper.setProcessPath(String(cString: d))

fixture.sut.start()
let controller = ViewWithLoadViewController()

Expand Down Expand Up @@ -328,6 +331,7 @@ class TestSubClassFinder: SentrySubClassFinder {
var invocations = Invocations<(imageName: String, block: (AnyClass) -> Void)>()
override func actOnSubclassesOfViewController(inImage imageName: String, block: @escaping (AnyClass) -> Void) {
invocations.record((imageName, block))
super.actOnSubclassesOfViewController(inImage: imageName, block: block)
}
}

Expand Down

0 comments on commit 60dd0f5

Please sign in to comment.