Skip to content

Commit 2ade01f

Browse files
committed
tests handle possible errors
1 parent 08abe3e commit 2ade01f

File tree

3 files changed

+28
-28
lines changed

3 files changed

+28
-28
lines changed

Tests/ConnectionTests.swift

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ class ConnectionTests : SQLiteTestCase {
7272
}
7373

7474
func test_prepare_preparesAndReturnsStatements() {
75-
_ = db.prepare("SELECT * FROM users WHERE admin = 0")
76-
_ = db.prepare("SELECT * FROM users WHERE admin = ?", 0)
77-
_ = db.prepare("SELECT * FROM users WHERE admin = ?", [0])
78-
_ = db.prepare("SELECT * FROM users WHERE admin = $admin", ["$admin": 0])
75+
_ = try! db.prepare("SELECT * FROM users WHERE admin = 0")
76+
_ = try! db.prepare("SELECT * FROM users WHERE admin = ?", 0)
77+
_ = try! db.prepare("SELECT * FROM users WHERE admin = ?", [0])
78+
_ = try! db.prepare("SELECT * FROM users WHERE admin = $admin", ["$admin": 0])
7979
}
8080

8181
func test_run_preparesRunsAndReturnsStatements() {
@@ -87,10 +87,10 @@ class ConnectionTests : SQLiteTestCase {
8787
}
8888

8989
func test_scalar_preparesRunsAndReturnsScalarValues() {
90-
XCTAssertEqual(0, db.scalar("SELECT count(*) FROM users WHERE admin = 0") as? Int64)
91-
XCTAssertEqual(0, db.scalar("SELECT count(*) FROM users WHERE admin = ?", 0) as? Int64)
92-
XCTAssertEqual(0, db.scalar("SELECT count(*) FROM users WHERE admin = ?", [0]) as? Int64)
93-
XCTAssertEqual(0, db.scalar("SELECT count(*) FROM users WHERE admin = $admin", ["$admin": 0]) as? Int64)
90+
XCTAssertEqual(0, try! db.scalar("SELECT count(*) FROM users WHERE admin = 0") as? Int64)
91+
XCTAssertEqual(0, try! db.scalar("SELECT count(*) FROM users WHERE admin = ?", 0) as? Int64)
92+
XCTAssertEqual(0, try! db.scalar("SELECT count(*) FROM users WHERE admin = ?", [0]) as? Int64)
93+
XCTAssertEqual(0, try! db.scalar("SELECT count(*) FROM users WHERE admin = $admin", ["$admin": 0]) as? Int64)
9494
AssertSQL("SELECT count(*) FROM users WHERE admin = 0", 4)
9595
}
9696

@@ -113,7 +113,7 @@ class ConnectionTests : SQLiteTestCase {
113113
}
114114

115115
func test_transaction_beginsAndCommitsTransactions() {
116-
let stmt = db.prepare("INSERT INTO users (email) VALUES (?)", "alice@example.com")
116+
let stmt = try! db.prepare("INSERT INTO users (email) VALUES (?)", "alice@example.com")
117117

118118
try! db.transaction {
119119
try stmt.run()
@@ -126,7 +126,7 @@ class ConnectionTests : SQLiteTestCase {
126126
}
127127

128128
func test_transaction_beginsAndRollsTransactionsBack() {
129-
let stmt = db.prepare("INSERT INTO users (email) VALUES (?)", "alice@example.com")
129+
let stmt = try! db.prepare("INSERT INTO users (email) VALUES (?)", "alice@example.com")
130130

131131
do {
132132
try db.transaction {
@@ -162,7 +162,7 @@ class ConnectionTests : SQLiteTestCase {
162162

163163
func test_savepoint_beginsAndRollsSavepointsBack() {
164164
let db = self.db
165-
let stmt = db.prepare("INSERT INTO users (email) VALUES (?)", "alice@example.com")
165+
let stmt = try! db.prepare("INSERT INTO users (email) VALUES (?)", "alice@example.com")
166166

167167
do {
168168
try db.savepoint("1") {
@@ -238,7 +238,7 @@ class ConnectionTests : SQLiteTestCase {
238238
try! db.transaction {
239239
try self.InsertUser("alice")
240240
}
241-
XCTAssertEqual(1, db.scalar("SELECT count(*) FROM users") as? Int64)
241+
XCTAssertEqual(1, try! db.scalar("SELECT count(*) FROM users") as? Int64)
242242
}
243243
}
244244

@@ -252,7 +252,7 @@ class ConnectionTests : SQLiteTestCase {
252252
}
253253
} catch {
254254
}
255-
XCTAssertEqual(0, db.scalar("SELECT count(*) FROM users") as? Int64)
255+
XCTAssertEqual(0, try! db.scalar("SELECT count(*) FROM users") as? Int64)
256256
}
257257
}
258258

@@ -268,36 +268,36 @@ class ConnectionTests : SQLiteTestCase {
268268
}
269269
} catch {
270270
}
271-
XCTAssertEqual(0, db.scalar("SELECT count(*) FROM users") as? Int64)
271+
XCTAssertEqual(0, try! db.scalar("SELECT count(*) FROM users") as? Int64)
272272
}
273273
}
274274

275275
func test_createFunction_withArrayArguments() {
276276
db.createFunction("hello") { $0[0].map { "Hello, \($0)!" } }
277277

278-
XCTAssertEqual("Hello, world!", db.scalar("SELECT hello('world')") as? String)
279-
XCTAssert(db.scalar("SELECT hello(NULL)") == nil)
278+
XCTAssertEqual("Hello, world!", try! db.scalar("SELECT hello('world')") as? String)
279+
XCTAssert(try! db.scalar("SELECT hello(NULL)") == nil)
280280
}
281281

282282
func test_createFunction_createsQuotableFunction() {
283283
db.createFunction("hello world") { $0[0].map { "Hello, \($0)!" } }
284284

285-
XCTAssertEqual("Hello, world!", db.scalar("SELECT \"hello world\"('world')") as? String)
286-
XCTAssert(db.scalar("SELECT \"hello world\"(NULL)") == nil)
285+
XCTAssertEqual("Hello, world!", try! db.scalar("SELECT \"hello world\"('world')") as? String)
286+
XCTAssert(try! db.scalar("SELECT \"hello world\"(NULL)") == nil)
287287
}
288288

289289
func test_createCollation_createsCollation() {
290290
db.createCollation("NODIACRITIC") { lhs, rhs in
291291
return lhs.compare(rhs, options: .DiacriticInsensitiveSearch)
292292
}
293-
XCTAssertEqual(1, db.scalar("SELECT ? = ? COLLATE NODIACRITIC", "cafe", "café") as? Int64)
293+
XCTAssertEqual(1, try! db.scalar("SELECT ? = ? COLLATE NODIACRITIC", "cafe", "café") as? Int64)
294294
}
295295

296296
func test_createCollation_createsQuotableCollation() {
297297
db.createCollation("NO DIACRITIC") { lhs, rhs in
298298
return lhs.compare(rhs, options: .DiacriticInsensitiveSearch)
299299
}
300-
XCTAssertEqual(1, db.scalar("SELECT ? = ? COLLATE \"NO DIACRITIC\"", "cafe", "café") as? Int64)
300+
XCTAssertEqual(1, try! db.scalar("SELECT ? = ? COLLATE \"NO DIACRITIC\"", "cafe", "café") as? Int64)
301301
}
302302

303303
func test_interrupt_interruptsLongRunningQuery() {
@@ -307,7 +307,7 @@ class ConnectionTests : SQLiteTestCase {
307307
return nil
308308
}
309309

310-
let stmt = db.prepare("SELECT *, sleep(?) FROM users", 0.1)
310+
let stmt = try! db.prepare("SELECT *, sleep(?) FROM users", 0.1)
311311
try! stmt.run()
312312

313313
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(10 * NSEC_PER_MSEC)), dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), db.interrupt)

Tests/FTS4Tests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class FTS4IntegrationTests : SQLiteTestCase {
7171
AssertSQL("CREATE VIRTUAL TABLE \"emails\" USING fts4(\"subject\", \"body\", tokenize=\"SQLite.swift\" \"tokenizer\")")
7272

7373
try! db.run(emails.insert(subject <- "Aún más cáfe!"))
74-
XCTAssertEqual(1, db.scalar(emails.filter(emails.match("aun")).count))
74+
XCTAssertEqual(1, try! db.scalar(emails.filter(emails.match("aun")).count))
7575
}
7676

7777
}

