Use new kotlin.io.path API in tests
This commit is contained in:
@@ -35,7 +35,10 @@ import java.io.ByteArrayOutputStream
|
||||
import java.io.File
|
||||
import java.io.PrintStream
|
||||
import java.net.URLClassLoader
|
||||
import java.nio.file.Path
|
||||
import kotlin.io.path.*
|
||||
|
||||
@OptIn(ExperimentalPathApi::class)
|
||||
class CompilerApiTest : KotlinIntegrationTestBase() {
|
||||
|
||||
private val compilerLibDir = getCompilerLib()
|
||||
@@ -119,7 +122,7 @@ class CompilerApiTest : KotlinIntegrationTestBase() {
|
||||
verbose = true,
|
||||
reportPerf = true)
|
||||
|
||||
val logFile = createTempFile("kotlin-daemon-test.", ".log")
|
||||
val logFile: Path = createTempFile("kotlin-daemon-test.", ".log")
|
||||
|
||||
val daemonJVMOptions = configureDaemonJVMOptions("D$COMPILE_DAEMON_LOG_PATH_PROPERTY=\"${logFile.loggerCompatiblePath}\"",
|
||||
inheritMemoryLimits = false, inheritOtherJvmOptions = false, inheritAdditionalProperties = false)
|
||||
@@ -137,7 +140,8 @@ class CompilerApiTest : KotlinIntegrationTestBase() {
|
||||
}
|
||||
finally {
|
||||
KotlinCompilerClient.shutdownCompileService(compilerId, daemonOptions)
|
||||
logFile.delete()
|
||||
runCatching { logFile.deleteIfExists() }
|
||||
.onFailure { e -> println("Failed to delete log file: $e") }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -158,7 +162,7 @@ class CompilerApiTest : KotlinIntegrationTestBase() {
|
||||
verbose = true,
|
||||
reportPerf = true)
|
||||
|
||||
val logFile = createTempFile("kotlin-daemon-test.", ".log")
|
||||
val logFile: Path = createTempFile("kotlin-daemon-test.", ".log")
|
||||
|
||||
val daemonJVMOptions = configureDaemonJVMOptions("D$COMPILE_DAEMON_LOG_PATH_PROPERTY=\"${logFile.loggerCompatiblePath}\"",
|
||||
inheritMemoryLimits = false, inheritOtherJvmOptions = false, inheritAdditionalProperties = false)
|
||||
@@ -174,7 +178,8 @@ class CompilerApiTest : KotlinIntegrationTestBase() {
|
||||
}
|
||||
finally {
|
||||
KotlinCompilerClient.shutdownCompileService(compilerId, daemonOptions)
|
||||
logFile.delete()
|
||||
runCatching { logFile.deleteIfExists() }
|
||||
.onFailure { e -> println("Failed to delete log file: $e") }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,10 +36,13 @@ import java.lang.management.ManagementFactory
|
||||
import java.net.URL
|
||||
import java.net.URLClassLoader
|
||||
import java.nio.charset.Charset
|
||||
import java.nio.file.Path
|
||||
import java.rmi.server.UnicastRemoteObject
|
||||
import java.util.concurrent.CountDownLatch
|
||||
import java.util.concurrent.TimeUnit
|
||||
import kotlin.concurrent.thread
|
||||
import kotlin.io.path.ExperimentalPathApi
|
||||
import kotlin.io.path.invariantSeparatorsPath
|
||||
import kotlin.script.dependencies.Environment
|
||||
import kotlin.script.dependencies.ScriptContents
|
||||
import kotlin.script.experimental.dependencies.DependenciesResolver
|
||||
@@ -997,9 +1000,12 @@ internal inline fun withLogFile(prefix: String, suffix: String = ".log", printLo
|
||||
// if file path is given in windows form (using backslash as a separator); the reason is unknown
|
||||
// this function makes a path with forward slashed, that works on windows too
|
||||
internal val File.loggerCompatiblePath: String
|
||||
get() =
|
||||
if (OSKind.current == OSKind.Windows) absolutePath.replace('\\', '/')
|
||||
else absolutePath
|
||||
get() = invariantSeparatorsPath
|
||||
|
||||
@OptIn(ExperimentalPathApi::class)
|
||||
internal val Path.loggerCompatiblePath: String
|
||||
get() = invariantSeparatorsPath
|
||||
|
||||
|
||||
open class TestKotlinScriptDummyDependenciesResolver : DependenciesResolver {
|
||||
|
||||
|
||||
+6
-3
@@ -28,13 +28,16 @@ import org.junit.Assert
|
||||
import org.junit.runner.RunWith
|
||||
import java.io.File
|
||||
import java.net.URLClassLoader
|
||||
import java.nio.file.Path
|
||||
import java.util.logging.LogManager
|
||||
import java.util.logging.Logger
|
||||
import kotlin.io.path.*
|
||||
|
||||
private val logFiles = arrayListOf<String>()
|
||||
|
||||
// TODO: remove ignore annotation from tests.
|
||||
|
||||
@OptIn(ExperimentalPathApi::class)
|
||||
@RunWith(IgnoreAll::class)
|
||||
class CompilerApiTest : KotlinIntegrationTestBase() {
|
||||
|
||||
@@ -43,7 +46,7 @@ class CompilerApiTest : KotlinIntegrationTestBase() {
|
||||
|
||||
private val compilerLibDir = getCompilerLib()
|
||||
|
||||
private fun createNewLogFile(): File {
|
||||
private fun createNewLogFile(): Path {
|
||||
println("creating logFile")
|
||||
val newLogFile = createTempFile("kotlin-daemon-experimental-test.", ".log")
|
||||
println("logFile created (${newLogFile.loggerCompatiblePath})")
|
||||
@@ -51,7 +54,7 @@ class CompilerApiTest : KotlinIntegrationTestBase() {
|
||||
return newLogFile
|
||||
}
|
||||
|
||||
private val currentLogFile: File by lazy {
|
||||
private val currentLogFile: Path by lazy {
|
||||
val newLogFile = createNewLogFile()
|
||||
val cfg: String =
|
||||
"handlers = java.util.logging.FileHandler\n" +
|
||||
@@ -67,7 +70,7 @@ class CompilerApiTest : KotlinIntegrationTestBase() {
|
||||
newLogFile
|
||||
}
|
||||
|
||||
private val externalLogFile: File by lazy { createNewLogFile() }
|
||||
private val externalLogFile: Path by lazy { createNewLogFile() }
|
||||
|
||||
private val log by lazy {
|
||||
currentLogFile
|
||||
|
||||
+14
-18
@@ -3,6 +3,8 @@
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
@file:OptIn(ExperimentalPathApi::class)
|
||||
|
||||
package org.jetbrains.kotlin.daemon.experimental.integration
|
||||
|
||||
import junit.framework.TestCase
|
||||
@@ -38,6 +40,7 @@ import java.net.URL
|
||||
import java.net.URLClassLoader
|
||||
import java.nio.channels.ClosedChannelException
|
||||
import java.nio.charset.Charset
|
||||
import java.nio.file.Path
|
||||
import java.rmi.ConnectException
|
||||
import java.rmi.ConnectIOException
|
||||
import java.rmi.UnmarshalException
|
||||
@@ -46,6 +49,7 @@ import java.util.concurrent.CountDownLatch
|
||||
import java.util.concurrent.TimeUnit
|
||||
import java.util.logging.LogManager
|
||||
import kotlin.concurrent.thread
|
||||
import kotlin.io.path.*
|
||||
import kotlin.script.dependencies.Environment
|
||||
import kotlin.script.dependencies.ScriptContents
|
||||
import kotlin.script.experimental.dependencies.DependenciesResolver
|
||||
@@ -64,7 +68,7 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() {
|
||||
|
||||
val kotlinCompilerClientInstance = KotlinCompilerDaemonClient.instantiate(DaemonProtocolVariant.SOCKETS)
|
||||
|
||||
private fun createNewLogFile(): File {
|
||||
private fun createNewLogFile(): Path {
|
||||
println("creating logFile")
|
||||
val newLogFile = createTempFile("kotlin-daemon-experimental-test.", ".log")
|
||||
println("logFile created (${newLogFile.loggerCompatiblePath})")
|
||||
@@ -595,8 +599,8 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() {
|
||||
shutdownDelayMilliseconds = 1,
|
||||
runFilesPath = File(tmpdir, getTestName(true)).absolutePath
|
||||
)
|
||||
val clientFlag = createTempFile(getTestName(true), "-client.alive")
|
||||
val sessionFlag = createTempFile(getTestName(true), "-session.alive")
|
||||
val clientFlag = createTempFile(getTestName(true), "-client.alive").toFile()
|
||||
val sessionFlag = createTempFile(getTestName(true), "-session.alive").toFile()
|
||||
try {
|
||||
withLogFile("kotlin-daemon-test") { logFile ->
|
||||
val daemonJVMOptions = makeTestDaemonJvmOptions(logFile)
|
||||
@@ -635,8 +639,8 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() {
|
||||
shutdownDelayMilliseconds = 1,
|
||||
runFilesPath = File(tmpdir, getTestName(true)).absolutePath
|
||||
)
|
||||
val clientFlag = createTempFile(getTestName(true), "-client.alive")
|
||||
val sessionFlag = createTempFile(getTestName(true), "-session.alive")
|
||||
val clientFlag = createTempFile(getTestName(true), "-client.alive").toFile()
|
||||
val sessionFlag = createTempFile(getTestName(true), "-session.alive").toFile()
|
||||
try {
|
||||
withLogFile("kotlin-daemon-test") { logFile ->
|
||||
val daemonJVMOptions = makeTestDaemonJvmOptions(logFile)
|
||||
@@ -678,8 +682,8 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() {
|
||||
shutdownDelayMilliseconds = 3000,
|
||||
runFilesPath = File(tmpdir, getTestName(true)).absolutePath
|
||||
)
|
||||
val clientFlag = createTempFile(getTestName(true), "-client.alive")
|
||||
val clientFlag2 = createTempFile(getTestName(true), "-client.alive")
|
||||
val clientFlag = createTempFile(getTestName(true), "-client.alive").toFile()
|
||||
val clientFlag2 = createTempFile(getTestName(true), "-client.alive").toFile()
|
||||
try {
|
||||
withLogFile("kotlin-daemon-test") { logFile ->
|
||||
val daemonJVMOptions = makeTestDaemonJvmOptions(logFile)
|
||||
@@ -769,8 +773,7 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() {
|
||||
assertEquals("Compilation failed:\n$resOutput", 0, resCode)
|
||||
println("OK")
|
||||
} finally {
|
||||
if (clientAliveFile.exists())
|
||||
clientAliveFile.delete()
|
||||
clientAliveFile.deleteIfExists()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1427,7 +1430,7 @@ fun restoreSystemProperty(propertyName: String, backupValue: String?) {
|
||||
}
|
||||
|
||||
internal inline fun withFlagFile(prefix: String, suffix: String? = null, body: (File) -> Unit) {
|
||||
val file = createTempFile(prefix, suffix)
|
||||
val file = createTempFile(prefix, suffix).toFile()
|
||||
try {
|
||||
body(file)
|
||||
} finally {
|
||||
@@ -1436,7 +1439,7 @@ internal inline fun withFlagFile(prefix: String, suffix: String? = null, body: (
|
||||
}
|
||||
|
||||
internal inline fun withLogFile(prefix: String, suffix: String = ".log", printLogOnException: Boolean = true, body: (File) -> Unit) {
|
||||
val logFile = createTempFile(prefix, suffix)
|
||||
val logFile = createTempFile(prefix, suffix).toFile()
|
||||
println("LOG FILE : ${logFile.path}")
|
||||
try {
|
||||
body(logFile)
|
||||
@@ -1449,13 +1452,6 @@ internal inline fun withLogFile(prefix: String, suffix: String = ".log", printLo
|
||||
}
|
||||
}
|
||||
|
||||
// java.util.Logger used in the daemon silently forgets to log into a file specified in the config on Windows,
|
||||
// if file path is given in windows form (using backslash as a separator); the reason is unknown
|
||||
// this function makes a path with forward slashed, that works on windows too
|
||||
internal val File.loggerCompatiblePath: String
|
||||
get() =
|
||||
if (OSKind.current == OSKind.Windows) absolutePath.replace('\\', '/')
|
||||
else absolutePath
|
||||
|
||||
open class TestKotlinScriptDummyDependenciesResolver : DependenciesResolver {
|
||||
|
||||
|
||||
+2
@@ -24,6 +24,7 @@ import java.io.ObjectInputStream
|
||||
import java.io.ObjectOutputStream
|
||||
import java.net.InetSocketAddress
|
||||
import java.util.logging.Logger
|
||||
import kotlin.io.path.*
|
||||
|
||||
@OptIn(KtorExperimentalAPI::class)
|
||||
class TestServer(val serverPort: Int = 6999) {
|
||||
@@ -44,6 +45,7 @@ val testServer = TestServer()
|
||||
|
||||
@RunWith(IgnoreAll::class)
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@OptIn(ExperimentalPathApi::class)
|
||||
class ClientSerializationTest : KotlinIntegrationTestBase() {
|
||||
|
||||
val file = createTempFile()
|
||||
|
||||
+6
-3
@@ -31,11 +31,14 @@ import java.io.ByteArrayOutputStream
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
import java.io.PrintStream
|
||||
import java.nio.file.Path
|
||||
import java.util.*
|
||||
import java.util.logging.LogManager
|
||||
import java.util.logging.Logger
|
||||
import kotlin.concurrent.schedule
|
||||
import kotlin.io.path.*
|
||||
|
||||
@OptIn(ExperimentalPathApi::class)
|
||||
@RunWith(IgnoreAll::class)
|
||||
class ConnectionsTest : KotlinIntegrationTestBase() {
|
||||
|
||||
@@ -247,15 +250,15 @@ class ConnectionsTest : KotlinIntegrationTestBase() {
|
||||
extraAction
|
||||
)
|
||||
|
||||
private val clientFiles = arrayListOf<File>()
|
||||
private val clientFiles = mutableListOf<Path>()
|
||||
private fun generateClient(): String {
|
||||
val file = createTempFile(getTestName(true), ".alive")
|
||||
clientFiles.add(file)
|
||||
return file.absolutePath
|
||||
return file.toAbsolutePath().toString()
|
||||
}
|
||||
|
||||
private fun deleteClients() {
|
||||
clientFiles.forEach { it.delete() }
|
||||
clientFiles.forEach { it.deleteIfExists() }
|
||||
}
|
||||
|
||||
private fun endTest() {
|
||||
|
||||
Reference in New Issue
Block a user