Skip to content

Commit

Permalink
Merge branch 'master' into fix/fix-flaky-tests
Browse files Browse the repository at this point in the history
* master:
  Run tests on iOS 16 using Xcode 14.0 (#2147)
  ref: Fix Xcode 14 compile issues (#2145)
  Provide fallbacks for assertions in production (#2141)

# Conflicts:
#	scripts/xcode-test.sh
  • Loading branch information
kevinrenskers committed Sep 13, 2022
2 parents b9b9a89 + 4c88404 commit 46885db
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 7 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ jobs:
xcode: "13.4.1"
test-destination-os: "latest"

# iOS 16
- runs-on: macos-12
platform: "iOS"
xcode: "14.0"
test-destination-os: "latest"

# macOS 11
- runs-on: macos-11
platform: "macOS"
Expand Down
4 changes: 4 additions & 0 deletions Sources/Sentry/SentryClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,10 @@ - (SentryEvent *_Nullable)prepareEvent:(SentryEvent *)event
isCrashEvent:(BOOL)isCrashEvent
{
NSParameterAssert(event);
if (event == nil) {
return nil;
}

if ([self isDisabled]) {
[self logDisabledMessage];
return nil;
Expand Down
8 changes: 8 additions & 0 deletions Sources/Sentry/SentrySerialization.m
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ + (SentryEnvelope *_Nullable)envelopeWithData:(NSData *)data
SentryEnvelopeHeader *envelopeHeader = nil;
const unsigned char *bytes = [data bytes];
int envelopeHeaderIndex = 0;

for (int i = 0; i < data.length; ++i) {
if (bytes[i] == '\n') {
envelopeHeaderIndex = i;
Expand Down Expand Up @@ -208,12 +209,19 @@ + (SentryEnvelope *_Nullable)envelopeWithData:(NSData *)data
break;
}
}

if (nil == envelopeHeader) {
[SentryLog logWithMessage:[NSString stringWithFormat:@"Invalid envelope. No header found."]
andLevel:kSentryLevelError];
return nil;
}

NSAssert(envelopeHeaderIndex > 0, @"EnvelopeHeader was parsed, its index is expected.");
if (envelopeHeaderIndex == 0) {
NSLog(@"EnvelopeHeader was parsed, its index is expected.");
return nil;
}

// Parse items
NSInteger itemHeaderStart = envelopeHeaderIndex + 1;

Expand Down
13 changes: 11 additions & 2 deletions Sources/Sentry/SentrySwizzle.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ @implementation SentrySwizzleInfo

- (SentrySwizzleOriginalIMP)getOriginalImplementation
{
NSAssert(_impProviderBlock, nil);
NSAssert(_impProviderBlock, @"_impProviderBlock can't be missing");
if (!_impProviderBlock) {
NSLog(@"_impProviderBlock can't be missing");
return NULL;
}

#if TEST
@synchronized(self) {
Expand Down Expand Up @@ -136,9 +140,14 @@ + (BOOL)swizzleInstanceMethod:(SEL)selector
mode:(SentrySwizzleMode)mode
key:(const void *)key
{
NSAssert(!(NULL == key && SentrySwizzleModeAlways != mode),
NSAssert(!(key == NULL && mode != SentrySwizzleModeAlways),
@"Key may not be NULL if mode is not SentrySwizzleModeAlways.");

if (key == NULL && mode != SentrySwizzleModeAlways) {
NSLog(@"Key may not be NULL if mode is not SentrySwizzleModeAlways.");
return NO;
}

@synchronized(swizzledClassesDictionary()) {
if (key) {
NSSet<Class> *swizzledClasses = swizzledClassesForKey(key);
Expand Down
2 changes: 1 addition & 1 deletion Sources/Sentry/SentryTime.mm
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# import "SentryMachLogging.hpp"

uint64_t
getAbsoluteTime()
getAbsoluteTime(void)
{
if (@available(macOS 10.12, iOS 10.0, *)) {
return clock_gettime_nsec_np(CLOCK_UPTIME_RAW);
Expand Down
2 changes: 1 addition & 1 deletion Sources/Sentry/include/SentryTime.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ SENTRY_EXTERN_C_BEGIN
* Returns the absolute timestamp, which has no defined reference point or unit
* as it is platform dependent.
*/
uint64_t getAbsoluteTime();
uint64_t getAbsoluteTime(void);

/**
* Returns the duration in nanoseconds between two absolute timestamps.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ - (id)initWithEncodeOptions:(SentryCrashJSONEncodeOption)encodeOptions
self.callbacks = malloc(sizeof(*self.callbacks));
// Unlikely malloc failure.
NSAssert(self.callbacks != NULL, @"Could not allocate callbacks");
if (self.callbacks == NULL) {
NSLog(@"Could not allocate callbacks");
return NULL;
}

self.callbacks->onBeginArray = onBeginArray;
self.callbacks->onBeginObject = onBeginObject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ class SentryUIViewControllerSwizzlingTests: XCTestCase {
let mockApplication = MockApplication(mockApplicationDelegate)
XCTAssertFalse(fixture.sut.swizzleRootViewController(from: mockApplication))
}

func testSwizzle_fromApplication_noWindow() {
let mockApplicationDelegate = MockApplication.MockApplicationDelegate(nil)
let mockApplication = MockApplication(mockApplicationDelegate)
Expand Down
2 changes: 0 additions & 2 deletions scripts/xcode-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ esac

echo "CONFIGURATION: $CONFIGURATION"

XCODE_MAJOR_VERSION=$(echo $XCODE | sed -E 's/([0-9]*)\.[0-9]*\.[0-9]*/\1/g')

if [ $PLATFORM == "iOS" -a $OS == "12.4" ]; then
# Skip some tests that fail on iOS 12.4.
env NSUnbufferedIO=YES xcodebuild -workspace Sentry.xcworkspace \
Expand Down

0 comments on commit 46885db

Please sign in to comment.