Tests/QueryTests.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ class QueryIntegrationTests : SQLiteTestCase {
278278
// MARK: -
279279

280280
func test_select() {
281-
for _ in db.prepare(users) {
281+
for _ in try! db.prepare(users) {
282282
// FIXME
283283
}
284284

@@ -288,22 +288,22 @@ class QueryIntegrationTests : SQLiteTestCase {
288288
let alice = try! db.run(users.insert(email <- "alice@example.com"))
289289
try! db.run(users.insert(email <- "betsy@example.com", managerId <- alice))
290290

291-
for user in db.prepare(users.join(managers, on: managers[id] == users[managerId])) {
291+
for user in try! db.prepare(users.join(managers, on: managers[id] == users[managerId])) {
292292
user[users[managerId]]
293293
}
294294
}
295295

296296
func test_scalar() {
297-
XCTAssertEqual(0, db.scalar(users.count))
298-
XCTAssertEqual(false, db.scalar(users.exists))
297+
XCTAssertEqual(0, try! db.scalar(users.count))
298+
XCTAssertEqual(false, try! db.scalar(users.exists))
299299

300300
try! InsertUsers("alice")
301-
XCTAssertEqual(1, db.scalar(users.select(id.average)))
301+
XCTAssertEqual(1, try! db.scalar(users.select(id.average)))
302302
}
303303

304304
func test_pluck() {
305305
let rowid = try! db.run(users.insert(email <- "alice@example.com"))
306-
XCTAssertEqual(rowid, db.pluck(users)![id])
306+
XCTAssertEqual(rowid, try! db.pluck(users)![id])
307307
}
308308

309309
func test_insert() {

0 commit comments

Comments
 (0)