Enable assertions in Kotlin Compile Daemon process
#KT-32992 Fixed
This commit is contained in:
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.daemon
|
||||
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import com.intellij.openapi.util.io.FileUtilRt
|
||||
import junit.framework.Assert
|
||||
import junit.framework.TestCase
|
||||
import org.jetbrains.kotlin.cli.AbstractCliTest
|
||||
import org.jetbrains.kotlin.cli.common.messages.MessageRenderer
|
||||
@@ -187,6 +188,53 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() {
|
||||
}
|
||||
}
|
||||
|
||||
fun testDaemonAssertsOptions() {
|
||||
val allAssetionsArgs = setOf(
|
||||
"-ea", "-enableassertions",
|
||||
"-da", "-disableassertions",
|
||||
"-esa", "-enablesystemassertions",
|
||||
"-dsa", "-disablesystemassertions"
|
||||
)
|
||||
|
||||
fun assertionsJvmArgs() = configureDaemonJVMOptions(
|
||||
inheritMemoryLimits = true,
|
||||
inheritOtherJvmOptions = false,
|
||||
inheritAdditionalProperties = true
|
||||
).mappers.flatMap { it.toArgs("-") }.filter { it in allAssetionsArgs }.joinToString(", ")
|
||||
|
||||
for (assertArgValue in allAssetionsArgs) {
|
||||
withDaemonJvmOptionsSetTo(assertArgValue) {
|
||||
Assert.assertEquals(assertArgValue, assertionsJvmArgs())
|
||||
}
|
||||
}
|
||||
|
||||
withDaemonJvmOptionsSetTo(null) {
|
||||
Assert.assertEquals("-ea", assertionsJvmArgs())
|
||||
}
|
||||
}
|
||||
|
||||
private fun withDaemonJvmOptionsSetTo(newValue: String?, fn: () -> Unit) {
|
||||
val backup = getAndSetSystemProperty(COMPILE_DAEMON_JVM_OPTIONS_PROPERTY, newValue)
|
||||
|
||||
try {
|
||||
fn()
|
||||
} finally {
|
||||
getAndSetSystemProperty(COMPILE_DAEMON_JVM_OPTIONS_PROPERTY, backup)
|
||||
}
|
||||
}
|
||||
|
||||
private fun getAndSetSystemProperty(property: String, newValue: String?): String? {
|
||||
val oldValue = System.getProperty(property)
|
||||
|
||||
if (newValue != null) {
|
||||
System.setProperty(property, newValue)
|
||||
} else {
|
||||
System.clearProperty(property)
|
||||
}
|
||||
|
||||
return oldValue
|
||||
}
|
||||
|
||||
fun testDaemonOptionsParsing() {
|
||||
val backupOptions = System.getProperty(COMPILE_DAEMON_OPTIONS_PROPERTY)
|
||||
try {
|
||||
|
||||
+48
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.daemon.experimental.integration
|
||||
|
||||
import junit.framework.Assert
|
||||
import junit.framework.TestCase
|
||||
import kotlinx.coroutines.*
|
||||
import org.jetbrains.kotlin.cli.AbstractCliTest
|
||||
@@ -264,6 +265,53 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() {
|
||||
}
|
||||
}
|
||||
|
||||
fun ignore_testDaemonAssertsOptions() {
|
||||
val allAssetionsArgs = setOf(
|
||||
"-ea", "-enableassertions",
|
||||
"-da", "-disableassertions",
|
||||
"-esa", "-enablesystemassertions",
|
||||
"-dsa", "-disablesystemassertions"
|
||||
)
|
||||
|
||||
fun assertionsJvmArgs() = configureDaemonJVMOptions(
|
||||
inheritMemoryLimits = true,
|
||||
inheritOtherJvmOptions = false,
|
||||
inheritAdditionalProperties = true
|
||||
).mappers.flatMap { it.toArgs("-") }.filter { it in allAssetionsArgs }.joinToString(", ")
|
||||
|
||||
for (assertArgValue in allAssetionsArgs) {
|
||||
withDaemonJvmOptionsSetTo(assertArgValue) {
|
||||
Assert.assertEquals(assertArgValue, assertionsJvmArgs())
|
||||
}
|
||||
}
|
||||
|
||||
withDaemonJvmOptionsSetTo(null) {
|
||||
Assert.assertEquals("-ea", assertionsJvmArgs())
|
||||
}
|
||||
}
|
||||
|
||||
private fun withDaemonJvmOptionsSetTo(newValue: String?, fn: () -> Unit) {
|
||||
val backup = getAndSetSystemProperty(COMPILE_DAEMON_JVM_OPTIONS_PROPERTY, newValue)
|
||||
|
||||
try {
|
||||
fn()
|
||||
} finally {
|
||||
getAndSetSystemProperty(COMPILE_DAEMON_JVM_OPTIONS_PROPERTY, backup)
|
||||
}
|
||||
}
|
||||
|
||||
private fun getAndSetSystemProperty(property: String, newValue: String?): String? {
|
||||
val oldValue = System.getProperty(property)
|
||||
|
||||
if (newValue != null) {
|
||||
System.setProperty(property, newValue)
|
||||
} else {
|
||||
System.clearProperty(property)
|
||||
}
|
||||
|
||||
return oldValue
|
||||
}
|
||||
|
||||
fun ignore_testDaemonOptionsParsing() {
|
||||
val backupOptions = System.getProperty(COMPILE_DAEMON_OPTIONS_PROPERTY)
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user