Swift 5.7 required: Remove compiler checks

This commit is contained in:
Gwendal Roué committed 2022-08-21 19:21:57 +02:00
1 parent fcb037bdf0
commit 6da7d47394
30 files changed
+35 -549

No files matched your search

-2
View File
@@ -158,10 +158,8 @@ public final class DatabasePool: DatabaseWriter {
}
}
#if swift(>=5.6) && canImport(_Concurrency)
// @unchecked because of databaseSnapshotCount and readerPool
extension DatabasePool: @unchecked Sendable { }
#endif
extension DatabasePool {
-2
View File
@@ -371,7 +371,6 @@ extension DatabaseReader {
}
}
#if compiler(>=5.6) && canImport(_Concurrency)
extension DatabaseReader {
// MARK: - Asynchronous Database Access
@@ -465,7 +464,6 @@ extension DatabaseReader {
}
}
}
#endif
#if canImport(Combine)
extension DatabaseReader {
-2
View File
@@ -356,13 +356,11 @@ public protocol DatabaseRegionConvertible {
func databaseRegion(_ db: Database) throws -> DatabaseRegion
}
#if compiler(>=5.5)
extension DatabaseRegionConvertible where Self == DatabaseRegion {
/// The region that covers the full database: all columns and all rows
/// from all tables.
public static var fullDatabase: Self { DatabaseRegion.fullDatabase }
}
#endif
extension DatabaseRegion: DatabaseRegionConvertible {
/// :nodoc:
-2
View File
@@ -159,11 +159,9 @@ extension DatabaseValue: StatementBinding {
extension DatabaseValue: Sendable { }
#if swift(>=5.6) && canImport(_Concurrency)
// @unchecked due to Foundation.Data not conforming to Sendable
// TODO: Remove @unchecked when Foundation has been upgraded
extension DatabaseValue.Storage: @unchecked Sendable { }
#endif
// MARK: - Hashable & Equatable
-3
View File
@@ -380,7 +380,6 @@ extension DatabaseWriter {
}
}
#if compiler(>=5.6) && canImport(_Concurrency)
extension DatabaseWriter {
// MARK: - Asynchronous Database Access
@@ -491,8 +490,6 @@ extension DatabaseWriter {
}
}
}
#endif
#if canImport(Combine)
extension DatabaseWriter {
-3
View File
@@ -2182,12 +2182,9 @@ struct ArrayRowImpl: RowImpl {
}
}
#if swift(>=5.6) && canImport(_Concurrency)
// @unchecked because columns property is not inferred as Sendable
// TODO: remove this @unchecked when compiler can handle tuples.
extension ArrayRowImpl: @unchecked Sendable { }
#endif
// TODO: merge with ArrayRowImpl eventually?
/// See Row.init(copiedFromStatementRef:sqliteStatement:)
-2
View File
@@ -249,9 +249,7 @@ final class SerializedDatabase {
}
}
#if swift(>=5.6) && canImport(_Concurrency)
// @unchecked because the wrapped `Database` itself is not Sendable.
// It happens the job of SerializedDatabase is precisely to provide thread-safe
// access to `Database`.
extension SerializedDatabase: @unchecked Sendable { }
#endif
@@ -459,11 +459,7 @@ extension TableRequest where Self: AggregatingRequest {
return [Column(rowIDColumn)]
} else if primaryKey.tableHasRowID {
// Prefer the rowid
#if compiler(>=5.5)
return [.rowID]
#else
return [Column.rowID]
#endif
} else {
// WITHOUT ROWID table: group by primary key columns
return primaryKey.columns.map { Column($0) }
-2
View File
@@ -52,12 +52,10 @@ extension ColumnExpression {
}
}
#if compiler(>=5.5)
extension ColumnExpression where Self == Column {
/// The hidden rowID column
public static var rowID: Self { Column.rowID }
}
#endif
/// A column in a database table.
///
@@ -1667,12 +1667,10 @@ public protocol SQLExpressible {
var sqlExpression: SQLExpression { get }
}
#if compiler(>=5.5)
extension SQLExpressible where Self == Column {
/// The hidden rowID column
public static var rowID: Self { Column.rowID }
}
#endif
/// `SQLSpecificExpressible` is a protocol for all database-specific types that
/// can be turned into an SQL expression. Types whose existence is not purely
@@ -299,7 +299,6 @@ public final class SharedValueObservation<Element> {
}
}
#if compiler(>=5.6) && canImport(_Concurrency)
extension SharedValueObservation {
// MARK: - Asynchronous Observation
/// The database observation, as an asynchronous sequence of
@@ -315,4 +314,3 @@ extension SharedValueObservation {
}
}
}
#endif
@@ -252,7 +252,6 @@ extension ValueObservation: Refinable {
}
}
#if compiler(>=5.6) && canImport(_Concurrency)
extension ValueObservation {
// MARK: - Asynchronous Observation
/// The database observation, as an asynchronous sequence of
@@ -350,7 +349,6 @@ public struct AsyncValueObservation<Element>: AsyncSequence {
}
}
}
#endif
#if canImport(Combine)
extension ValueObservation {
-29
View File
@@ -51,7 +51,6 @@ final class Test<Context> {
}
}
#if compiler(>=5.6) && canImport(_Concurrency)
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
final class AsyncTest<Context> {
// Raise the repeatCount in order to help spotting flaky tests.
@@ -100,9 +99,7 @@ final class AsyncTest<Context> {
}
}
}
#endif
#if compiler(>=5.3)
@available(OSX 10.15, iOS 13, tvOS 13, watchOS 6, *)
public func assertNoFailure<Failure>(
_ completion: Subscribers.Completion<Failure>,
@@ -127,31 +124,5 @@ public func assertFailure<Failure, ExpectedFailure>(
XCTFail("Expected \(ExpectedFailure.self), got \(completion)", file: file, line: line)
}
}
#else
@available(OSX 10.15, iOS 13, tvOS 13, watchOS 6, *)
public func assertNoFailure<Failure>(
_ completion: Subscribers.Completion<Failure>,
file: StaticString = #file,
line: UInt = #line)
{
if case let .failure(error) = completion {
XCTFail("Unexpected completion failure: \(error)", file: file, line: line)
}
}
@available(OSX 10.15, iOS 13, tvOS 13, watchOS 6, *)
public func assertFailure<Failure, ExpectedFailure>(
_ completion: Subscribers.Completion<Failure>,
file: StaticString = #file,
line: UInt = #line,
test: (ExpectedFailure) -> Void)
{
if case let .failure(error) = completion, let expectedError = error as? ExpectedFailure {
test(expectedError)
} else {
XCTFail("Expected \(ExpectedFailure.self), got \(completion)", file: file, line: line)
}
}
#endif
#endif
@@ -9,11 +9,11 @@ private struct CompoundPrimaryKey: TableRecord { }
private struct CompoundPrimaryKeyChild: TableRecord { }
class AssociationPrefetchingObservationTests: GRDBTestCase {
private func _assertRequestRegionEqual<T>(
private func assertRequestRegionEqual<T>(
_ db: Database,
_ request: QueryInterfaceRequest<T>,
_ expectedDescriptions: [String],
file: StaticString, line: UInt) throws
_ expectedDescriptions: String...,
file: StaticString = #filePath, line: UInt = #line) throws
{
// Test DatabaseRegionConvertible
do {
@@ -31,27 +31,6 @@ class AssociationPrefetchingObservationTests: GRDBTestCase {
}
}
// #file vs. #filePath dance
#if compiler(>=5.3)
private func assertRequestRegionEqual<T>(
_ db: Database,
_ request: QueryInterfaceRequest<T>,
_ expectedDescriptions: String...,
file: StaticString = #filePath, line: UInt = #line) throws
{
try _assertRequestRegionEqual(db, request, expectedDescriptions, file: file, line: line)
}
#else
private func assertRequestRegionEqual<T>(
_ db: Database,
_ request: QueryInterfaceRequest<T>,
_ expectedDescriptions: String...,
file: StaticString = #file, line: UInt = #line) throws
{
try _assertRequestRegionEqual(db, request, expectedDescriptions, file: file, line: line)
}
#endif
override func setup(_ dbWriter: DatabaseWriter) throws {
try dbWriter.write { db in
try db.create(table: "a") { t in
+1 -6
View File
@@ -30,7 +30,6 @@ class DatabaseReaderTests : GRDBTestCase {
try test(setup(makeDatabasePool()).makeSnapshot())
}
#if compiler(>=5.6) && canImport(_Concurrency)
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
func testAsyncAwait_ReadCanRead() async throws {
func setup<T: DatabaseWriter>(_ dbWriter: T) throws -> T {
@@ -50,7 +49,6 @@ class DatabaseReaderTests : GRDBTestCase {
try await test(setup(makeDatabasePool()))
try await test(setup(makeDatabasePool()).makeSnapshot())
}
#endif
func testReadPreventsDatabaseModification() throws {
func test(_ dbReader: DatabaseReader) throws {
@@ -68,7 +66,6 @@ class DatabaseReaderTests : GRDBTestCase {
try test(makeDatabasePool().makeSnapshot())
}
#if compiler(>=5.6) && canImport(_Concurrency)
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
func testAsyncAwait_ReadPreventsDatabaseModification() async throws {
func test(_ dbReader: DatabaseReader) async throws {
@@ -85,7 +82,7 @@ class DatabaseReaderTests : GRDBTestCase {
try await test(makeDatabasePool())
try await test(makeDatabasePool().makeSnapshot())
}
#endif
// MARK: - UnsafeRead
func testUnsafeReadCanRead() throws {
@@ -107,7 +104,6 @@ class DatabaseReaderTests : GRDBTestCase {
try test(setup(makeDatabasePool()).makeSnapshot())
}
#if compiler(>=5.6) && canImport(_Concurrency)
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
func testAsyncAwait_UnsafeReadCanRead() async throws {
func setup<T: DatabaseWriter>(_ dbWriter: T) throws -> T {
@@ -127,7 +123,6 @@ class DatabaseReaderTests : GRDBTestCase {
try await test(setup(makeDatabasePool()))
try await test(setup(makeDatabasePool()).makeSnapshot())
}
#endif
// MARK: - UnsafeReentrantRead
@@ -34,14 +34,14 @@ private let jpegData = try! Data(contentsOf: Bundle(for: DatabaseValueConversion
class DatabaseValueConversionTests : GRDBTestCase {
private func _assertDecoding<T: DatabaseValueConvertible & StatementColumnConvertible & Equatable>(
private func assertDecoding<T: DatabaseValueConvertible & StatementColumnConvertible & Equatable>(
_ db: Database,
_ sql: String,
_ type: T.Type,
expectedSQLiteConversion: T?,
expectedDatabaseValueConversion: T?,
file: StaticString,
line: UInt) throws
file: StaticString = #filePath,
line: UInt = #line) throws
{
func stringRepresentation(_ value: T?) -> String {
guard let value = value else { return "nil" }
@@ -86,12 +86,12 @@ class DatabaseValueConversionTests : GRDBTestCase {
}
}
private func _assertFailedDecoding<T: DatabaseValueConvertible>(
private func assertFailedDecoding<T: DatabaseValueConvertible>(
_ db: Database,
_ sql: String,
_ type: T.Type,
file: StaticString,
line: UInt) throws
file: StaticString = #filePath,
line: UInt = #line) throws
{
// We can only test failed decoding from database value, since
// StatementColumnConvertible only supports optimistic decoding which
@@ -100,61 +100,6 @@ class DatabaseValueConversionTests : GRDBTestCase {
XCTAssertNil(T.fromDatabaseValue(dbValue), file: file, line: line)
}
// #file vs. #filePath dance
#if compiler(>=5.3)
private func assertDecoding<T: DatabaseValueConvertible & StatementColumnConvertible & Equatable>(
_ db: Database,
_ sql: String,
_ type: T.Type,
expectedSQLiteConversion: T?,
expectedDatabaseValueConversion: T?,
file: StaticString = #filePath,
line: UInt = #line) throws
{
try _assertDecoding(
db, sql, type,
expectedSQLiteConversion: expectedSQLiteConversion,
expectedDatabaseValueConversion: expectedDatabaseValueConversion,
file: file, line: line)
}
private func assertFailedDecoding<T: DatabaseValueConvertible>(
_ db: Database,
_ sql: String,
_ type: T.Type,
file: StaticString = #filePath,
line: UInt = #line) throws
{
try _assertFailedDecoding(db, sql, type, file: file, line: line)
}
#else
private func assertDecoding<T: DatabaseValueConvertible & StatementColumnConvertible & Equatable>(
_ db: Database,
_ sql: String,
_ type: T.Type,
expectedSQLiteConversion: T?,
expectedDatabaseValueConversion: T?,
file: StaticString = #file,
line: UInt = #line) throws
{
try _assertDecoding(
db, sql, type,
expectedSQLiteConversion: expectedSQLiteConversion,
expectedDatabaseValueConversion: expectedDatabaseValueConversion,
file: file, line: line)
}
private func assertFailedDecoding<T: DatabaseValueConvertible>(
_ db: Database,
_ sql: String,
_ type: T.Type,
file: StaticString = #file,
line: UInt = #line) throws
{
try _assertFailedDecoding(db, sql, type, file: file, line: line)
}
#endif
// Datatypes In SQLite Version 3: https://www.sqlite.org/datatype3.html
override func setup(_ dbWriter: DatabaseWriter) throws {
-12
View File
@@ -266,7 +266,6 @@ class DatabaseWriterTests : GRDBTestCase {
try DatabaseQueue().backup(to: dbQueue)
}
#if compiler(>=5.6) && canImport(_Concurrency)
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
func testAsyncAwait_write() async throws {
func setup<T: DatabaseWriter>(_ dbWriter: T) throws -> T {
@@ -286,9 +285,7 @@ class DatabaseWriterTests : GRDBTestCase {
try await test(setup(makeDatabaseQueue()))
try await test(setup(makeDatabasePool()))
}
#endif
#if compiler(>=5.6) && canImport(_Concurrency)
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
func testAsyncAwait_writeWithoutTransaction() async throws {
func setup<T: DatabaseWriter>(_ dbWriter: T) throws -> T {
@@ -311,9 +308,7 @@ class DatabaseWriterTests : GRDBTestCase {
try await test(setup(makeDatabaseQueue()))
try await test(setup(makeDatabasePool()))
}
#endif
#if compiler(>=5.6) && canImport(_Concurrency)
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
func testAsyncAwait_barrierWriteWithoutTransaction() async throws {
func setup<T: DatabaseWriter>(_ dbWriter: T) throws -> T {
@@ -336,9 +331,7 @@ class DatabaseWriterTests : GRDBTestCase {
try await test(setup(makeDatabaseQueue()))
try await test(setup(makeDatabasePool()))
}
#endif
#if compiler(>=5.6) && canImport(_Concurrency)
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
func testAsyncAwait_erase() async throws {
func setup<T: DatabaseWriter>(_ dbWriter: T) throws -> T {
@@ -356,9 +349,7 @@ class DatabaseWriterTests : GRDBTestCase {
try await test(setup(makeDatabaseQueue()))
try await test(setup(makeDatabasePool()))
}
#endif
#if compiler(>=5.6) && canImport(_Concurrency)
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
func testAsyncAwait_vacuum() async throws {
func setup<T: DatabaseWriter>(_ dbWriter: T) throws -> T {
@@ -374,9 +365,7 @@ class DatabaseWriterTests : GRDBTestCase {
try await test(setup(makeDatabaseQueue()))
try await test(setup(makeDatabasePool()))
}
#endif
#if compiler(>=5.6) && canImport(_Concurrency)
@available(macOS 10.16, iOS 14, tvOS 14, watchOS 7, *) // async + vacuum into
func testAsyncAwait_vacuumInto() async throws {
// Prevent SQLCipher failures
@@ -406,5 +395,4 @@ class DatabaseWriterTests : GRDBTestCase {
try await test(setup(makeDatabaseQueue()))
try await test(setup(makeDatabasePool()))
}
#endif
}
@@ -25,17 +25,9 @@ private struct Book: FetchableRecord, PersistableRecord, Codable {
static let databaseTableName = "book"
static let author = belongsTo(Author.self)
#if compiler(>=5.5)
static let bookFts4 = hasOne(BookFts4.self, using: ForeignKey([.rowID]))
#else
static let bookFts4 = hasOne(BookFts4.self, using: ForeignKey([Column.rowID]))
#endif
#if SQLITE_ENABLE_FTS5
#if compiler(>=5.5)
static let bookFts5 = hasOne(BookFts5.self, using: ForeignKey([.rowID]))
#else
static let bookFts5 = hasOne(BookFts5.self, using: ForeignKey([Column.rowID]))
#endif
#endif
var author: QueryInterfaceRequest<Author> { request(for: Book.author) }
-8
View File
@@ -10,11 +10,7 @@ private struct Book {
extension Book : FetchableRecord {
init(row: Row) {
#if compiler(>=5.5)
id = row[.rowID]
#else
id = row[Column.rowID]
#endif
title = row["title"]
author = row["author"]
body = row["body"]
@@ -26,11 +22,7 @@ extension Book : MutablePersistableRecord {
static let databaseSelection: [SQLSelectable] = [AllColumns(), Column.rowID]
func encode(to container: inout PersistenceContainer) {
#if compiler(>=5.5)
container[.rowID] = id
#else
container[Column.rowID] = id
#endif
container["title"] = title
container["author"] = author
container["body"] = body
-8
View File
@@ -10,11 +10,7 @@ private struct Book {
extension Book : FetchableRecord {
init(row: Row) {
#if compiler(>=5.5)
id = row[.rowID]
#else
id = row[Column.rowID]
#endif
title = row["title"]
author = row["author"]
body = row["body"]
@@ -26,11 +22,7 @@ extension Book : MutablePersistableRecord {
static let databaseSelection: [SQLSelectable] = [AllColumns(), Column.rowID]
func encode(to container: inout PersistenceContainer) {
#if compiler(>=5.5)
container[.rowID] = id
#else
container[Column.rowID] = id
#endif
container["title"] = title
container["author"] = author
container["body"] = body
-8
View File
@@ -11,11 +11,7 @@ private struct Book {
extension Book : FetchableRecord {
init(row: Row) {
#if compiler(>=5.5)
id = row[.rowID]
#else
id = row[Column.rowID]
#endif
title = row["title"]
author = row["author"]
body = row["body"]
@@ -27,11 +23,7 @@ extension Book : MutablePersistableRecord {
static let databaseSelection: [SQLSelectable] = [AllColumns(), Column.rowID]
func encode(to container: inout PersistenceContainer) {
#if compiler(>=5.5)
container[.rowID] = id
#else
container[Column.rowID] = id
#endif
container["title"] = title
container["author"] = author
container["body"] = body
-72
View File
@@ -4,16 +4,8 @@ import XCTest
/// A XCTestCase subclass that can test its own failures.
class FailureTestCase: XCTestCase {
private struct Failure: Hashable {
#if compiler(>=5.3)
let issue: XCTIssue
#else
var description: String
var file: String
var line: Int
var expected: Bool
#endif
#if compiler(>=5.3)
func issue(prefix: String = "") -> XCTIssue {
if prefix.isEmpty {
return issue
@@ -27,22 +19,10 @@ class FailureTestCase: XCTestCase {
attachments: issue.attachments)
}
}
#else
func failure(prefix: String = "") -> (description: String, file: String, line: Int, expected: Bool) {
let prefix = prefix.isEmpty ? "" : "\(prefix): "
return (
description: prefix + description,
file: file,
line: line,
expected: expected)
}
#endif
#if compiler(>=5.3)
private var description: String {
return issue.compactDescription
}
#endif
func hash(into hasher: inout Hasher) {
hasher.combine(0)
@@ -60,7 +40,6 @@ class FailureTestCase: XCTestCase {
let recordedFailures = try recordingFailures(execute)
if prefixes.isEmpty {
if recordedFailures.isEmpty {
#if compiler(>=5.3)
record(XCTIssue(
type: .assertionFailure,
compactDescription: "No failure did happen",
@@ -71,17 +50,9 @@ class FailureTestCase: XCTestCase {
lineNumber: Int(line))),
associatedError: nil,
attachments: []))
#else
recordFailure(
withDescription: "No failure did happen",
inFile: file.description,
atLine: Int(line),
expected: true)
#endif
}
} else {
let expectedFailures = prefixes.map { prefix -> Failure in
#if compiler(>=5.3)
return Failure(issue: XCTIssue(
type: .assertionFailure,
compactDescription: prefix,
@@ -92,13 +63,6 @@ class FailureTestCase: XCTestCase {
lineNumber: Int(line))),
associatedError: nil,
attachments: []))
#else
return Failure(
description: prefix,
file: String(describing: file),
line: Int(line),
expected: true)
#endif
}
assertMatch(
recordedFailures: recordedFailures,
@@ -112,7 +76,6 @@ class FailureTestCase: XCTestCase {
recordedFailures = []
}
#if compiler(>=5.3)
override func record(_ issue: XCTIssue) {
if isRecordingFailures {
recordedFailures.append(Failure(issue: issue))
@@ -120,23 +83,6 @@ class FailureTestCase: XCTestCase {
super.record(issue)
}
}
#else
override func recordFailure(withDescription description: String, inFile filePath: String, atLine lineNumber: Int, expected: Bool) {
if isRecordingFailures {
recordedFailures.append(Failure(
description: description,
file: filePath,
line: lineNumber,
expected: expected))
} else {
super.recordFailure(
withDescription: description,
inFile: filePath,
atLine: lineNumber,
expected: expected)
}
}
#endif
private func recordingFailures(_ execute: () throws -> Void) rethrows -> [Failure] {
let oldRecordingFailures = isRecordingFailures
@@ -161,16 +107,7 @@ class FailureTestCase: XCTestCase {
if let index = expectedFailures.firstIndex(of: failure) {
expectedFailures.remove(at: index)
} else {
#if compiler(>=5.3)
record(failure.issue())
#else
let failure = failure.failure()
recordFailure(
withDescription: failure.description,
inFile: failure.file,
atLine: failure.line,
expected: failure.expected)
#endif
}
}
@@ -179,16 +116,7 @@ class FailureTestCase: XCTestCase {
if let index = recordedFailures.firstIndex(of: failure) {
recordedFailures.remove(at: index)
} else {
#if compiler(>=5.3)
record(failure.issue(prefix: "Failure did not happen"))
#else
let failure = failure.failure(prefix: "Failure did not happen")
recordFailure(
withDescription: failure.description,
inFile: failure.file,
atLine: failure.line,
expected: failure.expected)
#endif
}
}
}
+1 -12
View File
@@ -3,7 +3,7 @@ import XCTest
class ForeignKeyInfoTests: GRDBTestCase {
private func _assertEqual(_ lhs: ForeignKeyInfo, _ rhs: ForeignKeyInfo, file: StaticString, line: UInt) {
private func assertEqual(_ lhs: ForeignKeyInfo, _ rhs: ForeignKeyInfo, file: StaticString = #filePath, line: UInt = #line) {
XCTAssertEqual(lhs.destinationTable, rhs.destinationTable, file: file, line: line)
XCTAssertEqual(lhs.mapping.count, rhs.mapping.count, file: file, line: line)
for (larrow, rarrow) in zip(lhs.mapping, rhs.mapping) {
@@ -12,17 +12,6 @@ class ForeignKeyInfoTests: GRDBTestCase {
}
}
// #file vs. #filePath dance
#if compiler(>=5.3)
private func assertEqual(_ lhs: ForeignKeyInfo, _ rhs: ForeignKeyInfo, file: StaticString = #filePath, line: UInt = #line) {
_assertEqual(lhs, rhs, file: file, line: line)
}
#else
private func assertEqual(_ lhs: ForeignKeyInfo, _ rhs: ForeignKeyInfo, file: StaticString = #file, line: UInt = #line) {
_assertEqual(lhs, rhs, file: file, line: line)
}
#endif
func testForeignKeys() throws {
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
@@ -349,7 +349,7 @@ class FoundationDateComponentsTests : GRDBTestCase {
}
func testDatabaseDateComponentsParsing() {
func _assertParse(_ string: String, _ dateComponent: DatabaseDateComponents, file: StaticString, line: UInt) {
func assertParse(_ string: String, _ dateComponent: DatabaseDateComponents, file: StaticString = #filePath, line: UInt = #line) {
do {
// Test DatabaseValueConvertible adoption
guard let parsed = DatabaseDateComponents.fromDatabaseValue(string.databaseValue) else {
@@ -372,17 +372,6 @@ class FoundationDateComponentsTests : GRDBTestCase {
}
}
// #file vs. #filePath dance
#if compiler(>=5.3)
func assertParse(_ string: String, _ dateComponent: DatabaseDateComponents, file: StaticString = #filePath, line: UInt = #line) {
_assertParse(string, dateComponent, file: file, line: line)
}
#else
func assertParse(_ string: String, _ dateComponent: DatabaseDateComponents, file: StaticString = #file, line: UInt = #line) {
_assertParse(string, dateComponent, file: file, line: line)
}
#endif
assertParse(
"0000-01-01",
DatabaseDateComponents(
+6 -52
View File
@@ -322,12 +322,12 @@ class FoundationDateTests : GRDBTestCase {
return
}
func _assert(
func assert(
_ db: Database,
_ expression: SQLExpression,
equal expectedDate: Date,
file: StaticString,
line: UInt) throws
file: StaticString = #filePath,
line: UInt = #line) throws
{
let request: SQLRequest<Double> = "SELECT \(expression)"
guard let shiftedDate = try request.fetchOne(db).flatMap(Date.init(julianDay:)) else {
@@ -339,29 +339,6 @@ class FoundationDateTests : GRDBTestCase {
XCTAssertEqual(shiftedInterval, expectedInterval, accuracy: 0.1, file: file, line: line)
}
// #file vs. #filePath dance
#if compiler(>=5.3)
func assert(
_ db: Database,
_ expression: SQLExpression,
equal expectedDate: Date,
file: StaticString = #filePath,
line: UInt = #line) throws
{
try _assert(db, expression, equal: expectedDate, file: file, line: line)
}
#else
func assert(
_ db: Database,
_ expression: SQLExpression,
equal expectedDate: Date,
file: StaticString = #file,
line: UInt = #line) throws
{
try _assert(db, expression, equal: expectedDate, file: file, line: line)
}
#endif
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
let dbDate = date.databaseValue
@@ -394,12 +371,12 @@ class FoundationDateTests : GRDBTestCase {
return
}
func _assert(
func assert(
_ db: Database,
_ expression: SQLExpression,
equal expectedDate: String,
file: StaticString,
line: UInt) throws
file: StaticString = #filePath,
line: UInt = #line) throws
{
let request: SQLRequest<String> = "SELECT \(expression)"
guard let shiftedDate = try request.fetchOne(db) else {
@@ -409,29 +386,6 @@ class FoundationDateTests : GRDBTestCase {
XCTAssertEqual(shiftedDate, expectedDate, file: file, line: line)
}
// #file vs. #filePath dance
#if compiler(>=5.3)
func assert(
_ db: Database,
_ expression: SQLExpression,
equal expectedDate: String,
file: StaticString = #filePath,
line: UInt = #line) throws
{
try _assert(db, expression, equal: expectedDate, file: file, line: line)
}
#else
func assert(
_ db: Database,
_ expression: SQLExpression,
equal expectedDate: String,
file: StaticString = #file,
line: UInt = #line) throws
{
try _assert(db, expression, equal: expectedDate, file: file, line: line)
}
#endif
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
let dbDate = date.databaseValue
+6 -65
View File
@@ -121,7 +121,7 @@ class GRDBTestCase: XCTestCase {
do { try FileManager.default.removeItem(atPath: dbDirectoryPath) } catch { }
}
private func _assertNoError(file: StaticString, line: UInt, _ test: () throws -> Void) {
func assertNoError(file: StaticString = #filePath, line: UInt = #line, _ test: () throws -> Void) {
do {
try test()
} catch {
@@ -129,93 +129,36 @@ class GRDBTestCase: XCTestCase {
}
}
private func _assertDidExecute(sql: String, file: StaticString, line: UInt) {
func assertDidExecute(sql: String, file: StaticString = #filePath, line: UInt = #line) {
XCTAssertTrue(sqlQueries.contains(sql), "Did not execute \(sql)", file: file, line: line)
}
private func _assert(_ record: EncodableRecord, isEncodedIn row: Row, file: StaticString, line: UInt) {
func assert(_ record: EncodableRecord, isEncodedIn row: Row, file: StaticString = #filePath, line: UInt = #line) {
let recordDict = record.databaseDictionary
let rowDict = Dictionary(row, uniquingKeysWith: { (left, _) in left })
XCTAssertEqual(recordDict, rowDict, file: file, line: line)
}
// Compare SQL strings (ignoring leading and trailing white space and semicolons.
private func _assertEqualSQL(_ lhs: String, _ rhs: String, file: StaticString, line: UInt) {
func assertEqualSQL(_ lhs: String, _ rhs: String, file: StaticString = #filePath, line: UInt = #line) {
// Trim white space and ";"
let cs = CharacterSet.whitespacesAndNewlines.union(CharacterSet(charactersIn: ";"))
XCTAssertEqual(lhs.trimmingCharacters(in: cs), rhs.trimmingCharacters(in: cs), file: file, line: line)
}
// Compare SQL strings (ignoring leading and trailing white space and semicolons.
private func _assertEqualSQL<Request: FetchRequest>(_ db: Database, _ request: Request, _ sql: String, file: StaticString, line: UInt) throws {
func assertEqualSQL<Request: FetchRequest>(_ db: Database, _ request: Request, _ sql: String, file: StaticString = #filePath, line: UInt = #line) throws {
try request.makeStatement(db).makeCursor().next()
assertEqualSQL(lastSQLQuery!, sql, file: file, line: line)
}
// Compare SQL strings (ignoring leading and trailing white space and semicolons.
private func _assertEqualSQL<Request: FetchRequest>(_ databaseReader: DatabaseReader, _ request: Request, _ sql: String, file: StaticString, line: UInt) throws {
func assertEqualSQL<Request: FetchRequest>(_ databaseReader: DatabaseReader, _ request: Request, _ sql: String, file: StaticString = #filePath, line: UInt = #line) throws {
try databaseReader.unsafeRead { db in
try assertEqualSQL(db, request, sql, file: file, line: line)
}
}
// #file vs. #filePath dance
#if compiler(>=5.3)
func assertNoError(file: StaticString = #filePath, line: UInt = #line, _ test: () throws -> Void) {
_assertNoError(file: file, line: line, test)
}
func assertDidExecute(sql: String, file: StaticString = #filePath, line: UInt = #line) {
_assertDidExecute(sql: sql, file: file, line: line)
}
func assert(_ record: EncodableRecord, isEncodedIn row: Row, file: StaticString = #filePath, line: UInt = #line) {
_assert(record, isEncodedIn: row, file: file, line: line)
}
// Compare SQL strings (ignoring leading and trailing white space and semicolons.
func assertEqualSQL(_ lhs: String, _ rhs: String, file: StaticString = #filePath, line: UInt = #line) {
_assertEqualSQL(lhs, rhs, file: file, line: line)
}
// Compare SQL strings (ignoring leading and trailing white space and semicolons.
func assertEqualSQL<Request: FetchRequest>(_ db: Database, _ request: Request, _ sql: String, file: StaticString = #filePath, line: UInt = #line) throws {
try _assertEqualSQL(db, request, sql, file: file, line: line)
}
// Compare SQL strings (ignoring leading and trailing white space and semicolons.
func assertEqualSQL<Request: FetchRequest>(_ databaseReader: DatabaseReader, _ request: Request, _ sql: String, file: StaticString = #filePath, line: UInt = #line) throws {
try _assertEqualSQL(databaseReader, request, sql, file: file, line: line)
}
#else
func assertNoError(file: StaticString = #file, line: UInt = #line, _ test: () throws -> Void) {
_assertNoError(file: file, line: line, test)
}
func assertDidExecute(sql: String, file: StaticString = #file, line: UInt = #line) {
_assertDidExecute(sql: sql, file: file, line: line)
}
func assert(_ record: EncodableRecord, isEncodedIn row: Row, file: StaticString = #file, line: UInt = #line) {
_assert(record, isEncodedIn: row, file: file, line: line)
}
// Compare SQL strings (ignoring leading and trailing white space and semicolons.
func assertEqualSQL(_ lhs: String, _ rhs: String, file: StaticString = #file, line: UInt = #line) {
_assertEqualSQL(lhs, rhs, file: file, line: line)
}
// Compare SQL strings (ignoring leading and trailing white space and semicolons.
func assertEqualSQL<Request: FetchRequest>(_ db: Database, _ request: Request, _ sql: String, file: StaticString = #file, line: UInt = #line) throws {
try _assertEqualSQL(db, request, sql, file: file, line: line)
}
// Compare SQL strings (ignoring leading and trailing white space and semicolons.
func assertEqualSQL<Request: FetchRequest>(_ databaseReader: DatabaseReader, _ request: Request, _ sql: String, file: StaticString = #file, line: UInt = #line) throws {
try _assertEqualSQL(databaseReader, request, sql, file: file, line: line)
}
#endif
func sql<Request: FetchRequest>(_ databaseReader: DatabaseReader, _ request: Request) -> String {
try! databaseReader.unsafeRead { db in
try request.makeStatement(db).makeCursor().next()
@@ -259,7 +202,5 @@ public struct AnyValueReducer<Fetched, Value>: ValueReducer {
}
}
#if swift(>=5.6) && canImport(_Concurrency)
// Assume this is correct :-/
extension XCTestExpectation: @unchecked Sendable { }
#endif
@@ -36,11 +36,7 @@ private class Person : Record, Hashable {
}
required init(row: Row) {
#if compiler(>=5.5)
id = row[.rowID]
#else
id = row[Column.rowID]
#endif
age = row["age"]
name = row["name"]
creationDate = row["creationDate"]
@@ -48,11 +44,7 @@ private class Person : Record, Hashable {
}
override func encode(to container: inout PersistenceContainer) {
#if compiler(>=5.5)
container[.rowID] = id
#else
container[Column.rowID] = id
#endif
container["name"] = name
container["age"] = age
container["creationDate"] = creationDate
@@ -621,7 +621,6 @@ class SharedValueObservationTests: GRDBTestCase {
}
#endif
#if compiler(>=5.6) && canImport(_Concurrency)
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
func testAsyncAwait() async throws {
let dbQueue = try makeDatabaseQueue()
@@ -641,7 +640,6 @@ class SharedValueObservationTests: GRDBTestCase {
break
}
}
#endif
}
private class Log: TextOutputStream {
+11 -132
View File
@@ -283,8 +283,6 @@ extension XCTestCase {
return try valueObservationExpectation.get()
}
// #file vs. #filePath dance
#if compiler(>=5.3)
/// This test checks the fundamental promise of ValueObservation by
/// comparing recorded values with expected values.
///
@@ -310,71 +308,13 @@ extension XCTestCase {
/// - `[]` (missing last value)
/// - `[0, 1, 2]` (unexpected value)
/// - `[1, 0, 1]` (unexpected value)
public func assertValueObservationRecordingMatch<Value>(
recorded recordedValues: [Value],
expected expectedValues: [Value],
func assertValueObservationRecordingMatch<R, E>(
recorded recordedValues: R,
expected expectedValues: E,
allowMissingLastValue: Bool = false,
_ message: @autoclosure () -> String = "",
file: StaticString = #filePath,
line: UInt = #line)
where Value: Equatable
{
_assertValueObservationRecordingMatch(
recorded: recordedValues,
expected: expectedValues,
// Last value can't be missed
allowMissingLastValue: false,
message(), file: file, line: line)
}
#else
/// This test checks the fundamental promise of ValueObservation by
/// comparing recorded values with expected values.
///
/// Recorded values match the expected values if and only if:
///
/// - The last recorded value is the last expected value
/// - Recorded values are in the same order as expected values
///
/// However, both missing and repeated values are allowed - with the only
/// exception of the last expected value which can not be missed.
///
/// For example, if the expected values are [0, 1], then the following
/// recorded values match:
///
/// - `[0, 1]` (identical values)
/// - `[1]` (missing value but the last one)
/// - `[0, 0, 1, 1]` (repeated value)
///
/// However the following recorded values don't match, and fail the test:
///
/// - `[1, 0]` (wrong order)
/// - `[0]` (missing last value)
/// - `[]` (missing last value)
/// - `[0, 1, 2]` (unexpected value)
/// - `[1, 0, 1]` (unexpected value)
public func assertValueObservationRecordingMatch<Value>(
recorded recordedValues: [Value],
expected expectedValues: [Value],
_ message: @autoclosure () -> String = "",
file: StaticString = #file,
line: UInt = #line)
where Value: Equatable
{
_assertValueObservationRecordingMatch(
recorded: recordedValues,
expected: expectedValues,
// Last value can't be missed
allowMissingLastValue: false,
message(), file: file, line: line)
}
#endif
private func _assertValueObservationRecordingMatch<R, E>(
recorded recordedValues: R,
expected expectedValues: E,
allowMissingLastValue: Bool,
_ message: @autoclosure () -> String = "",
file: StaticString,
line: UInt)
where
R: BidirectionalCollection,
E: BidirectionalCollection,
@@ -400,7 +340,7 @@ extension XCTestCase {
let remainingRecordedValues = recordedValues.prefix(recordedValues.count - recordedSuffix.count)
let remainingExpectedValues = expectedValues.prefix(expectedValues.count - expectedSuffix.count)
_assertValueObservationRecordingMatch(
assertValueObservationRecordingMatch(
recorded: remainingRecordedValues,
expected: remainingExpectedValues,
// Other values can be missed
@@ -412,13 +352,13 @@ extension XCTestCase {
// MARK: - GRDBTestCase + ValueObservationExpectation
extension GRDBTestCase {
func _assertValueObservation<Reducer: ValueReducer>(
func assertValueObservation<Reducer: ValueReducer>(
_ observation: ValueObservation<Reducer>,
records expectedValues: [Reducer.Value],
setup: (Database) throws -> Void,
recordedUpdates: @escaping (Database) throws -> Void,
file: StaticString,
line: UInt)
file: StaticString = #filePath,
line: UInt = #line)
throws
where Reducer.Value: Equatable
{
@@ -624,12 +564,12 @@ extension GRDBTestCase {
}
}
func _assertValueObservation<Reducer: ValueReducer, Failure: Error>(
func assertValueObservation<Reducer: ValueReducer, Failure: Error>(
_ observation: ValueObservation<Reducer>,
fails testFailure: (Failure, DatabaseWriter) throws -> Void,
setup: (Database) throws -> Void,
file: StaticString,
line: UInt)
file: StaticString = #filePath,
line: UInt = #line)
throws
{
func test(
@@ -689,67 +629,6 @@ extension GRDBTestCase {
testErrorDispatching: { XCTAssertNotNil(DispatchQueue.getSpecific(key: key)) })
}
}
// #file vs. #filePath dance
#if compiler(>=5.3)
func assertValueObservation<Reducer: _ValueReducer>(
_ observation: ValueObservation<Reducer>,
records expectedValues: [Reducer.Value],
setup: (Database) throws -> Void,
recordedUpdates: @escaping (Database) throws -> Void,
file: StaticString = #filePath,
line: UInt = #line)
throws
where Reducer.Value: Equatable
{
try _assertValueObservation(
observation,
records: expectedValues,
setup: setup,
recordedUpdates: recordedUpdates,
file: file, line: line)
}
func assertValueObservation<Reducer: _ValueReducer, Failure: Error>(
_ observation: ValueObservation<Reducer>,
fails testFailure: (Failure, DatabaseWriter) throws -> Void,
setup: (Database) throws -> Void,
file: StaticString = #filePath,
line: UInt = #line)
throws
{
try _assertValueObservation(observation, fails: testFailure, setup: setup, file: file, line: line)
}
#else
func assertValueObservation<Reducer: ValueReducer>(
_ observation: ValueObservation<Reducer>,
records expectedValues: [Reducer.Value],
setup: (Database) throws -> Void,
recordedUpdates: @escaping (Database) throws -> Void,
file: StaticString = #file,
line: UInt = #line)
throws
where Reducer.Value: Equatable
{
try _assertValueObservation(
observation,
records: expectedValues,
setup: setup,
recordedUpdates: recordedUpdates,
file: file, line: line)
}
func assertValueObservation<Reducer: ValueReducer, Failure: Error>(
_ observation: ValueObservation<Reducer>,
fails testFailure: (Failure, DatabaseWriter) throws -> Void,
setup: (Database) throws -> Void,
file: StaticString = #file,
line: UInt = #line)
throws
{
try _assertValueObservation(observation, fails: testFailure, setup: setup, file: file, line: line)
}
#endif
}
// MARK: - ValueObservationExpectations
@@ -741,7 +741,6 @@ class ValueObservationTests: GRDBTestCase {
try test(makeDatabasePool())
}
#if compiler(>=5.6) && canImport(_Concurrency)
// MARK: - Async Await
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
@@ -936,5 +935,4 @@ class ValueObservationTests: GRDBTestCase {
.runAtTemporaryDatabasePath { try DatabaseQueue(path: $0) }
.runAtTemporaryDatabasePath { try DatabasePool(path: $0) }
}
#endif
}