stephencelis / SQLite.swift

A type-safe, Swift-language layer over SQLite3.
MIT License
9.7k stars 1.56k forks source link

Native user_version support in Connection #1105

Closed nathanfallet closed 2 years ago

nathanfallet commented 2 years ago

@jberkel Test fails on Linux because of something related to encodable, but I don't think that it is related to my changes. Do you have any idea?

Test Case 'QueryTests.test_update_encodable_with_nested_encodable' started at 2022-01-17 16:31:02.883
/home/runner/work/SQLite.swift/SQLite.swift/Tests/SQLiteTests/QueryTests.swift:396: error: QueryTests.test_update_encodable_with_nested_encodable : XCTAssertEqual failed: ("UPDATE "emails" SET "int" = 1, "string" = '2', "bool" = 1, "float" = 3.0, "double" = 4.0, "date" = '1970-01-01T00:00:00.000', "sub" = '{"date":-978307200,"int":1,"float":3,"string":"2","double":4,"bool":true}'") is not equal to ("UPDATE "emails" SET "int" = 1, "string" = '2', "bool" = 1, "float" = 3.0, "double" = 4.0, "date" = '1970-01-01T00:00:00.000', "sub" = '{"date":-978307200,"double":4,"int":1,"string":"2","bool":true,"float":3}'") - 
Test Case 'QueryTests.test_update_encodable_with_nested_encodable' failed (0.001 seconds)
jberkel commented 2 years ago

@NathanFallet the test is brittle because it compares the JSON as a string. On Linux the JSON serialization is different (order of fields). You could make the JSON serialization more deterministic with OutputFormatting.sortedKeys (but that's only iOS 11+, macOS 10.13+) or improve the test so that it does not do a by string comparison.

nathanfallet commented 2 years ago

@jberkel Right, I'm gonna inspect that. I need to understand why it changed since the last commit (because test was passing for the last commit on master)

nathanfallet commented 2 years ago

@NathanFallet the test is brittle because it compares the JSON as a string. On Linux the JSON serialization is different (order of fields). You could make the JSON serialization more deterministic with OutputFormatting.sortedKeys (but that's only iOS 11+, macOS 10.13+) or improve the test so that it does not do a by string comparison.

After inspection, it means that JSONEncoder().encode(value) gives different data each time, even with the same object passed as value?!

jberkel commented 2 years ago

After inspection, it means that JSONEncoder().encode(value) gives different data each time, even with the same object passed as value?!

Possibly, there are no guarantees by the method. I think we should do both: make the JSON output consistent (with sortedKeys) if possible, and avoid doing a string comparison in the test.