Skip to content

Commit 22e581c

Browse files
committed
Fix tests in 6.0
1 parent 39b3632 commit 22e581c

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

Tests/FluentPostgresDriverTests/FluentPostgresDriverTests.swift

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,24 +102,25 @@ struct FluentPostgresDriverTests {
102102
init() {
103103
#expect(isLoggingConfigured)
104104
}
105-
105+
106+
#if !compiler(<6.1) // #expect(throws:) doesn't return the Error until 6.1
106107
@Test
107108
func databaseError() async throws {
108109
try await withDbs { dbs, db in
109110
let sql1 = (db as! any SQLDatabase)
110-
let error = await #expect(throws: (any Error).self) { try await sql1.raw("asdf").run() }
111-
#expect((error as? any DatabaseError)?.isSyntaxError ?? false, "\(String(reflecting: error))")
112-
#expect(!((error as? any DatabaseError)?.isConstraintFailure ?? true), "\(String(reflecting: error))")
113-
#expect(!((error as? any DatabaseError)?.isConnectionClosed ?? true), "\(String(reflecting: error))")
111+
let error1 = await #expect(throws: (any Error).self) { try await sql1.raw("asdf").run() }
112+
#expect((error1 as? any DatabaseError)?.isSyntaxError ?? false, "\(String(reflecting: error1))")
113+
#expect(!((error1 as? any DatabaseError)?.isConstraintFailure ?? true), "\(String(reflecting: error1))")
114+
#expect(!((error1 as? any DatabaseError)?.isConnectionClosed ?? true), "\(String(reflecting: error1))")
114115

115116
let sql2 = (dbs.database(.a, logger: .init(label: "test.fluent.a"), on: dbs.eventLoopGroup.any())!) as! any SQLDatabase
116117
try await sql2.drop(table: "foo").ifExists().run()
117118
try await sql2.create(table: "foo").column("name", type: .text, .unique).run()
118119
try await sql2.insert(into: "foo").columns("name").values("bar").run()
119-
await #expect(throws: (any Error).self) { try await sql2.insert(into: "foo").columns("name").values("bar").run() }
120-
#expect((error as? any DatabaseError)?.isSyntaxError ?? false, "\(String(reflecting: error))")
121-
#expect(!((error as? any DatabaseError)?.isConstraintFailure ?? true), "\(String(reflecting: error))")
122-
#expect(!((error as? any DatabaseError)?.isConnectionClosed ?? true), "\(String(reflecting: error))")
120+
let error2 = await #expect(throws: (any Error).self) { try await sql2.insert(into: "foo").columns("name").values("bar").run() }
121+
#expect((error2 as? any DatabaseError)?.isSyntaxError ?? false, "\(String(reflecting: error2))")
122+
#expect(!((error2 as? any DatabaseError)?.isConstraintFailure ?? true), "\(String(reflecting: error2))")
123+
#expect(!((error2 as? any DatabaseError)?.isConnectionClosed ?? true), "\(String(reflecting: error2))")
123124
}
124125

125126
// Disabled until we figure out why it hangs instead of throwing an error.
@@ -134,6 +135,7 @@ struct FluentPostgresDriverTests {
134135
// XCTAssertFalse(($0 as? any DatabaseError)?.isConstraintFailure ?? true, "\(String(reflecting: $0))")
135136
//}
136137
}
138+
#endif
137139

138140
@Test
139141
func blob() async throws {

Tests/FluentPostgresDriverTests/FluentPostgresTransactionControlTests.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ extension AllSuites {
66
struct FluentPostgresTransactionControlTests {
77
init() { #expect(isLoggingConfigured) }
88

9+
#if !compiler(<6.1) // #expect(throws:) doesn't return the Error until 6.1
910
@Test
1011
func rollback() async throws {
1112
try await withDbs { _, db in try await db.withConnection { db in
@@ -26,7 +27,8 @@ struct FluentPostgresTransactionControlTests {
2627
try await CreateTodo().revert(on: db)
2728
} }
2829
}
29-
30+
#endif
31+
3032
final class Todo: Model, @unchecked Sendable {
3133
static let schema = "todos"
3234
@ID var id

0 commit comments

Comments
 (0)