Made File.Handle a non-copyable struct in the library to adopt Swift 6.4.

This commit is contained in:
2026-09-18 12:18:05 +02:00
parent 95ae01f97a
commit 07c4fce37b
5 changed files with 66 additions and 30 deletions
+13
View File
@@ -422,6 +422,19 @@ enum Mock {
private static func installJSON() {
jsonAPI.initialize(to: playdate_json())
// Pulls one chunk through the reader, as the OS would, and decodes
// it as `null`.
jsonAPI.pointee.decode = { _, reader, outval in
var buffer = [UInt8](repeating: 0, count: 16)
let count = buffer.withUnsafeMutableBufferPointer { buffer in
reader.read?(reader.userdata, buffer.baseAddress, Int32(buffer.count)) ?? -1
}
Mock.record("decode(\(count))")
outval?.pointee = json_value()
outval?.pointee.type = CChar(kJSONNull.rawValue)
return 1
}
jsonAPI.pointee.decodeString = { decoder, _, outval in
guard let decoder else { return 0 }
+20
View File
@@ -345,6 +345,26 @@ struct WrapperTests {
#expect(Mock.eventCount("close") == 1)
}
@Test func jsonDecodeFileReadsThroughTheHandleAndClosesIt() throws {
Mock.fileReadLimit = 5
let value = try JSON.decodeFile(path: "save.json")
guard case .null = value else {
Issue.record("expected .null, got \(value)")
return
}
#expect(Mock.events.contains("decode(5)"))
#expect(Mock.eventCount("close") == 1)
}
@Test func fileHandleClosesWhenItGoesOutOfScope() throws {
do {
let handle = try File.Handle(path: "save.dat", mode: .write)
_ = try handle.write([1])
#expect(Mock.eventCount("close") == 0)
}
#expect(Mock.eventCount("close") == 1)
}
@Test func fileHandleReadLengthReturnsOnlyTheBytesRead() throws {
let handle = try File.Handle(path: "save.dat", mode: [.read, .readData])