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
+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])