@@ -4,25 +4,30 @@ import kotlin.test.*
4
4
5
5
class FileTests {
6
6
7
- private val localSeparator = ' /'
8
-
9
7
@Test
10
8
fun testNonexistentRootFile () {
11
9
val testFile = File (" testNonexistentRootFile.txt" )
12
10
13
11
assertFalse(testFile.exists(), " file should not exist" )
14
12
assertFalse(testFile.isDirectory(), " file should not be directory" )
15
13
assertFalse(testFile.isFile(), " file should not be file" )
16
- assertNull(testFile.getParent(), " file should not have parent" )
17
- assertNull(testFile.getParentFile(), " file should not have parent file" )
14
+
15
+ if (platform() == Platform .JVM ) {
16
+ assertNull(testFile.getParent(), " file should not have parent" )
17
+ assertNull(testFile.getParentFile(), " file should not have parent file" )
18
+ }
19
+
20
+ if (platform().isPosix()) { // in posix we always resolve relative path via `realpath` syscall
21
+ assertEquals(testFile.getParent(), File (" ./" ).getAbsolutePath(), " as parent should be current dir" )
22
+ assertEquals(testFile.getParentFile()?.getAbsolutePath(), File (" ./" ).getAbsolutePath(), " as parent should be current dir" )
23
+ }
18
24
19
25
assertEquals(" testNonexistentRootFile" , testFile.nameWithoutExtension)
20
26
}
21
27
22
28
@Test
23
29
fun testExistentRootFile () {
24
30
val testFile = File (" testFileRoot/testExistentRootFile.txt" )
25
- println (testFile.getAbsolutePath())
26
31
27
32
assertFalse(testFile.exists(), " file should not exist" )
28
33
assertFalse(testFile.getParentFile()?.exists() == true , " file should not have parent file" )
@@ -33,6 +38,10 @@ class FileTests {
33
38
34
39
@Test
35
40
fun testFileCreateAndDelete () {
41
+ if (platform() == Platform .Windows ) {
42
+ return
43
+ }
44
+
36
45
val testFolder = File (" build/testNewDirectoryCreation" )
37
46
38
47
assertTrue(testFolder.mkdirs(), " create directory failed" )
@@ -52,6 +61,10 @@ class FileTests {
52
61
53
62
@Test
54
63
fun testFileWriteAndRead () {
64
+ if (platform() == Platform .Windows ) {
65
+ return
66
+ }
67
+
55
68
val testFolder = File (" build/testFileWriteAndRead" )
56
69
val testFile = File (" build/testFileWriteAndRead/test.txt" )
57
70
@@ -87,6 +100,10 @@ class FileTests {
87
100
88
101
@Test
89
102
fun testFileCopyMethod () {
103
+ if (platform() == Platform .Windows ) {
104
+ return
105
+ }
106
+
90
107
val testFile = File (" gradle/wrapper/gradle-wrapper.properties" )
91
108
val testDestFolder = File (" build/testCopyFolder" )
92
109
val testDestFile = File (" build/testCopyFolder/gradle-wrapper.properties" )
@@ -107,6 +124,10 @@ class FileTests {
107
124
108
125
@Test
109
126
fun testFileMoveMethod () {
127
+ if (platform() == Platform .Windows ) {
128
+ return
129
+ }
130
+
110
131
val testFolder = File (" build/testMoveFolder" )
111
132
val testDestFolder = File (" build/testMoveFolder2" )
112
133
val testFile = File (" build/testMoveFolder/test_move_file.properties" )
@@ -198,4 +219,32 @@ class FileTests {
198
219
199
220
assertTrue(testFile.delete(), " delete file failed" )
200
221
}
222
+
223
+ @Test
224
+ fun testFileRealPathIfRelativeLinks__posixOnly () {
225
+ if (! platform().isPosix()) {
226
+ return
227
+ }
228
+
229
+ val symlinkPrefix = if (platform() == Platform .Macos ) " /private" else " "
230
+
231
+ val testDir = File (" /tmp/build" )
232
+ val testFile = Files .createTempFile(prefix = " ../test" , suffix = " .txt" , dir = testDir)
233
+ assertEquals(" $symlinkPrefix /tmp/test.txt" , testFile.getAbsolutePath()) // 'cause /tmp is a symlink for /private/tmp
234
+ assertTrue(testFile.delete(), " delete file failed" )
235
+ assertTrue(testDir.delete(), " delete test folder failed" )
236
+ }
237
+
238
+ @Test
239
+ fun testFileRealPathIfRelativeLinks__jvmOnly () {
240
+ if (platform() != Platform .JVM ) {
241
+ return
242
+ }
243
+
244
+ val testDir = File (" /tmp/build" )
245
+ val testFile = Files .createTempFile(prefix = " ../test" , suffix = " .txt" , dir = testDir)
246
+ assertEquals(" /tmp/build/../test.txt" , testFile.getAbsolutePath()) // lazy canonicalization in jvm
247
+ assertTrue(testFile.delete(), " delete file failed" )
248
+ assertTrue(testDir.delete(), " delete test folder failed" )
249
+ }
201
250
}
0 commit comments