Skip to content

Commit 72b18d9

Browse files
committed
Move Windows-specific test to a common source set to reuse it for JVM and JS
1 parent 1af7bdb commit 72b18d9

File tree

10 files changed

+26
-9
lines changed

10 files changed

+26
-9
lines changed

core/mingw/test/files/SmokeFileTestWindows.kt renamed to core/common/test/files/SmokeFileTestWindows.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
/*
2-
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
2+
* Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors.
33
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE.txt file.
44
*/
55

66
package kotlinx.io.files
77

8+
import kotlinx.io.isWindows
89
import kotlin.test.*
910

1011
class SmokeFileTestWindows {
1112
@Test
1213
fun isAbsolute() {
14+
if (!isWindows) return
1315
assertTrue(Path("C:\\").isAbsolute)
1416
assertTrue(Path("C:/").isAbsolute)
1517
assertTrue(Path("C:/../").isAbsolute)
@@ -21,6 +23,7 @@ class SmokeFileTestWindows {
2123

2224
@Test
2325
fun getParent() {
26+
if (!isWindows) return
2427
assertNull(Path("C:\\").parent)
2528
assertNull(Path("a\\b").parent?.parent)
2629
assertEquals(Path("\\\\server"), Path("\\\\server\\share").parent)
@@ -30,6 +33,7 @@ class SmokeFileTestWindows {
3033

3134
@Test
3235
fun trailingSeparatorsTrimming() {
36+
if (!isWindows) return
3337
assertEquals(".", Path(".\\").toString())
3438
assertEquals("C:\\", Path("C:\\").toString())
3539
assertEquals("C:\\", Path("C:\\\\").toString())

core/common/test/util.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,5 @@ fun Char.repeat(count: Int): String {
7171
fun assertArrayEquals(a: ByteArray, b: ByteArray) {
7272
assertEquals(a.contentToString(), b.contentToString())
7373
}
74+
75+
expect val isWindows: Boolean

core/js/src/-PlatfromJs.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,5 @@ public actual open class IOException actual constructor(
2121
public actual open class EOFException actual constructor(message: String?) : IOException(message) {
2222
public actual constructor() : this(null)
2323
}
24+
25+
internal val isWindows_ = os.platform() == "win32"

core/js/src/files/FileSystemJs.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55

66
package kotlinx.io.files
77

8-
import kotlinx.io.IOException
9-
import kotlinx.io.RawSink
10-
import kotlinx.io.RawSource
8+
import kotlinx.io.*
9+
import kotlinx.io.buffer
10+
import kotlinx.io.fs
11+
import kotlinx.io.os
1112

1213
public actual val SystemFileSystem: FileSystem = object : SystemFileSystemImpl() {
1314
override fun exists(path: Path): Boolean {

core/js/src/files/PathsJs.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public actual class Path internal constructor(
1717
get() {
1818
check(pathLib !== null) { "Path module not found" }
1919
if (path.isEmpty()) return null
20-
if (isWindows) {
20+
if (isWindows_) {
2121
if (!path.contains(UnixPathSeparator) && !path.contains(WindowsPathSeparator)) {
2222
return null
2323
}
@@ -74,8 +74,6 @@ public actual val SystemPathSeparator: Char by lazy {
7474

7575
private const val WindowsPathSeparator: Char = '\\'
7676
private const val UnixPathSeparator: Char = '/'
77-
private val isWindows = os.platform() == "win32"
78-
7977
public actual fun Path(path: String): Path {
8078
return Path(path, null)
8179
}
@@ -164,7 +162,7 @@ private fun isUnc(path: String): Boolean {
164162
}
165163

166164
internal fun removeTrailingSeparators(path: String): String {
167-
if (isWindows) {
165+
if (isWindows_) {
168166
// don't trim the path separator right after the drive name
169167
val limit = if (path.length > 1) {
170168
if (path[1] == ':') {

core/js/src/files/imports.kt renamed to core/js/src/imports.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE.txt file.
44
*/
55

6-
package kotlinx.io.files
6+
package kotlinx.io
77

88
internal val os: dynamic
99
get(): dynamic {

core/js/test/utils.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,5 @@ actual fun tempFileName(): String {
4747
return fullpath
4848
}
4949
}
50+
51+
actual val isWindows: Boolean = isWindows_

core/jvm/test/utilJVM.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,5 @@ actual fun tempFileName(): String {
2424
fun assertByteArrayEquals(expectedUtf8: String, b: ByteArray) {
2525
assertEquals(expectedUtf8, b.toString(Charsets.UTF_8))
2626
}
27+
28+
actual val isWindows: Boolean = System.getProperty("os.name")?.startsWith("Windows") ?: false

core/native/test/util.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import kotlinx.cinterop.UnsafeNumber
1111
import kotlinx.io.files.SystemTemporaryDirectory
1212
import platform.posix.F_OK
1313
import platform.posix.access
14+
import kotlin.experimental.ExperimentalNativeApi
1415
import kotlin.random.Random
1516

1617
@OptIn(UnsafeNumber::class, ExperimentalStdlibApi::class)
@@ -25,3 +26,6 @@ actual fun tempFileName(): String {
2526
}
2627
throw IOException("Failed to generate temp file name")
2728
}
29+
30+
@OptIn(ExperimentalNativeApi::class)
31+
actual val isWindows: Boolean = Platform.osFamily == OsFamily.WINDOWS

core/wasm/test/utils.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ package kotlinx.io
88
import kotlinx.io.files.unsupported
99

1010
actual fun tempFileName(): String = unsupported()
11+
12+
actual val isWindows: Boolean = false

0 commit comments

Comments
 (0)