Fix IR compilation for empty script
#KT-46646 fixed
This commit is contained in:
committed by
TeamCityServer
parent
3a0e3798ec
commit
d365d7c784
+22
-1
@@ -24,6 +24,7 @@ import org.jetbrains.kotlin.test.TestJdkKind
|
||||
import org.jetbrains.kotlin.utils.PathUtil
|
||||
import org.junit.Assert
|
||||
import java.io.File
|
||||
import java.nio.file.Files
|
||||
import kotlin.reflect.KClass
|
||||
import kotlin.script.experimental.annotations.KotlinScript
|
||||
import kotlin.script.experimental.api.*
|
||||
@@ -45,6 +46,19 @@ class ScriptCliCompilationTest : TestCase() {
|
||||
Assert.assertEquals("Hello from basic script!", out)
|
||||
}
|
||||
|
||||
fun testEmptyScript() {
|
||||
val emptyFile = Files.createTempFile("empty",".kts").toFile()
|
||||
try {
|
||||
Assert.assertTrue(
|
||||
"Script file is not empty",
|
||||
emptyFile.exists() && emptyFile.isFile && emptyFile.length() == 0L
|
||||
)
|
||||
checkRun(emptyFile)
|
||||
} finally {
|
||||
emptyFile.delete()
|
||||
}
|
||||
}
|
||||
|
||||
fun testSimpleScriptWithArgs() {
|
||||
val out = checkRun("hello_args.kts", listOf("kotlin"))
|
||||
Assert.assertEquals("Hello, kotlin!", out)
|
||||
@@ -92,9 +106,16 @@ class ScriptCliCompilationTest : TestCase() {
|
||||
args: List<String> = emptyList(),
|
||||
scriptDef: KClass<*>? = null,
|
||||
classpath: List<File> = emptyList()
|
||||
): String = checkRun(File(testDataPath, scriptFileName), args, scriptDef, classpath)
|
||||
|
||||
private fun checkRun(
|
||||
scriptFile: File,
|
||||
args: List<String> = emptyList(),
|
||||
scriptDef: KClass<*>? = null,
|
||||
classpath: List<File> = emptyList()
|
||||
): String =
|
||||
captureOut {
|
||||
val res = runCompiler(File(testDataPath, scriptFileName), args, scriptDef, classpath)
|
||||
val res = runCompiler(scriptFile, args, scriptDef, classpath)
|
||||
val resMessage = lazy {
|
||||
"Compilation results:\n" + res.second.toString()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user