Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
philipphofmann committed Feb 6, 2023
1 parent fac7b58 commit eb0833e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
12 changes: 8 additions & 4 deletions Tests/SentryTests/SentryCrash/CrashReport.swift
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import XCTest

extension XCTestCase {
func givenStoredSentryCrashReport(resource: String) throws {

private func jsonDataOfResource(resource: String) throws -> Data {
let jsonPath = Bundle(for: type(of: self)).path(forResource: resource, ofType: "json")
let jsonData = try Data(contentsOf: URL(fileURLWithPath: jsonPath ?? ""))
return try Data(contentsOf: URL(fileURLWithPath: jsonPath ?? ""))
}

func givenStoredSentryCrashReport(resource: String) throws {
let jsonData = try jsonDataOfResource(resource: resource)
jsonData.withUnsafeBytes { ( bytes: UnsafeRawBufferPointer) -> Void in
let pointer = bytes.bindMemory(to: Int8.self)
sentrycrashcrs_addUserReport(pointer.baseAddress, Int32(jsonData.count))
}
}

func getCrashReport(resource: String) throws -> [String: Any] {
let jsonPath = Bundle(for: type(of: self)).path(forResource: resource, ofType: "json")
let jsonData = try Data(contentsOf: URL(fileURLWithPath: jsonPath ?? ""))
let jsonData = try jsonDataOfResource(resource: resource)
return try JSONSerialization.jsonObject(with: jsonData, options: []) as! [String: Any]
}
}
4 changes: 2 additions & 2 deletions Tests/SentryTests/SentryCrash/SentryCrashDoctorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import XCTest
final class SentryCrashDoctorTests: XCTestCase {

func testBadAccess() throws {
let report = try getCrashReport(resource: "crash-bad-access")
let report = try getCrashReport(resource: "Resources/crash-bad-access")

let diagnose = SentryCrashDoctor().diagnoseCrash(report)

XCTAssertEqual("EXC_ARM_DA_ALIGN at 0x13fd4582e.", diagnose)
}

func testBadAccess_NoSubcode() throws {
let report = try getCrashReport(resource: "crash-bad-access-no-subcode")
let report = try getCrashReport(resource: "Resources/crash-bad-access-no-subcode")

let diagnose = SentryCrashDoctor().diagnoseCrash(report)

Expand Down

0 comments on commit eb0833e

Please sign in to comment.