@@ -70,6 +70,62 @@ final class FileSystemTests: XCTestCase {
7070
7171 var fs : FileSystem { . shared }
7272
73+ func testSetLastAccessAndDataModificationTimes( ) async throws {
74+ let path = try await self . fs. temporaryFilePath ( )
75+ try await self . fs. withFileHandle ( forWritingAt: path, options: . newFile( replaceExisting: false ) ) { _ in }
76+
77+ let originalInfo = try await self . fs. info ( forFileAt: path)
78+ let originalLastAccessTime = originalInfo? . lastAccessTime
79+ let originalLastDataModificationTime = originalInfo? . lastDataModificationTime
80+
81+ let newAccessTime = FileInfo . Timespec ( seconds: 10 , nanoseconds: 5 )
82+ let newDataModTime = FileInfo . Timespec ( seconds: 20 , nanoseconds: 25 )
83+
84+ try await self . fs. setTimes ( forFileAt: path, lastAccess: newAccessTime, lastDataModification: newDataModTime)
85+
86+ let newInfo = try await self . fs. info ( forFileAt: path)
87+ XCTAssertEqual ( newInfo? . lastAccessTime, newAccessTime)
88+ XCTAssertEqual ( newInfo? . lastDataModificationTime, newDataModTime)
89+ XCTAssertNotEqual ( newInfo? . lastAccessTime, originalLastAccessTime)
90+ XCTAssertNotEqual ( newInfo? . lastDataModificationTime, originalLastDataModificationTime)
91+
92+ try await self . fs. removeItem ( at: path)
93+ }
94+
95+ func testSetLastAccessTime( ) async throws {
96+ let path = try await self . fs. temporaryFilePath ( )
97+ try await self . fs. withFileHandle ( forWritingAt: path, options: . newFile( replaceExisting: false ) ) { _ in }
98+
99+ let originalInfo = try await self . fs. info ( forFileAt: path)
100+ let originalLastDataModificationTime = originalInfo? . lastDataModificationTime
101+
102+ let newAccessTime = FileInfo . Timespec ( seconds: 10 , nanoseconds: 5 )
103+ try await self . fs. setLastAccessTime ( forFileAt: path, to: newAccessTime)
104+
105+ let newInfo = try await self . fs. info ( forFileAt: path)
106+ XCTAssertEqual ( newInfo? . lastAccessTime, newAccessTime)
107+ XCTAssertEqual ( newInfo? . lastDataModificationTime, originalLastDataModificationTime)
108+
109+ try await self . fs. removeItem ( at: path)
110+ }
111+
112+ func testSetLastDataModificationTime( ) async throws {
113+ let path = try await self . fs. temporaryFilePath ( )
114+ try await self . fs. withFileHandle ( forWritingAt: path, options: . newFile( replaceExisting: false ) ) { _ in }
115+
116+ let originalInfo = try await self . fs. info ( forFileAt: path)
117+ let originalLastAccessTime = originalInfo? . lastAccessTime
118+
119+ let newDataModTime = FileInfo . Timespec ( seconds: 20 , nanoseconds: 25 )
120+ try await self . fs. setLastDataModificationTime ( forFileAt: path, to: newDataModTime)
121+
122+ let newInfo = try await self . fs. info ( forFileAt: path)
123+ XCTAssertEqual ( newInfo? . lastDataModificationTime, newDataModTime)
124+ XCTAssertEqual ( newInfo? . lastAccessTime, originalLastAccessTime)
125+
126+ try await self . fs. removeItem ( at: path)
127+ }
128+
73129 func testOpenFileForReading( ) async throws {
74130 try await self . fs. withFileHandle ( forReadingAt: . testDataReadme) { file in
75131 let info = try await file. info ( )
0 commit comments