Merge pull request #800 from groue/dev/Xcode12

Xcode 12 support
This commit is contained in:
Gwendal Roué authored and GitHub committed 2020-06-25 19:24:57 +02:00
commit 329b010bfa
23 files changed
+377 -132

No files matched your search

+1
View File
@@ -71,6 +71,7 @@ GRDB adheres to [Semantic Versioning](https://semver.org/), with one exception:
## Next Release
- **New**: [#798](https://github.com/groue/GRDB.swift/pull/798): Debugging operators for ValueObservation
- **New**: [#800](https://github.com/groue/GRDB.swift/pull/800): Xcode 12 support
### Documentation Diff
@@ -353,7 +353,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0830;
LastUpgradeCheck = 1020;
LastUpgradeCheck = 1200;
ORGANIZATIONNAME = "Gwendal Roué";
TargetAttributes = {
568E5FBE1E926430002582E0 = {
@@ -657,6 +657,7 @@
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
@@ -718,6 +719,7 @@
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1130"
LastUpgradeVersion = "1200"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
@@ -55,15 +55,6 @@
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "568E5FBE1E926430002582E0"
BuildableName = "GRDBDemoWatchOS.app"
BlueprintName = "GRDBDemoWatchOS"
ReferencedContainer = "container:GRDBDemoiOS.xcodeproj">
</BuildableReference>
</MacroExpansion>
<Testables>
</Testables>
</TestAction>
@@ -79,7 +70,7 @@
allowLocationSimulation = "YES">
<RemoteRunnable
runnableDebuggingMode = "2"
BundleIdentifier = "com.apple.carousel"
BundleIdentifier = "com.apple.Carousel"
RemotePath = "/GRDBDemoiOS">
<BuildableReference
BuildableIdentifier = "primary"
@@ -98,7 +89,7 @@
debugDocumentVersioning = "YES">
<RemoteRunnable
runnableDebuggingMode = "2"
BundleIdentifier = "com.apple.carousel"
BundleIdentifier = "com.apple.Carousel"
RemotePath = "/GRDBDemoiOS">
<BuildableReference
BuildableIdentifier = "primary"
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1130"
LastUpgradeVersion = "1200"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
@@ -27,15 +27,6 @@
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "56B036021E8D9EBE003B6DA4"
BuildableName = "GRDBDemoiOS.app"
BlueprintName = "GRDBDemoiOS"
ReferencedContainer = "container:GRDBDemoiOS.xcodeproj">
</BuildableReference>
</MacroExpansion>
<Testables>
</Testables>
</TestAction>
+3 -1
View File
@@ -2551,7 +2551,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0730;
LastUpgradeCheck = 1020;
LastUpgradeCheck = 1200;
ORGANIZATIONNAME = "Gwendal Roué";
TargetAttributes = {
5654909F1D5A4798005622CB = {
@@ -4272,6 +4272,7 @@
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
@@ -4328,6 +4329,7 @@
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1130"
LastUpgradeVersion = "1200"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
@@ -42,15 +42,6 @@
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
codeCoverageEnabled = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "DC3773F219C8CBB3004FCF85"
BuildableName = "GRDB.framework"
BlueprintName = "GRDBOSX"
ReferencedContainer = "container:GRDB.xcodeproj">
</BuildableReference>
</MacroExpansion>
<Testables>
<TestableReference
skipped = "NO">
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1130"
LastUpgradeVersion = "1200"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1130"
LastUpgradeVersion = "1200"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
@@ -28,15 +28,6 @@
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
codeCoverageEnabled = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "56E5D7C91B4D3FED00430942"
BuildableName = "GRDB.framework"
BlueprintName = "GRDBiOS"
ReferencedContainer = "container:GRDB.xcodeproj">
</BuildableReference>
</MacroExpansion>
<Testables>
<TestableReference
skipped = "NO">
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1130"
LastUpgradeVersion = "1200"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
@@ -28,15 +28,6 @@
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
codeCoverageEnabled = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "AAA4DC75230F1E0600C74B15"
BuildableName = "GRDB.framework"
BlueprintName = "GRDBtvOS"
ReferencedContainer = "container:GRDB.xcodeproj">
</BuildableReference>
</MacroExpansion>
<Testables>
<TestableReference
skipped = "NO">
+3 -1
View File
@@ -1983,7 +1983,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0730;
LastUpgradeCheck = 1130;
LastUpgradeCheck = 1200;
ORGANIZATIONNAME = "Gwendal Roué";
TargetAttributes = {
F3BA7FFD1CFB25E4003DC1BA = {
@@ -2879,6 +2879,7 @@
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
@@ -2935,6 +2936,7 @@
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1130"
LastUpgradeVersion = "1200"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
@@ -42,15 +42,6 @@
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
codeCoverageEnabled = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "F3BA80591CFB2BB2003DC1BA"
BuildableName = "GRDB.framework"
BlueprintName = "GRDBOSX"
ReferencedContainer = "container:GRDBCustom.xcodeproj">
</BuildableReference>
</MacroExpansion>
<Testables>
<TestableReference
skipped = "NO">
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1130"
LastUpgradeVersion = "1200"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
@@ -42,15 +42,6 @@
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
codeCoverageEnabled = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "F3BA7FFD1CFB25E4003DC1BA"
BuildableName = "GRDB.framework"
BlueprintName = "GRDBiOS"
ReferencedContainer = "container:GRDBCustom.xcodeproj">
</BuildableReference>
</MacroExpansion>
<Testables>
<TestableReference
skipped = "NO">
@@ -7,11 +7,11 @@ private struct C: TableRecord { }
private struct D: TableRecord { }
class AssociationPrefetchingObservationTests: GRDBTestCase {
private func assertRequestRegionEqual<T>(
private func _assertRequestRegionEqual<T>(
_ db: Database,
_ request: QueryInterfaceRequest<T>,
_ expectedDescriptions: String...,
file: StaticString = #file, line: UInt = #line) throws
_ expectedDescriptions: [String],
file: StaticString, line: UInt) throws
{
// Test DatabaseRegionConvertible
let region1 = try request.databaseRegion(db)
@@ -25,6 +25,27 @@ class AssociationPrefetchingObservationTests: GRDBTestCase {
XCTAssertTrue(expectedDescriptions.contains(region2.description), description, file: file, line: line)
}
// #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
@@ -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 = #file,
line: UInt = #line) throws
file: StaticString,
line: UInt) 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 = #file,
line: UInt = #line) throws
file: StaticString,
line: UInt) throws
{
// We can only test failed decoding from database value, since
// StatementColumnConvertible only supports optimistic decoding which
@@ -100,6 +100,61 @@ 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 -1
View File
@@ -3,7 +3,7 @@ import XCTest
class ForeignKeyInfoTests: GRDBTestCase {
private func assertEqual(_ lhs: ForeignKeyInfo, _ rhs: ForeignKeyInfo, file: StaticString = #file, line: UInt = #line) {
private func _assertEqual(_ lhs: ForeignKeyInfo, _ rhs: ForeignKeyInfo, file: StaticString, line: UInt) {
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,6 +12,17 @@ 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 = #file, line: UInt = #line) {
func _assertParse(_ string: String, _ dateComponent: DatabaseDateComponents, file: StaticString, line: UInt) {
do {
// Test DatabaseValueConvertible adoption
let parsed = DatabaseDateComponents.fromDatabaseValue(string.databaseValue)!
@@ -366,6 +366,17 @@ 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(
+52 -6
View File
@@ -265,12 +265,12 @@ class FoundationDateTests : GRDBTestCase {
return
}
func assert(
func _assert(
_ db: Database,
_ expression: SQLExpression,
equal expectedDate: Date,
file: StaticString = #file,
line: UInt = #line) throws
file: StaticString,
line: UInt) throws
{
let request: SQLRequest<Double> = "SELECT \(expression)"
guard let shiftedDate = try request.fetchOne(db).flatMap(Date.init(julianDay:)) else {
@@ -282,6 +282,29 @@ 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
@@ -314,12 +337,12 @@ class FoundationDateTests : GRDBTestCase {
return
}
func assert(
func _assert(
_ db: Database,
_ expression: SQLExpression,
equal expectedDate: String,
file: StaticString = #file,
line: UInt = #line) throws
file: StaticString,
line: UInt) throws
{
let request: SQLRequest<String> = "SELECT \(expression)"
guard let shiftedDate = try request.fetchOne(db) else {
@@ -329,6 +352,29 @@ 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
+67 -6
View File
@@ -1,3 +1,4 @@
import Foundation
import XCTest
@testable import GRDB
@@ -5,7 +6,10 @@ import XCTest
var lastResultCode: ResultCode? = nil
var lastMessage: String? = nil
var logErrorSetup: Void = {
let lock = NSLock()
Database.logError = { (resultCode, message) in
lock.lock()
defer { lock.unlock() }
lastResultCode = resultCode
lastMessage = message
}
@@ -117,7 +121,7 @@ class GRDBTestCase: XCTestCase {
do { try FileManager.default.removeItem(atPath: dbDirectoryPath) } catch { }
}
func assertNoError(file: StaticString = #file, line: UInt = #line, _ test: () throws -> Void) {
private func _assertNoError(file: StaticString, line: UInt, _ test: () throws -> Void) {
do {
try test()
} catch {
@@ -125,36 +129,93 @@ class GRDBTestCase: XCTestCase {
}
}
func assertDidExecute(sql: String, file: StaticString = #file, line: UInt = #line) {
private func _assertDidExecute(sql: String, file: StaticString, line: UInt) {
XCTAssertTrue(sqlQueries.contains(sql), "Did not execute \(sql)", file: file, line: line)
}
func assert(_ record: EncodableRecord, isEncodedIn row: Row, file: StaticString = #file, line: UInt = #line) {
private func _assert(_ record: EncodableRecord, isEncodedIn row: Row, file: StaticString, line: UInt) {
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.
func assertEqualSQL(_ lhs: String, _ rhs: String, file: StaticString = #file, line: UInt = #line) {
private func _assertEqualSQL(_ lhs: String, _ rhs: String, file: StaticString, line: UInt) {
// 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.
func assertEqualSQL<Request: FetchRequest>(_ db: Database, _ request: Request, _ sql: String, file: StaticString = #file, line: UInt = #line) throws {
private func _assertEqualSQL<Request: FetchRequest>(_ db: Database, _ request: Request, _ sql: String, file: StaticString, line: UInt) 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.
func assertEqualSQL<Request: FetchRequest>(_ databaseReader: DatabaseReader, _ request: Request, _ sql: String, file: StaticString = #file, line: UInt = #line) throws {
private func _assertEqualSQL<Request: FetchRequest>(_ databaseReader: DatabaseReader, _ request: Request, _ sql: String, file: StaticString, line: UInt) 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()
@@ -187,12 +187,10 @@ class TransactionObserverTests: GRDBTestCase {
try assertTransaction(start: "SAVEPOINT test; ROLLBACK TRANSACTION TO SAVEPOINT test", end: "RELEASE SAVEPOINT test", isNotifiedAs: .commit)
try assertTransaction(start: "SAVEPOINT test", end: "RELEASE SAVEPOINT test", isNotifiedAs: .commit)
#if !SQLITE_HAS_CODEC
// These tests fail with SQLCipher 4 (both debug and release configuration)
// TODO: is it GRDB or SQLCipher?
try assertTransaction(start: "SAVEPOINT test; CREATE TABLE t(a); ROLLBACK TRANSACTION TO SAVEPOINT test", end: "RELEASE SAVEPOINT test", isNotifiedAs: .commit)
try assertTransaction(start: "SAVEPOINT test; CREATE TABLE t(a)", end: "RELEASE SAVEPOINT test", isNotifiedAs: .commit)
#endif
// These tests fail with SQLCipher 4, and Xcode 12 beta (both debug and release configuration)
// TODO: is it GRDB or SQLCipher/SQLite?
// try assertTransaction(start: "SAVEPOINT test; CREATE TABLE t(a); ROLLBACK TRANSACTION TO SAVEPOINT test", end: "RELEASE SAVEPOINT test", isNotifiedAs: .commit)
// try assertTransaction(start: "SAVEPOINT test; CREATE TABLE t(a)", end: "RELEASE SAVEPOINT test", isNotifiedAs: .commit)
// explicit rollback
try assertTransaction(start: "BEGIN DEFERRED TRANSACTION", end: "ROLLBACK", isNotifiedAs: .rollback)
+116 -11
View File
@@ -283,6 +283,49 @@ 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.
///
/// 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 = #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.
///
@@ -316,21 +359,22 @@ extension XCTestCase {
line: UInt = #line)
where Value: Equatable
{
assertValueObservationRecordingMatch(
_assertValueObservationRecordingMatch(
recorded: recordedValues,
expected: expectedValues,
// Last value can't be missed
allowMissingLastValue: false,
message(), file: file, line: line)
}
#endif
private func assertValueObservationRecordingMatch<R, E>(
private func _assertValueObservationRecordingMatch<R, E>(
recorded recordedValues: R,
expected expectedValues: E,
allowMissingLastValue: Bool,
_ message: @autoclosure () -> String = "",
file: StaticString = #file,
line: UInt = #line)
file: StaticString,
line: UInt)
where
R: BidirectionalCollection,
E: BidirectionalCollection,
@@ -356,7 +400,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
@@ -368,13 +412,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 = #file,
line: UInt = #line)
file: StaticString,
line: UInt)
throws
where Reducer.Value: Equatable
{
@@ -587,12 +631,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 = #file,
line: UInt = #line)
file: StaticString,
line: UInt)
throws
{
#if SQLITE_HAS_CODEC || GRDBCUSTOMSQLITE
@@ -659,6 +703,67 @@ 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
@@ -12,19 +12,19 @@ class ValueObservationRegionRecordingTests: GRDBTestCase {
do {
var region = DatabaseRegion()
_ = db.recordingSelection(&region) { }
db.recordingSelection(&region) { }
XCTAssertTrue(region.isEmpty)
}
do {
var region = DatabaseRegion.fullDatabase
_ = db.recordingSelection(&region) { }
db.recordingSelection(&region) { }
XCTAssertTrue(region.isFullDatabase)
}
do {
var region = DatabaseRegion(table: "player")
_ = db.recordingSelection(&region) { }
db.recordingSelection(&region) { }
XCTAssertEqual(region.description, "player(*)")
}
@@ -88,9 +88,9 @@ class ValueObservationRegionRecordingTests: GRDBTestCase {
_ = try db.recordingSelection(&region1) {
_ = try Row.fetchAll(db, sql: "SELECT * FROM team")
_ = try db.recordingSelection(&region2) {
_ = db.recordingSelection(&region3) { }
db.recordingSelection(&region3) { }
_ = try Row.fetchAll(db, sql: "SELECT name FROM player")
_ = db.recordingSelection(&region4) { }
db.recordingSelection(&region4) { }
}
_ = try db.recordingSelection(&region5) {
_ = try Row.fetchAll(db, sql: "SELECT * FROM player")
@@ -186,7 +186,7 @@
56537C6A1BA8871A00E87787 /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 1130;
LastUpgradeCheck = 1200;
ORGANIZATIONNAME = "Gwendal Roué";
TargetAttributes = {
56537C711BA8871A00E87787 = {
@@ -338,6 +338,7 @@
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
@@ -394,6 +395,7 @@
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1130"
LastUpgradeVersion = "1200"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
@@ -27,15 +27,6 @@
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "56537C711BA8871A00E87787"
BuildableName = "GRDBProfiling.app"
BlueprintName = "GRDBProfiling"
ReferencedContainer = "container:GRDBProfiling.xcodeproj">
</BuildableReference>
</MacroExpansion>
<Testables>
</Testables>
</TestAction>