Skip to content

Commit 544e7b9

Browse files
committed
Remove force tries in tests
1 parent 9d0c0b9 commit 544e7b9

11 files changed

+164
-160
lines changed

Tests/SQLiteTests/CipherTests.swift

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import SQLCipher
55

66
class CipherTests: XCTestCase {
77

8-
let db1 = try! Connection()
9-
let db2 = try! Connection()
8+
let db1 = try Connection()
9+
let db2 = try Connection()
1010

1111
override func setUpWithError() throws {
1212
// db
@@ -26,41 +26,41 @@ class CipherTests: XCTestCase {
2626
try super.setUpWithError()
2727
}
2828

29-
func test_key() {
30-
XCTAssertEqual(1, try! db1.scalar("SELECT count(*) FROM foo") as? Int64)
29+
func test_key() throws {
30+
XCTAssertEqual(1, try db1.scalar("SELECT count(*) FROM foo") as? Int64)
3131
}
3232

3333
func test_key_blob_literal() {
34-
let db = try! Connection()
35-
try! db.key("x'2DD29CA851E7B56E4697B0E1F08507293D761A05CE4D1B628663F411A8086D99'")
34+
let db = try Connection()
35+
try db.key("x'2DD29CA851E7B56E4697B0E1F08507293D761A05CE4D1B628663F411A8086D99'")
3636
}
3737

38-
func test_rekey() {
39-
try! db1.rekey("goodbye")
40-
XCTAssertEqual(1, try! db1.scalar("SELECT count(*) FROM foo") as? Int64)
38+
func test_rekey() throws {
39+
try db1.rekey("goodbye")
40+
XCTAssertEqual(1, try db1.scalar("SELECT count(*) FROM foo") as? Int64)
4141
}
4242

43-
func test_data_key() {
44-
XCTAssertEqual(1, try! db2.scalar("SELECT count(*) FROM foo") as? Int64)
43+
func test_data_key() throws {
44+
XCTAssertEqual(1, try db2.scalar("SELECT count(*) FROM foo") as? Int64)
4545
}
4646

47-
func test_data_rekey() {
47+
func test_data_rekey() throws {
4848
let newKey = keyData()
49-
try! db2.rekey(Blob(bytes: newKey.bytes, length: newKey.length))
50-
XCTAssertEqual(1, try! db2.scalar("SELECT count(*) FROM foo") as? Int64)
49+
try db2.rekey(Blob(bytes: newKey.bytes, length: newKey.length))
50+
XCTAssertEqual(1, try db2.scalar("SELECT count(*) FROM foo") as? Int64)
5151
}
5252

53-
func test_keyFailure() {
53+
func test_keyFailure() throws {
5454
let path = "\(NSTemporaryDirectory())/db.sqlite3"
5555
_ = try? FileManager.default.removeItem(atPath: path)
5656

57-
let connA = try! Connection(path)
58-
defer { try! FileManager.default.removeItem(atPath: path) }
57+
let connA = try Connection(path)
58+
defer { try FileManager.default.removeItem(atPath: path) }
5959

60-
try! connA.key("hello")
61-
try! connA.run("CREATE TABLE foo (bar TEXT)")
60+
try connA.key("hello")
61+
try connA.run("CREATE TABLE foo (bar TEXT)")
6262

63-
let connB = try! Connection(path, readonly: true)
63+
let connB = try Connection(path, readonly: true)
6464

6565
do {
6666
try connB.key("world")
@@ -72,7 +72,7 @@ class CipherTests: XCTestCase {
7272
}
7373
}
7474

75-
func test_open_db_encrypted_with_sqlcipher() {
75+
func test_open_db_encrypted_with_sqlcipher() throws {
7676
// $ sqlcipher Tests/SQLiteTests/fixtures/encrypted-[version].x.sqlite
7777
// sqlite> pragma key = 'sqlcipher-test';
7878
// sqlite> CREATE TABLE foo (bar TEXT);
@@ -85,17 +85,17 @@ class CipherTests: XCTestCase {
8585
fixture("encrypted-3.x", withExtension: "sqlite") :
8686
fixture("encrypted-4.x", withExtension: "sqlite")
8787

88-
try! FileManager.default.setAttributes([FileAttributeKey.immutable: 1], ofItemAtPath: encryptedFile)
88+
try FileManager.default.setAttributes([FileAttributeKey.immutable: 1], ofItemAtPath: encryptedFile)
8989
XCTAssertFalse(FileManager.default.isWritableFile(atPath: encryptedFile))
9090

9191
defer {
9292
// ensure file can be cleaned up afterwards
93-
try! FileManager.default.setAttributes([FileAttributeKey.immutable: 0], ofItemAtPath: encryptedFile)
93+
try FileManager.default.setAttributes([FileAttributeKey.immutable: 0], ofItemAtPath: encryptedFile)
9494
}
9595

96-
let conn = try! Connection(encryptedFile)
97-
try! conn.key("sqlcipher-test")
98-
XCTAssertEqual(1, try! conn.scalar("SELECT count(*) FROM foo") as? Int64)
96+
let conn = try Connection(encryptedFile)
97+
try conn.key("sqlcipher-test")
98+
XCTAssertEqual(1, try conn.scalar("SELECT count(*) FROM foo") as? Int64)
9999
}
100100

101101
private func keyData(length: Int = 64) -> NSMutableData {

Tests/SQLiteTests/CustomAggregationTests.swift

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class CustomAggregationTests: SQLiteTestCase {
2525
try insertUser("Eve", age: 28, admin: false)
2626
}
2727

28-
func testUnsafeCustomSum() {
28+
func testUnsafeCustomSum() throws {
2929
let step = { (bindings: [Binding?], state: UnsafeMutablePointer<Int64>) in
3030
if let v = bindings[0] as? Int64 {
3131
state.pointee += v
@@ -43,15 +43,15 @@ class CustomAggregationTests: SQLiteTestCase {
4343
v[0] = 0
4444
return v.baseAddress!
4545
}
46-
let result = try! db.prepare("SELECT mySUM1(age) AS s FROM users")
46+
let result = try db.prepare("SELECT mySUM1(age) AS s FROM users")
4747
let i = result.columnNames.firstIndex(of: "s")!
4848
for row in result {
4949
let value = row[i] as? Int64
5050
XCTAssertEqual(83, value)
5151
}
5252
}
5353

54-
func testUnsafeCustomSumGrouping() {
54+
func testUnsafeCustomSumGrouping() throws {
5555
let step = { (bindings: [Binding?], state: UnsafeMutablePointer<Int64>) in
5656
if let v = bindings[0] as? Int64 {
5757
state.pointee += v
@@ -68,46 +68,46 @@ class CustomAggregationTests: SQLiteTestCase {
6868
v[0] = 0
6969
return v.baseAddress!
7070
}
71-
let result = try! db.prepare("SELECT mySUM2(age) AS s FROM users GROUP BY admin ORDER BY s")
71+
let result = try db.prepare("SELECT mySUM2(age) AS s FROM users GROUP BY admin ORDER BY s")
7272
let i = result.columnNames.firstIndex(of: "s")!
7373
let values = result.compactMap { $0[i] as? Int64 }
7474
XCTAssertTrue(values.elementsEqual([28, 55]))
7575
}
7676

77-
func testCustomSum() {
77+
func testCustomSum() throws {
7878
let reduce: (Int64, [Binding?]) -> Int64 = { (last, bindings) in
7979
let v = (bindings[0] as? Int64) ?? 0
8080
return last + v
8181
}
8282
db.createAggregation("myReduceSUM1", initialValue: Int64(2000), reduce: reduce, result: { $0 })
83-
let result = try! db.prepare("SELECT myReduceSUM1(age) AS s FROM users")
83+
let result = try db.prepare("SELECT myReduceSUM1(age) AS s FROM users")
8484
let i = result.columnNames.firstIndex(of: "s")!
8585
for row in result {
8686
let value = row[i] as? Int64
8787
XCTAssertEqual(2083, value)
8888
}
8989
}
9090

91-
func testCustomSumGrouping() {
91+
func testCustomSumGrouping() throws {
9292
let reduce: (Int64, [Binding?]) -> Int64 = { (last, bindings) in
9393
let v = (bindings[0] as? Int64) ?? 0
9494
return last + v
9595
}
9696
db.createAggregation("myReduceSUM2", initialValue: Int64(3000), reduce: reduce, result: { $0 })
97-
let result = try! db.prepare("SELECT myReduceSUM2(age) AS s FROM users GROUP BY admin ORDER BY s")
97+
let result = try db.prepare("SELECT myReduceSUM2(age) AS s FROM users GROUP BY admin ORDER BY s")
9898
let i = result.columnNames.firstIndex(of: "s")!
9999
let values = result.compactMap { $0[i] as? Int64 }
100100
XCTAssertTrue(values.elementsEqual([3028, 3055]))
101101
}
102102

103-
func testCustomStringAgg() {
103+
func testCustomStringAgg() throws {
104104
let initial = String(repeating: " ", count: 64)
105105
let reduce: (String, [Binding?]) -> String = { (last, bindings) in
106106
let v = (bindings[0] as? String) ?? ""
107107
return last + v
108108
}
109109
db.createAggregation("myReduceSUM3", initialValue: initial, reduce: reduce, result: { $0 })
110-
let result = try! db.prepare("SELECT myReduceSUM3(email) AS s FROM users")
110+
let result = try db.prepare("SELECT myReduceSUM3(email) AS s FROM users")
111111

112112
let i = result.columnNames.firstIndex(of: "s")!
113113
for row in result {
@@ -116,7 +116,7 @@ class CustomAggregationTests: SQLiteTestCase {
116116
}
117117
}
118118

119-
func testCustomObjectSum() {
119+
func testCustomObjectSum() throws {
120120
{
121121
let initial = TestObject(value: 1000)
122122
let reduce: (TestObject, [Binding?]) -> TestObject = { (last, bindings) in

Tests/SQLiteTests/CustomFunctionsTests.swift

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@ class CustomFunctionNoArgsTests: SQLiteTestCase {
88
typealias FunctionNoOptional = () -> Expression<String>
99
typealias FunctionResultOptional = () -> Expression<String?>
1010

11-
func testFunctionNoOptional() {
12-
let _: FunctionNoOptional = try! db.createFunction("test", deterministic: true) {
11+
func testFunctionNoOptional() throws {
12+
let _: FunctionNoOptional = try db.createFunction("test", deterministic: true) {
1313
"a"
1414
}
15-
let result = try! db.prepare("SELECT test()").scalar() as! String
15+
let result = try db.prepare("SELECT test()").scalar() as! String
1616
XCTAssertEqual("a", result)
1717
}
1818

19-
func testFunctionResultOptional() {
20-
let _: FunctionResultOptional = try! db.createFunction("test", deterministic: true) {
19+
func testFunctionResultOptional() throws {
20+
let _: FunctionResultOptional = try db.createFunction("test", deterministic: true) {
2121
"a"
2222
}
23-
let result = try! db.prepare("SELECT test()").scalar() as! String?
23+
let result = try db.prepare("SELECT test()").scalar() as! String?
2424
XCTAssertEqual("a", result)
2525
}
2626
}
@@ -31,35 +31,35 @@ class CustomFunctionWithOneArgTests: SQLiteTestCase {
3131
typealias FunctionResultOptional = (Expression<String>) -> Expression<String?>
3232
typealias FunctionLeftResultOptional = (Expression<String?>) -> Expression<String?>
3333

34-
func testFunctionNoOptional() {
35-
let _: FunctionNoOptional = try! db.createFunction("test", deterministic: true) { a in
34+
func testFunctionNoOptional() throws {
35+
let _: FunctionNoOptional = try db.createFunction("test", deterministic: true) { a in
3636
"b" + a
3737
}
38-
let result = try! db.prepare("SELECT test(?)").scalar("a") as! String
38+
let result = try db.prepare("SELECT test(?)").scalar("a") as! String
3939
XCTAssertEqual("ba", result)
4040
}
4141

42-
func testFunctionLeftOptional() {
43-
let _: FunctionLeftOptional = try! db.createFunction("test", deterministic: true) { a in
42+
func testFunctionLeftOptional() throws {
43+
let _: FunctionLeftOptional = try db.createFunction("test", deterministic: true) { a in
4444
"b" + a!
4545
}
46-
let result = try! db.prepare("SELECT test(?)").scalar("a") as! String
46+
let result = try db.prepare("SELECT test(?)").scalar("a") as! String
4747
XCTAssertEqual("ba", result)
4848
}
4949

50-
func testFunctionResultOptional() {
51-
let _: FunctionResultOptional = try! db.createFunction("test", deterministic: true) { a in
50+
func testFunctionResultOptional() throws {
51+
let _: FunctionResultOptional = try db.createFunction("test", deterministic: true) { a in
5252
"b" + a
5353
}
54-
let result = try! db.prepare("SELECT test(?)").scalar("a") as! String
54+
let result = try db.prepare("SELECT test(?)").scalar("a") as! String
5555
XCTAssertEqual("ba", result)
5656
}
5757

58-
func testFunctionLeftResultOptional() {
59-
let _: FunctionLeftResultOptional = try! db.createFunction("test", deterministic: true) { (a: String?) -> String? in
58+
func testFunctionLeftResultOptional() throws {
59+
let _: FunctionLeftResultOptional = try db.createFunction("test", deterministic: true) { (a: String?) -> String? in
6060
"b" + a!
6161
}
62-
let result = try! db.prepare("SELECT test(?)").scalar("a") as! String
62+
let result = try db.prepare("SELECT test(?)").scalar("a") as! String
6363
XCTAssertEqual("ba", result)
6464
}
6565
}
@@ -74,76 +74,76 @@ class CustomFunctionWithTwoArgsTests: SQLiteTestCase {
7474
typealias FunctionRightResultOptional = (Expression<String>, Expression<String?>) -> Expression<String?>
7575
typealias FunctionLeftRightResultOptional = (Expression<String?>, Expression<String?>) -> Expression<String?>
7676

77-
func testNoOptional() {
78-
let _: FunctionNoOptional = try! db.createFunction("test", deterministic: true) { a, b in
77+
func testNoOptional() throws {
78+
let _: FunctionNoOptional = try db.createFunction("test", deterministic: true) { a, b in
7979
a + b
8080
}
81-
let result = try! db.prepare("SELECT test(?, ?)").scalar("a", "b") as! String
81+
let result = try db.prepare("SELECT test(?, ?)").scalar("a", "b") as! String
8282
XCTAssertEqual("ab", result)
8383
}
8484

85-
func testLeftOptional() {
86-
let _: FunctionLeftOptional = try! db.createFunction("test", deterministic: true) { a, b in
85+
func testLeftOptional() throws {
86+
let _: FunctionLeftOptional = try db.createFunction("test", deterministic: true) { a, b in
8787
a! + b
8888
}
89-
let result = try! db.prepare("SELECT test(?, ?)").scalar("a", "b") as! String
89+
let result = try db.prepare("SELECT test(?, ?)").scalar("a", "b") as! String
9090
XCTAssertEqual("ab", result)
9191
}
9292

93-
func testRightOptional() {
94-
let _: FunctionRightOptional = try! db.createFunction("test", deterministic: true) { a, b in
93+
func testRightOptional() throws {
94+
let _: FunctionRightOptional = try db.createFunction("test", deterministic: true) { a, b in
9595
a + b!
9696
}
97-
let result = try! db.prepare("SELECT test(?, ?)").scalar("a", "b") as! String
97+
let result = try db.prepare("SELECT test(?, ?)").scalar("a", "b") as! String
9898
XCTAssertEqual("ab", result)
9999
}
100100

101-
func testResultOptional() {
102-
let _: FunctionResultOptional = try! db.createFunction("test", deterministic: true) { a, b in
101+
func testResultOptional() throws {
102+
let _: FunctionResultOptional = try db.createFunction("test", deterministic: true) { a, b in
103103
a + b
104104
}
105-
let result = try! db.prepare("SELECT test(?, ?)").scalar("a", "b") as! String?
105+
let result = try db.prepare("SELECT test(?, ?)").scalar("a", "b") as! String?
106106
XCTAssertEqual("ab", result)
107107
}
108108

109-
func testFunctionLeftRightOptional() {
110-
let _: FunctionLeftRightOptional = try! db.createFunction("test", deterministic: true) { a, b in
109+
func testFunctionLeftRightOptional() throws {
110+
let _: FunctionLeftRightOptional = try db.createFunction("test", deterministic: true) { a, b in
111111
a! + b!
112112
}
113-
let result = try! db.prepare("SELECT test(?, ?)").scalar("a", "b") as! String
113+
let result = try db.prepare("SELECT test(?, ?)").scalar("a", "b") as! String
114114
XCTAssertEqual("ab", result)
115115
}
116116

117-
func testFunctionLeftResultOptional() {
118-
let _: FunctionLeftResultOptional = try! db.createFunction("test", deterministic: true) { a, b in
117+
func testFunctionLeftResultOptional() throws {
118+
let _: FunctionLeftResultOptional = try db.createFunction("test", deterministic: true) { a, b in
119119
a! + b
120120
}
121-
let result = try! db.prepare("SELECT test(?, ?)").scalar("a", "b") as! String?
121+
let result = try db.prepare("SELECT test(?, ?)").scalar("a", "b") as! String?
122122
XCTAssertEqual("ab", result)
123123
}
124124

125-
func testFunctionRightResultOptional() {
126-
let _: FunctionRightResultOptional = try! db.createFunction("test", deterministic: true) { a, b in
125+
func testFunctionRightResultOptional() throws {
126+
let _: FunctionRightResultOptional = try db.createFunction("test", deterministic: true) { a, b in
127127
a + b!
128128
}
129-
let result = try! db.prepare("SELECT test(?, ?)").scalar("a", "b") as! String?
129+
let result = try db.prepare("SELECT test(?, ?)").scalar("a", "b") as! String?
130130
XCTAssertEqual("ab", result)
131131
}
132132

133-
func testFunctionLeftRightResultOptional() {
134-
let _: FunctionLeftRightResultOptional = try! db.createFunction("test", deterministic: true) { a, b in
133+
func testFunctionLeftRightResultOptional() throws {
134+
let _: FunctionLeftRightResultOptional = try db.createFunction("test", deterministic: true) { a, b in
135135
a! + b!
136136
}
137-
let result = try! db.prepare("SELECT test(?, ?)").scalar("a", "b") as! String?
137+
let result = try db.prepare("SELECT test(?, ?)").scalar("a", "b") as! String?
138138
XCTAssertEqual("ab", result)
139139
}
140140
}
141141

142142
class CustomFunctionTruncation: SQLiteTestCase {
143143
// https://github.com/stephencelis/SQLite.swift/issues/468
144-
func testStringTruncation() {
145-
_ = try! db.createFunction("customLower") { (value: String) in value.lowercased() }
146-
let result = try! db.prepare("SELECT customLower(?)").scalar("TÖL-AA 12") as? String
144+
func testStringTruncation() throws {
145+
_ = try db.createFunction("customLower") { (value: String) in value.lowercased() }
146+
let result = try db.prepare("SELECT customLower(?)").scalar("TÖL-AA 12") as? String
147147
XCTAssertEqual("töl-aa 12", result)
148148
}
149149
}

0 commit comments

Comments
 (0)