Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: setting SDK name through options[sdk][name] shouldn't clear version #2139

Merged
merged 3 commits into from
Sep 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

- Can't find app image when swizzling (#2124)
- Crash with screenshot is reported twice (#2134)
- Setting SDK name through `options[sdk][name]` shouldn't clear version (#2139)

## 7.24.1

Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ let package = Package(
platforms: [.iOS(.v9), .macOS(.v10_10), .tvOS(.v9), .watchOS(.v2)],
products: [
.library(name: "Sentry", targets: ["Sentry"]),
.library(name: "Sentry-Dynamic", type: .dynamic, targets: ["Sentry"]),
.library(name: "Sentry-Dynamic", type: .dynamic, targets: ["Sentry"])
],
targets: [
.target(
Expand Down
2 changes: 1 addition & 1 deletion Samples/SPM-Dynamic/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import PackageDescription
let package = Package(
name: "SPM-Dynamic",
products: [
.library(name: "SPM-Dynamic", type: .dynamic, targets: ["SPM-Dynamic"]),
.library(name: "SPM-Dynamic", type: .dynamic, targets: ["SPM-Dynamic"])
],
dependencies: [
// branch is replaced in CI to the current sha
Expand Down
4 changes: 3 additions & 1 deletion Sources/Sentry/SentryOptions.m
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,9 @@ - (BOOL)validateOptions:(NSDictionary<NSString *, id> *)options
// Note: we should remove this code once the hybrid SDKs move over to the new
// PrivateSentrySDKOnly setter functions.
if ([options[@"sdk"] isKindOfClass:[NSDictionary class]]) {
SentrySdkInfo *sdkInfo = [[SentrySdkInfo alloc] initWithDict:options];
SentrySdkInfo *defaults = [[SentrySdkInfo alloc] initWithName:SentryMeta.sdkName
andVersion:SentryMeta.versionString];
SentrySdkInfo *sdkInfo = [[SentrySdkInfo alloc] initWithDict:options orDefaults:defaults];
SentryMeta.versionString = sdkInfo.version;
SentryMeta.sdkName = sdkInfo.name;
}
Expand Down
8 changes: 8 additions & 0 deletions Tests/SentryTests/PrivateSentrySDKOnlyTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,20 @@ class PrivateSentrySDKOnlyTests: XCTestCase {
func testSetSdkName() {
let originalName = PrivateSentrySDKOnly.getSdkName()
let name = "Some SDK name"
let originalVersion = SentryMeta.versionString
XCTAssertNotEqual(originalVersion, "")

PrivateSentrySDKOnly.setSdkName(name)
XCTAssertEqual(SentryMeta.sdkName, name)
XCTAssertEqual(SentryMeta.versionString, originalVersion)
XCTAssertEqual(PrivateSentrySDKOnly.getSdkName(), name)
XCTAssertEqual(PrivateSentrySDKOnly.getSdkVersionString(), originalVersion)

PrivateSentrySDKOnly.setSdkName(originalName)
XCTAssertEqual(SentryMeta.sdkName, originalName)
XCTAssertEqual(SentryMeta.versionString, originalVersion)
XCTAssertEqual(PrivateSentrySDKOnly.getSdkName(), originalName)
XCTAssertEqual(PrivateSentrySDKOnly.getSdkVersionString(), originalVersion)
}

func testSetSdkNameAndVersion() {
Expand Down
10 changes: 8 additions & 2 deletions Tests/SentryTests/SentryOptionsTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,7 @@ - (void)testSetCustomSdkInfo
- (void)testSetCustomSdkName
{
NSDictionary *dict = @{ @"name" : @"custom.sdk" };
NSString *originalVersion = SentryMeta.versionString;

NSError *error = nil;
SentryOptions *options =
Expand All @@ -614,13 +615,16 @@ - (void)testSetCustomSdkName
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
XCTAssertEqual(dict[@"name"], options.sdkInfo.name);
XCTAssertEqual(SentryMeta.versionString, options.sdkInfo.version); // default version
// version stays unchanged
XCTAssertEqual(SentryMeta.versionString, options.sdkInfo.version);
XCTAssertEqual(SentryMeta.versionString, originalVersion);
#pragma clang diagnostic pop
}

- (void)testSetCustomSdkVersion
{
NSDictionary *dict = @{ @"version" : @"1.2.3-alpha.0" };
NSString *originalName = SentryMeta.sdkName;

NSError *error = nil;
SentryOptions *options =
Expand All @@ -631,8 +635,10 @@ - (void)testSetCustomSdkVersion

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
XCTAssertEqual(SentryMeta.sdkName, options.sdkInfo.name); // default name
XCTAssertEqual(dict[@"version"], options.sdkInfo.version);
// name stays unchanged
XCTAssertEqual(SentryMeta.sdkName, options.sdkInfo.name);
XCTAssertEqual(SentryMeta.sdkName, originalName);
#pragma clang diagnostic pop

NSDictionary *info = [[NSBundle bundleForClass:[SentryClient class]] infoDictionary];
Expand Down