Skip to content

Commit caa6a20

Browse files
committed
fixed tests of expressions-converter for java 11
1 parent 63da3cd commit caa6a20

File tree

3 files changed

+67
-1
lines changed

3 files changed

+67
-1
lines changed

plugins/expressions-converter/build.gradle.kts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ dependencies {
3838

3939
tasks.test {
4040
useJUnitPlatform()
41+
// gets the path to JDK 11 either from gradle.properties or from the system property, defaulting to java.home
42+
environment(
43+
"JDK_11_0",
44+
project.properties["JDK_11_0"] ?: System.getProperty("JDK_11_0", System.getProperty("java.home")),
45+
)
4146
doFirst {
4247
setLibraryProperty("org.jetbrains.kotlin.test.kotlin-stdlib", "kotlin-stdlib")
4348
setLibraryProperty("org.jetbrains.kotlin.test.kotlin-reflect", "kotlin-reflect")

plugins/expressions-converter/tests/org/jetbrains/kotlinx/dataframe/AbstractExplainerBlackBoxCodegenTest.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,18 @@ import org.jetbrains.kotlin.test.model.DependencyKind
2323
import org.jetbrains.kotlin.test.model.FrontendKinds
2424
import org.jetbrains.kotlin.test.model.TestModule
2525
import org.jetbrains.kotlin.test.services.RuntimeClasspathProvider
26+
import org.jetbrains.kotlin.test.services.TemporaryDirectoryManager
2627
import org.jetbrains.kotlin.test.services.TestServices
2728
import org.jetbrains.kotlin.test.services.configuration.CommonEnvironmentConfigurator
2829
import org.jetbrains.kotlin.test.services.configuration.JvmEnvironmentConfigurator
30+
import org.jetbrains.kotlinx.dataframe.services.TemporaryDirectoryManagerImplFixed
2931
import java.io.File
3032

3133
open class AbstractExplainerBlackBoxCodegenTest : BaseTestRunner() {
3234

3335
override fun TestConfigurationBuilder.configuration() {
3436
globalDefaults {
35-
frontend = FrontendKinds.ClassicFrontend
37+
frontend = FrontendKinds.ClassicAndFIR
3638
targetPlatform = JvmPlatforms.jvm11
3739
dependencyKind = DependencyKind.Binary
3840
targetBackend = TargetBackend.JVM_IR
@@ -65,6 +67,7 @@ open class AbstractExplainerBlackBoxCodegenTest : BaseTestRunner() {
6567
useConfigurators(::JvmEnvironmentConfigurator, ::CommonEnvironmentConfigurator, ::PluginAnnotationsProvider)
6668
useCustomRuntimeClasspathProviders(::MyClasspathProvider)
6769
useAfterAnalysisCheckers(::BlackBoxCodegenSuppressor)
70+
useAdditionalService<TemporaryDirectoryManager>(::TemporaryDirectoryManagerImplFixed)
6871
}
6972

7073
class MyClasspathProvider(testServices: TestServices) : RuntimeClasspathProvider(testServices) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package org.jetbrains.kotlinx.dataframe.services
2+
3+
import org.jetbrains.kotlin.test.services.TemporaryDirectoryManager
4+
import org.jetbrains.kotlin.test.services.TestServices
5+
import org.jetbrains.kotlin.test.services.testInfo
6+
import org.jetbrains.kotlin.test.util.KtTestUtil
7+
import java.io.File
8+
import java.nio.file.Paths
9+
import java.util.Locale
10+
import kotlin.io.path.ExperimentalPathApi
11+
import kotlin.io.path.deleteRecursively
12+
13+
// Copied from org.jetbrains.kotlin.test.services.impl.TemporaryDirectoryManagerImpl
14+
// because it uses NioFiles#deleteRecursively and throws method not found as a result.
15+
class TemporaryDirectoryManagerImplFixed(testServices: TestServices) : TemporaryDirectoryManager(testServices) {
16+
private val cache = mutableMapOf<String, File>()
17+
private val rootTempDir = lazy {
18+
val testInfo = testServices.testInfo
19+
val className = testInfo.className
20+
val methodName = testInfo.methodName
21+
if (!onWindows && className.length + methodName.length < 255) {
22+
return@lazy KtTestUtil.tmpDirForTest(className, methodName)
23+
}
24+
25+
// This code will simplify directory name for windows. This is needed because there can occur errors due to long name
26+
val lastDot = className.lastIndexOf('.')
27+
val simplifiedClassName = className.substring(lastDot + 1).getOnlyUpperCaseSymbols()
28+
val simplifiedMethodName = methodName.getOnlyUpperCaseSymbols()
29+
KtTestUtil.tmpDirForTest(simplifiedClassName, simplifiedMethodName)
30+
}
31+
32+
override val rootDir: File
33+
get() = rootTempDir.value
34+
35+
override fun getOrCreateTempDirectory(name: String): File =
36+
cache.getOrPut(name) {
37+
KtTestUtil.tmpDir(rootDir, name)
38+
}
39+
40+
@OptIn(ExperimentalPathApi::class)
41+
override fun cleanupTemporaryDirectories() {
42+
cache.clear()
43+
44+
if (rootTempDir.isInitialized()) {
45+
Paths.get(rootDir.path).deleteRecursively()
46+
}
47+
}
48+
49+
companion object {
50+
private val onWindows: Boolean =
51+
System.getProperty("os.name").lowercase(Locale.getDefault()).contains("windows")
52+
53+
private fun String.getOnlyUpperCaseSymbols(): String =
54+
this.filter { it.isUpperCase() || it == '$' }
55+
.toList()
56+
.joinToString(separator = "")
57+
}
58+
}

0 commit comments

Comments
 (0)