Skip to content

Commit eb0833e

Browse files
fix tests
1 parent fac7b58 commit eb0833e

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed
Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
import XCTest
22

33
extension XCTestCase {
4-
func givenStoredSentryCrashReport(resource: String) throws {
4+
5+
private func jsonDataOfResource(resource: String) throws -> Data {
56
let jsonPath = Bundle(for: type(of: self)).path(forResource: resource, ofType: "json")
6-
let jsonData = try Data(contentsOf: URL(fileURLWithPath: jsonPath ?? ""))
7+
return try Data(contentsOf: URL(fileURLWithPath: jsonPath ?? ""))
8+
}
9+
10+
func givenStoredSentryCrashReport(resource: String) throws {
11+
let jsonData = try jsonDataOfResource(resource: resource)
712
jsonData.withUnsafeBytes { ( bytes: UnsafeRawBufferPointer) -> Void in
813
let pointer = bytes.bindMemory(to: Int8.self)
914
sentrycrashcrs_addUserReport(pointer.baseAddress, Int32(jsonData.count))
1015
}
1116
}
1217

1318
func getCrashReport(resource: String) throws -> [String: Any] {
14-
let jsonPath = Bundle(for: type(of: self)).path(forResource: resource, ofType: "json")
15-
let jsonData = try Data(contentsOf: URL(fileURLWithPath: jsonPath ?? ""))
19+
let jsonData = try jsonDataOfResource(resource: resource)
1620
return try JSONSerialization.jsonObject(with: jsonData, options: []) as! [String: Any]
1721
}
1822
}

Tests/SentryTests/SentryCrash/SentryCrashDoctorTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ import XCTest
33
final class SentryCrashDoctorTests: XCTestCase {
44

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

88
let diagnose = SentryCrashDoctor().diagnoseCrash(report)
99

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

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

1616
let diagnose = SentryCrashDoctor().diagnoseCrash(report)
1717

0 commit comments

Comments
 (0)