Fix assertQuery changing to empty results after snapshot contains results - #191
Conversation
|
@rcarver Can you give an example of what this fixes? Maybe a test with an expected failure or something to that effect? I think the fix we probably want to apply here is to always record an empty result set, something like: assertQuery(Reminder.all) {
"""
(No results.)
"""
}Think you could cook that change up? |
|
@stephencelis sorry based on the comments in slack I assumed you'd have context. This fixes the following:
Here's a diff I used to switch between diff --git a/Tests/SharingGRDBTests/AssertQueryTests.swift b/Tests/SharingGRDBTests/AssertQueryTests.swift
index 73de34d..6dbe543 100644
--- a/Tests/SharingGRDBTests/AssertQueryTests.swift
+++ b/Tests/SharingGRDBTests/AssertQueryTests.swift
@@ -153,4 +153,40 @@ extension DatabaseWriter where Self == DatabaseQueue {
}
return database
}
+ fileprivate static func emptyDatabase() throws -> DatabaseQueue {
+ let database = try DatabaseQueue()
+ try database.write { db in
+ try #sql(
+ """
+ CREATE TABLE "records" (
+ "id" INTEGER PRIMARY KEY AUTOINCREMENT,
+ "date" INTEGER NOT NULL DEFAULT 42
+ )
+ """
+ )
+ .execute(db)
+ }
+ return database
+ }
+}
+
+
+@Suite(
+ .dependency(\.defaultDatabase, try .database()),
+ .snapshots(record: .failed),
+)
+struct AssertQueryEmptyResultTests {
+ @Test func assertQueryBasic() throws {
+ assertQuery(
+ Record.all.select(\.id)
+ ) {
+ """
+ ┌───┐
+ │ 1 │
+ │ 2 │
+ │ 3 │
+ └───┘
+ """
+ }
+ }
} |
|
Also clarified the 'no results' case @Test func assertQueryEmpty() throws {
assertQuery(
Record.all.where { $0.id == -1 }.select(\.id)
) {
"""
(No results)
"""
}
} |
|
Hmm, looks like this got caught in the repo rename, let me know if you'd like me to recreate the PR |
|
I just merged main to get everything caught up and re-recorded the SQLiteData tests which now properly shows "(no results)" in a bunch of tests. |
|
Thanks! lgtm |

Fixes the issue brought up in slack