Skip to content

Commit f563548

Browse files
committed
Fix duplicate test
1 parent 04729f2 commit f563548

File tree

50 files changed

+319
-138
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+319
-138
lines changed

SentryTestUtils/Sources/TestClient.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import _SentryPrivate
22
import Foundation
3-
@_spi(Private) import Sentry
3+
@_spi(Private) @testable import Sentry
44

55
public class TestClient: SentryClientInternal {
66
public override init?(options: NSObject) {
77
super.init(
88
options: options,
99
transportAdapter: TestTransportAdapter(transports: [TestTransport()], options: options as! Options),
1010
fileManager: try! TestFileManager(
11-
options: options.toOptions(),
11+
options: options as? Options,
1212
dateProvider: TestCurrentDateProvider(),
1313
dispatchQueueWrapper: TestSentryDispatchQueueWrapper()
1414
),

SentryTestUtils/Sources/TestFileManager.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ import Foundation
77
var readTimestampLastInForegroundInvocations: Int = 0
88
var storeTimestampLastInForegroundInvocations: Int = 0
99
var deleteTimestampLastInForegroundInvocations: Int = 0
10+
11+
public init(options: Options?, dateProvider: any SentryCurrentDateProvider, dispatchQueueWrapper: SentryDispatchQueueWrapper) throws {
12+
let helper = try SentryFileManagerHelper(options: options)
13+
super.init(helper: helper, dateProvider: dateProvider, dispatchQueueWrapper: dispatchQueueWrapper)
14+
}
1015

1116
@_spi(Private) public var storeEnvelopeInvocations = Invocations<SentryEnvelope>()
1217
public var storeEnvelopePath: String?

Sources/Sentry/Profiling/SentryProfilingSwiftHelpers.m

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,20 @@
167167
BOOL
168168
sentry_appHangsDisabled(void)
169169
{
170-
return [[[[SentrySDKInternal currentHub] getClient] options] isAppHangTrackingDisabled];
170+
SentryOptions *options = [[[SentrySDKInternal currentHub] getClient] options];
171+
if (options == nil) {
172+
return NO;
173+
}
174+
return [options isAppHangTrackingDisabled];
171175
}
172176
BOOL
173177
sentry_autoPerformanceTracingDisabled(void)
174178
{
175-
return ![[[[SentrySDKInternal currentHub] getClient] options] enableAutoPerformanceTracing];
179+
SentryOptions *options = [[[SentrySDKInternal currentHub] getClient] options];
180+
if (options == nil) {
181+
return YES;
182+
}
183+
return ![options enableAutoPerformanceTracing];
176184
}
177185
void
178186
sentry_startFramesTracker(void)

Sources/Sentry/SentryClient.m

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,8 @@ @interface SentryClientInternal ()
5858

5959
@implementation SentryClientInternal
6060

61-
- (_Nullable instancetype)initWithOptions:(SentryOptionsObjC *)internalOptions
61+
- (_Nullable instancetype)initWithOptions:(SentryOptions *)options
6262
{
63-
SentryOptions *options = [internalOptions toOptions];
6463
NSError *error;
6564
SentryFileManager *fileManager = [[SentryFileManager alloc]
6665
initWithOptions:options
@@ -82,9 +81,9 @@ - (_Nullable instancetype)initWithOptions:(SentryOptionsObjC *)internalOptions
8281
[[SentryTransportAdapter alloc] initWithTransports:transports options:options];
8382

8483
SentryDefaultThreadInspector *threadInspector =
85-
[[SentryDefaultThreadInspector alloc] initWithOptions:internalOptions];
84+
[[SentryDefaultThreadInspector alloc] initWithOptions:options];
8685

87-
return [self initWithOptions:internalOptions
86+
return [self initWithOptions:options
8887
transportAdapter:transportAdapter
8988
fileManager:fileManager
9089
threadInspector:threadInspector
@@ -94,7 +93,7 @@ - (_Nullable instancetype)initWithOptions:(SentryOptionsObjC *)internalOptions
9493
timezone:[NSCalendar autoupdatingCurrentCalendar].timeZone];
9594
}
9695

97-
- (instancetype)initWithOptions:(SentryOptionsObjC *)options
96+
- (instancetype)initWithOptions:(SentryOptions *)options
9897
transportAdapter:(SentryTransportAdapter *)transportAdapter
9998
fileManager:(SentryFileManager *)fileManager
10099
threadInspector:(SentryDefaultThreadInspector *)threadInspector
@@ -105,7 +104,7 @@ - (instancetype)initWithOptions:(SentryOptionsObjC *)options
105104
{
106105
if (self = [super init]) {
107106
_isEnabled = YES;
108-
self.optionsInternal = options;
107+
self.options = options;
109108
self.transportAdapter = transportAdapter;
110109
self.fileManager = fileManager;
111110
self.threadInspector = threadInspector;
@@ -117,17 +116,21 @@ - (instancetype)initWithOptions:(SentryOptionsObjC *)options
117116

118117
// The SDK stores the installationID in a file. The first call requires file IO. To avoid
119118
// executing this on the main thread, we cache the installationID async here.
120-
[SentryInstallation
121-
cacheIDAsyncWithCacheDirectoryPath:[options toOptions].cacheDirectoryPath];
119+
[SentryInstallation cacheIDAsyncWithCacheDirectoryPath:options.cacheDirectoryPath];
122120

123121
[fileManager deleteOldEnvelopeItems];
124122
}
125123
return self;
126124
}
127125

128-
- (SentryOptions *)options
126+
- (void)setOptionsInternal:(SentryOptions *)optionsInternal
129127
{
130-
return [self.optionsInternal toOptions];
128+
self.options = optionsInternal;
129+
}
130+
131+
- (NSObject *)getOptions
132+
{
133+
return self.options;
131134
}
132135

133136
- (SentryId *)captureMessage:(NSString *)message
@@ -384,7 +387,7 @@ - (nullable SentryTraceContext *)getTraceStateWithEvent:(SentryEvent *)event
384387

385388
SentryTracer *tracer = [SentryTracer getTracer:span];
386389
if (tracer != nil) {
387-
return [[SentryTraceContext alloc] initWithTracer:tracer scope:scope options:self.options];
390+
return [[SentryTraceContext alloc] initWithTracer:tracer scope:scope options:_options];
388391
}
389392

390393
if (event.error || event.exceptions.count > 0) {

Sources/Sentry/SentryCoreDataTrackingIntegration.m

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ - (BOOL)installWithOptions:(SentryOptions *)options
2121
}
2222

2323
self.tracker = [[SentryCoreDataTracker alloc]
24-
initWithThreadInspector:[[SentryDefaultThreadInspector alloc]
25-
initWithOptions:[options toInternal]]
24+
initWithThreadInspector:[[SentryDefaultThreadInspector alloc] initWithOptions:options]
2625
processInfoWrapper:[SentryDependencyContainer.sharedInstance processInfoWrapper]];
2726
[SentryCoreDataSwizzling.sharedInstance startWithTracker:self.tracker];
2827

Sources/Sentry/SentryDependencyContainerSwiftHelper.m

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,24 @@
44
#import "SentrySDK+Private.h"
55
#import "SentrySwift.h"
66

7+
@implementation SentryDefaultRedactOptions
8+
- (instancetype)initWithMaskAllText:(BOOL)maskAllText
9+
maskAllImages:(BOOL)maskAllImages
10+
maskedViewClasses:(NSArray<Class> *)maskedViewClasses
11+
unmaskedViewClasses:(NSArray<Class> *)unmaskedViewClasses
12+
{
13+
if (self = [super init]) {
14+
_maskAllText = maskAllText;
15+
_maskAllImages = maskAllImages;
16+
_maskedViewClasses = maskedViewClasses;
17+
_unmaskedViewClasses = unmaskedViewClasses;
18+
return self;
19+
}
20+
return nil;
21+
}
22+
23+
@end
24+
725
@implementation SentryDependencyContainerSwiftHelper
826

927
#if SENTRY_HAS_UIKIT
@@ -13,8 +31,70 @@ @implementation SentryDependencyContainerSwiftHelper
1331
return [SentryDependencyContainer.sharedInstance.application getWindows];
1432
}
1533

34+
+ (BOOL)fastViewRenderingEnabled:(SentryOptions *)options
35+
{
36+
return options.screenshot.enableFastViewRendering;
37+
}
38+
39+
+ (BOOL)viewRendererV2Enabled:(SentryOptions *)options
40+
{
41+
return options.screenshot.enableViewRendererV2;
42+
}
43+
44+
+ (SentryDefaultRedactOptions *)redactOptions:(SentryOptions *)options
45+
{
46+
return [[SentryDefaultRedactOptions alloc]
47+
initWithMaskAllText:options.screenshot.maskAllText
48+
maskAllImages:options.screenshot.maskAllImages
49+
maskedViewClasses:options.screenshot.maskedViewClasses
50+
unmaskedViewClasses:options.screenshot.unmaskedViewClasses];
51+
}
52+
1653
#endif // SENTRY_HAS_UIKIT
1754

55+
+ (NSString *)release:(SentryOptions *)options
56+
{
57+
return options.releaseName;
58+
}
59+
60+
+ (SentryLog *)beforeSendLog:(SentryLog *)log options:(SentryOptions *)options
61+
{
62+
if (options.beforeSendLog) {
63+
return options.beforeSendLog(log);
64+
}
65+
return log;
66+
}
67+
68+
+ (NSString *)environment:(SentryOptions *)options
69+
{
70+
return options.environment;
71+
}
72+
73+
+ (NSString *)cacheDirectoryPath:(SentryOptions *)options
74+
{
75+
return options.cacheDirectoryPath;
76+
}
77+
78+
+ (BOOL)enableLogs:(SentryOptions *)options
79+
{
80+
return options.enableLogs;
81+
}
82+
83+
+ (NSArray<NSString *> *)enabledFeatures:(SentryOptions *)options
84+
{
85+
return [SentryEnabledFeaturesBuilder getEnabledFeaturesWithOptions:options];
86+
}
87+
88+
+ (BOOL)sendDefaultPii:(SentryOptions *)options
89+
{
90+
return options.sendDefaultPii;
91+
}
92+
93+
+ (NSArray<NSString *> *)inAppIncludes:(SentryOptions *)options
94+
{
95+
return options.inAppIncludes;
96+
}
97+
1898
+ (SentryDispatchQueueWrapper *)dispatchQueueWrapper
1999
{
20100
return SentryDependencyContainer.sharedInstance.dispatchQueueWrapper;

Sources/Sentry/SentryFileManagerHelper.m

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#import "SentryEvent.h"
99
#import "SentryInternalDefines.h"
1010
#import "SentryLogC.h"
11+
#import "SentrySDK+Private.h"
1112
#import "SentrySerialization.h"
1213
#import "SentrySwift.h"
1314

@@ -101,11 +102,16 @@ @interface SentryFileManagerHelper ()
101102

102103
@implementation SentryFileManagerHelper
103104

104-
- (nullable instancetype)initWithOptions:(SentryOptionsObjC *_Nullable)optionsInternal
105-
error:(NSError **)error
105+
- (nullable instancetype)initWithPlaceholder:(NSObject *)objc
106+
error:(NSError *_Nullable *_Nullable)error
107+
{
108+
SentryOptions *options = [SentrySDKInternal options];
109+
return [self initWithOptions:options error:error];
110+
}
111+
112+
- (nullable instancetype)initWithOptions:(SentryOptions *_Nullable)options error:(NSError **)error
106113
{
107114
if (self = [super init]) {
108-
SentryOptions *options = [optionsInternal toOptions];
109115
[self createPathsWithOptions:options];
110116

111117
// Remove old cached events for versions before 6.0.0

Sources/Sentry/SentrySDKInternal.m

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,11 +220,10 @@ + (void)setStartTimestamp:(NSDate *)value
220220
startTimestamp = value;
221221
}
222222

223-
+ (void)startWithOptions:(SentryOptionsObjC *)internalOptions
223+
+ (void)startWithOptions:(SentryOptions *)options
224224
{
225225
// We save the options before checking for Xcode preview because
226226
// we will use this options in the preview
227-
SentryOptions *options = [internalOptions toOptions];
228227
startOption = options;
229228
if ([SentryDependencyContainer.sharedInstance.processInfoWrapper
230229
.environment[SENTRY_XCODE_PREVIEW_ENVIRONMENT_KEY] isEqualToString:@"1"]) {
@@ -255,8 +254,7 @@ + (void)startWithOptions:(SentryOptionsObjC *)internalOptions
255254
startInvocations++;
256255
startTimestamp = [SentryDependencyContainer.sharedInstance.dateProvider date];
257256

258-
SentryClientInternal *newClient =
259-
[[SentryClientInternal alloc] initWithOptions:internalOptions];
257+
SentryClientInternal *newClient = [[SentryClientInternal alloc] initWithOptions:options];
260258
[newClient.fileManager moveAppStateToPreviousAppState];
261259
[newClient.fileManager moveBreadcrumbsToPreviousBreadcrumbs];
262260
[SentryDependencyContainer.sharedInstance

Sources/Sentry/include/SentryClient.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ SENTRY_NO_INIT
2121

2222
@property (nonatomic, assign, readonly) BOOL isEnabled;
2323

24-
@property (nonatomic, strong) SentryOptionsObjC *optionsInternal;
24+
@property (nonatomic, strong) SentryOptions *options;
2525

26-
@property (nonatomic, strong, readonly) SentryOptions *options;
26+
- (void)setOptionsInternal:(SentryOptionsObjC *)optionsInternal;
27+
28+
- (SentryOptionsObjC *)getOptions;
2729

2830
/**
2931
* Initializes a @c SentryClient. Pass in a dictionary of options.

Sources/Sentry/include/SentryDependencyContainerSwiftHelper.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#import "SentryDefines.h"
2+
#import "SentryOptionsObjC.h"
23
#import "SentryProfilingConditionals.h"
34
#import <Foundation/Foundation.h>
45

@@ -11,6 +12,15 @@
1112

1213
NS_ASSUME_NONNULL_BEGIN
1314

15+
@interface SentryDefaultRedactOptions : NSObject
16+
17+
@property (nonatomic) BOOL maskAllText;
18+
@property (nonatomic) BOOL maskAllImages;
19+
@property (nonatomic) NSArray<Class> *maskedViewClasses;
20+
@property (nonatomic) NSArray<Class> *unmaskedViewClasses;
21+
22+
@end
23+
1424
// Some Swift code needs to access Sentry types that we don’t want to completely
1525
// expose to Swift. This class is exposed to Swift
1626
// and bridges some functionality from without importing large amounts of the
@@ -21,8 +31,22 @@ NS_ASSUME_NONNULL_BEGIN
2131

2232
+ (nullable NSArray<UIWindow *> *)windows;
2333

34+
// Since SentryOptions is in ObjC, Swift code can't see the SentryViewScreenshotOptions property
35+
+ (BOOL)fastViewRenderingEnabled:(SentryOptionsObjC *)options;
36+
+ (BOOL)viewRendererV2Enabled:(SentryOptionsObjC *)options;
37+
+ (SentryDefaultRedactOptions *)redactOptions:(SentryOptionsObjC *)options;
38+
2439
#endif // SENTRY_HAS_UIKIT
2540

41+
+ (NSString *_Nullable)release:(SentryOptionsObjC *)options;
42+
+ (NSString *)environment:(SentryOptionsObjC *)options;
43+
+ (NSObject *_Nullable)beforeSendLog:(NSObject *)beforeSendLog options:(SentryOptionsObjC *)options;
44+
+ (NSString *)cacheDirectoryPath:(SentryOptionsObjC *)options;
45+
+ (BOOL)enableLogs:(SentryOptionsObjC *)options;
46+
+ (NSArray<NSString *> *)enabledFeatures:(SentryOptionsObjC *)options;
47+
+ (BOOL)sendDefaultPii:(SentryOptionsObjC *)options;
48+
+ (NSArray<NSString *> *)inAppIncludes:(SentryOptionsObjC *)options;
49+
2650
+ (SentryDispatchQueueWrapper *)dispatchQueueWrapper;
2751
+ (void)dispatchSyncOnMainQueue:(void (^)(void))block;
2852
+ (nullable NSDate *)readTimestampLastInForeground;

0 commit comments

Comments
 (0)