Skip to content

Commit

Permalink
Tests for #1541
Browse files Browse the repository at this point in the history
  • Loading branch information
groue committed Jun 9, 2024
1 parent 263a549 commit a9a9d4c
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 1 deletion.
9 changes: 9 additions & 0 deletions Tests/GRDBTests/BackupTestCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,13 @@ class BackupTestCase: GRDBTestCase {
XCTAssertFalse(try db.tableExists("items"))
}
}

// Test passes if it compiles.
// See <https://github.com/groue/GRDB.swift/issues/1541>
func testBackupToAnyDatabaseWriter(
_ reader: some DatabaseReader,
destination: any DatabaseWriter
) throws {
try reader.backup(to: destination)
}
}
6 changes: 6 additions & 0 deletions Tests/GRDBTests/DatabaseMigratorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ import XCTest
import GRDB

class DatabaseMigratorTests : GRDBTestCase {
// Test passes if it compiles.
// See <https://github.com/groue/GRDB.swift/issues/1541>
func testMigrateAnyDatabaseWriter(writer: any DatabaseWriter) throws {
let migrator = DatabaseMigrator()
try migrator.migrate(writer)
}

func testEmptyMigratorSync() throws {
func test(writer: some DatabaseWriter) throws {
Expand Down
18 changes: 17 additions & 1 deletion Tests/GRDBTests/DatabaseReaderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,29 @@ import XCTest
import GRDB

class DatabaseReaderTests : GRDBTestCase {

func testAnyDatabaseReader() throws {
// This test passes if this code compiles.
let dbQueue = try DatabaseQueue()
let _: any DatabaseReader = AnyDatabaseReader(dbQueue)
}

// Test passes if it compiles.
func testInitFromGeneric(_ reader: some DatabaseReader) {
_ = AnyDatabaseReader(reader)
}

// Test passes if it compiles.
// See <https://github.com/groue/GRDB.swift/issues/1541>
func testInitFromExistentialReader(_ reader: any DatabaseReader) {
_ = AnyDatabaseReader(reader)
}

// Test passes if it compiles.
// See <https://github.com/groue/GRDB.swift/issues/1541>
func testInitFromExistentialWriter(_ writer: any DatabaseWriter) {
_ = AnyDatabaseReader(writer)
}

// MARK: - Read

func testReadCanRead() throws {
Expand Down
9 changes: 9 additions & 0 deletions Tests/GRDBTests/DatabaseRegionObservationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ import XCTest
import GRDB

class DatabaseRegionObservationTests: GRDBTestCase {
// Test passes if it compiles.
// See <https://github.com/groue/GRDB.swift/issues/1541>
func testAnyDatabaseWriter(writer: any DatabaseWriter) throws {
let observation = DatabaseRegionObservation(tracking: .fullDatabase)

_ = observation.start(in: writer, onError: { _ in }, onChange: { _ in })
_ = observation.publisher(in: writer)
}

func testDatabaseRegionObservation_FullDatabase() throws {
let dbQueue = try makeDatabaseQueue()
try dbQueue.write {
Expand Down
16 changes: 16 additions & 0 deletions Tests/GRDBTests/SharedValueObservationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,22 @@ import XCTest
import GRDB

class SharedValueObservationTests: GRDBTestCase {
// Test passes if it compiles.
// See <https://github.com/groue/GRDB.swift/issues/1541>
func testInitFromAnyDatabaseReader(reader: any DatabaseReader) {
_ = ValueObservation
.trackingConstantRegion { _ in }
.shared(in: reader)
}

// Test passes if it compiles.
// See <https://github.com/groue/GRDB.swift/issues/1541>
func testInitFromAnyDatabaseWriter(writer: any DatabaseWriter) {
_ = ValueObservation
.trackingConstantRegion { _ in }
.shared(in: writer)
}

func test_immediate_observationLifetime() throws {
let dbQueue = try makeDatabaseQueue()
try dbQueue.write { db in
Expand Down
26 changes: 26 additions & 0 deletions Tests/GRDBTests/ValueObservationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,32 @@ import Dispatch
@testable import GRDB

class ValueObservationTests: GRDBTestCase {
// Test passes if it compiles.
// See <https://github.com/groue/GRDB.swift/issues/1541>
func testStartFromAnyDatabaseReader(reader: any DatabaseReader) {
_ = ValueObservation
.trackingConstantRegion { _ in }
.start(in: reader, onError: { _ in }, onChange: { })
}

// Test passes if it compiles.
// See <https://github.com/groue/GRDB.swift/issues/1541>
func testStartFromAnyDatabaseWriter(writer: any DatabaseWriter) {
_ = ValueObservation
.trackingConstantRegion { _ in }
.start(in: writer, onError: { _ in }, onChange: { })
}

// Test passes if it compiles.
// See <https://github.com/groue/GRDB.swift/issues/1541>
func testValuesFromAnyDatabaseWriter(writer: any DatabaseWriter) {
func observe<T>(
fetch: @Sendable @escaping (Database) throws -> T
) throws -> AsyncValueObservation<T> {
ValueObservation.tracking(fetch).values(in: writer)
}
}

func testImmediateError() throws {
struct TestError: Error { }

Expand Down

0 comments on commit a9a9d4c

Please sign in to comment.