Skip to content

Commit

Permalink
Add a test to ensure bridging RLMError to Realm.Error.
Browse files Browse the repository at this point in the history
  • Loading branch information
kishikawakatsumi committed Feb 13, 2017
1 parent 07c8f99 commit 6c17a96
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion RealmSwift/Error.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ extension Realm {
```swift
let realm: Realm?
do {
realm = Realm()
realm = try Realm()
} catch Realm.Error.incompatibleLockFile {
print("Realm Browser app may be attached to Realm on device?")
}
Expand Down
19 changes: 19 additions & 0 deletions RealmSwift/Tests/RealmTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -813,4 +813,23 @@ class RealmTests: TestCase {
XCTAssertFalse(realm == otherThreadRealm)
}
}

func testCatchSpecificErrors() {
do {
_ = try Realm(configuration: Realm.Configuration(fileURL: URL(fileURLWithPath: "/dev/null/foo")))
XCTFail("Error should be thrown")
} catch Realm.Error.fileAccess {
// Success to catch the error
} catch {
XCTFail("Failed to brigde RLMError to Realm.Error")
}
do {
_ = try Realm(configuration: Realm.Configuration(fileURL: defaultRealmURL(), readOnly: true))
XCTFail("Error should be thrown")
} catch Realm.Error.fileNotFound {
// Success to catch the error
} catch {
XCTFail("Failed to brigde RLMError to Realm.Error")
}
}
}

0 comments on commit 6c17a96

Please sign in to comment.