@@ -131,4 +131,71 @@ class FileTests {
131131 assertTrue(testDestFile.delete(), " failed to cleanup test file" )
132132 assertTrue(testDestFolder.delete(), " failed to cleanup directory" )
133133 }
134+
135+ @Test
136+ fun testCreateTempFileAndDelete () {
137+ if (platform() == Platform .Windows ) {
138+ return
139+ }
140+
141+ val testFile = Files .createTempFile(" test" )
142+
143+ assertContains(
144+ testFile.getAbsolutePath(),
145+ " /tmp/test.tmp" .replace(' /' , filePathSeparator),
146+ message = " different path: ${testFile.getAbsolutePath()} "
147+ )
148+ assertTrue(testFile.exists(), " file should exist" )
149+ assertTrue(testFile.canRead(), " file should be readable" )
150+ assertTrue(testFile.canWrite(), " file should be writable" )
151+ assertTrue(testFile.isFile(), " file should be considered a file" )
152+ assertFalse(testFile.isDirectory(), " file should not be considered a directory" )
153+ assertTrue(testFile.delete(), " delete file failed" )
154+ }
155+
156+ @Test
157+ fun testCreateTempFileWithinCustomDirAndDelete () {
158+ if (platform() == Platform .Windows ) {
159+ return
160+ }
161+
162+ val testDir = File (" /tmp/testdir" ).apply { mkdirs() }
163+ val testFile = Files .createTempFile(prefix = " test" , suffix = " all.t" , dir = testDir)
164+
165+ assertContains(
166+ testFile.getAbsolutePath(),
167+ " /tmp/testdir/testall.t" .replace(' /' , filePathSeparator),
168+ message = " different path: ${testFile.getAbsolutePath()} "
169+ )
170+ assertTrue(testFile.exists(), " file should exist" )
171+ assertTrue(testFile.canRead(), " file should be readable" )
172+ assertTrue(testFile.canWrite(), " file should be writable" )
173+ assertTrue(testFile.isFile(), " file should be considered a file" )
174+ assertFalse(testFile.isDirectory(), " file should not be considered a directory" )
175+ assertTrue(testFile.delete(), " delete file failed" )
176+
177+ assertTrue(testDir.deleteRecursively(), " error while deleting all files in dir" )
178+ }
179+
180+ @Test
181+ fun testFileLengthAndAppendings () {
182+ if (platform() == Platform .Windows ) {
183+ return
184+ }
185+
186+ val testFile = Files .createTempFile(" test" )
187+ val data = " testData"
188+ testFile.writeText(data)
189+
190+ assertTrue(testFile.exists(), " file should exists" )
191+ assertEquals(data, testFile.readText())
192+
193+ val appendedData = " \n New Text!"
194+ testFile.appendBytes(appendedData.encodeToByteArray())
195+
196+ assertEquals(data + appendedData, testFile.readText())
197+ assertEquals((data + appendedData).length.toLong(), testFile.length())
198+
199+ assertTrue(testFile.delete(), " delete file failed" )
200+ }
134201}
0 commit comments