Compile most test scripts with runtime
This commit is contained in:
Vendored
+2
-2
@@ -2,9 +2,9 @@
|
||||
|
||||
fun fib(n: Int): Int {
|
||||
val v = if(n < 2) 1 else fib(n-1) + fib(n-2)
|
||||
System.out.println("fib($n)=$v")
|
||||
println("fib($n)=$v")
|
||||
return v
|
||||
}
|
||||
|
||||
System.out.println("num: $num")
|
||||
println("num: $num")
|
||||
val result = fib(num)
|
||||
|
||||
Vendored
+2
-2
@@ -3,9 +3,9 @@ package kotlin.scripting.fibonacci
|
||||
|
||||
fun fib(n: Int): Int {
|
||||
val v = if(n < 2) 1 else fib(n-1) + fib(n-2)
|
||||
System.out.println("fib($n)=$v")
|
||||
println("fib($n)=$v")
|
||||
return v
|
||||
}
|
||||
|
||||
System.out.println("num: $num")
|
||||
println("num: $num")
|
||||
val result = fib(num)
|
||||
|
||||
Vendored
+2
-2
@@ -2,10 +2,10 @@
|
||||
|
||||
fun fib(n: Int): Int {
|
||||
val v = if(n < 2) 1 else fib(n-1) + fib(n-2)
|
||||
System.out.println("fib($n)=$v")
|
||||
println("fib($n)=$v")
|
||||
return v
|
||||
}
|
||||
|
||||
System.out.println("num: ${param.memberNum}")
|
||||
println("num: ${param.memberNum}")
|
||||
val result = fib(param.memberNum)
|
||||
|
||||
|
||||
Vendored
+2
-2
@@ -5,10 +5,10 @@ import org.jetbrains.kotlin.scripts.*
|
||||
|
||||
fun fib(n: Int): Int {
|
||||
val v = fibCombine( { fib(it) }, n)
|
||||
System.out.println("fib($n)=$v")
|
||||
println("fib($n)=$v")
|
||||
return v
|
||||
}
|
||||
|
||||
System.out.println("num: $num")
|
||||
println("num: $num")
|
||||
val result = fib(num)
|
||||
|
||||
|
||||
Vendored
+2
-2
@@ -3,7 +3,7 @@
|
||||
|
||||
fun fib(n: Int): Int {
|
||||
val v = if(n < 2) 1 else fib(n-1) + fib(n-2)
|
||||
System.out.println("fib($n)=$v")
|
||||
println("fib($n)=$v")
|
||||
return v
|
||||
}
|
||||
|
||||
@@ -11,6 +11,6 @@ val hdr = "Num".decapitalize()
|
||||
|
||||
org.junit.Assert.assertTrue(true)
|
||||
|
||||
System.out.println("$hdr: $num")
|
||||
println("$hdr: $num")
|
||||
val result = fib(num)
|
||||
|
||||
|
||||
+2
-2
@@ -5,12 +5,12 @@
|
||||
|
||||
fun fib(n: Int): Int {
|
||||
val v = if(n < 2) 1 else fib(n-1) + fib(n-2)
|
||||
System.out.println("fib($n)=$v")
|
||||
println("fib($n)=$v")
|
||||
return v
|
||||
}
|
||||
|
||||
val hdr = "Num".decapitalize()
|
||||
|
||||
System.out.println("$hdr: $num")
|
||||
println("$hdr: $num")
|
||||
val result = fib(num)
|
||||
|
||||
|
||||
+2
-2
@@ -5,12 +5,12 @@
|
||||
|
||||
fun fib(n: Int): Int {
|
||||
val v = if(n < 2) 1 else fib(n-1) + fib(n-2)
|
||||
System.out.println("fib($n)=$v")
|
||||
println("fib($n)=$v")
|
||||
return v
|
||||
}
|
||||
|
||||
val hdr = "Num".decapitalize()
|
||||
|
||||
System.out.println("$hdr: $num")
|
||||
println("$hdr: $num")
|
||||
val result = fib(num)
|
||||
|
||||
|
||||
Vendored
+2
-2
@@ -2,12 +2,12 @@
|
||||
|
||||
fun fib(n: Int): Int {
|
||||
val v = if(n < 2) 1 else fib(n-1) + fib(n-2)
|
||||
System.out.println("fib($n)=$v")
|
||||
println("fib($n)=$v")
|
||||
return v
|
||||
}
|
||||
|
||||
val num = if (args.size > 0) java.lang.Integer.parseInt(args[0]) else 4
|
||||
val comment = if (args.size > 1) args[1] else "none"
|
||||
|
||||
System.out.println("num: $num ($comment)")
|
||||
println("num: $num ($comment)")
|
||||
val result = fib(num)
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// this script expected parameter num: Int
|
||||
|
||||
val test = num + 10
|
||||
System.out.println(test)
|
||||
println(test)
|
||||
+1
-1
@@ -1,2 +1,2 @@
|
||||
val num = 10 // check that we could declare property with the name as in the super class
|
||||
System.out.println(num)
|
||||
println(num)
|
||||
@@ -80,7 +80,9 @@ class ScriptTemplateTest {
|
||||
|
||||
@Test
|
||||
fun testScriptWithDependsAnn() {
|
||||
val aClass = compileScript("fib_ext_ann.kts", ScriptWithIntParam::class, null)
|
||||
Assert.assertNull(compileScript("fib_ext_ann.kts", ScriptWithIntParamAndDummyResolver::class, null, includeKotlinRuntime = false))
|
||||
|
||||
val aClass = compileScript("fib_ext_ann.kts", ScriptWithIntParam::class, null, includeKotlinRuntime = false)
|
||||
Assert.assertNotNull(aClass)
|
||||
val out = captureOut {
|
||||
aClass!!.getConstructor(Integer.TYPE).newInstance(4)
|
||||
@@ -90,7 +92,9 @@ class ScriptTemplateTest {
|
||||
|
||||
@Test
|
||||
fun testScriptWithDependsAnn2() {
|
||||
val aClass = compileScript("fib_ext_ann2.kts", ScriptWithIntParam::class, null)
|
||||
Assert.assertNull(compileScript("fib_ext_ann2.kts", ScriptWithIntParamAndDummyResolver::class, null, includeKotlinRuntime = false))
|
||||
|
||||
val aClass = compileScript("fib_ext_ann2.kts", ScriptWithIntParam::class, null, includeKotlinRuntime = false)
|
||||
Assert.assertNotNull(aClass)
|
||||
val out = captureOut {
|
||||
aClass!!.getConstructor(Integer.TYPE).newInstance(4)
|
||||
@@ -222,14 +226,16 @@ class ScriptTemplateTest {
|
||||
scriptTemplate: KClass<out Any>,
|
||||
environment: Map<String, Any?>? = null,
|
||||
runIsolated: Boolean = true,
|
||||
suppressOutput: Boolean = false): Class<*>? =
|
||||
compileScriptImpl("compiler/testData/script/" + scriptPath, KotlinScriptDefinitionFromTemplate(scriptTemplate, null, null, environment), runIsolated, suppressOutput)
|
||||
suppressOutput: Boolean = false,
|
||||
includeKotlinRuntime: Boolean = true): Class<*>? =
|
||||
compileScriptImpl("compiler/testData/script/" + scriptPath, KotlinScriptDefinitionFromTemplate(scriptTemplate, null, null, environment), runIsolated, suppressOutput, includeKotlinRuntime)
|
||||
|
||||
private fun compileScriptImpl(
|
||||
scriptPath: String,
|
||||
scriptDefinition: KotlinScriptDefinition,
|
||||
runIsolated: Boolean,
|
||||
suppressOutput: Boolean): Class<*>?
|
||||
suppressOutput: Boolean,
|
||||
includeKotlinRuntime: Boolean): Class<*>?
|
||||
{
|
||||
val paths = PathUtil.getKotlinPathsForDistDirectory()
|
||||
val messageCollector =
|
||||
@@ -238,7 +244,7 @@ class ScriptTemplateTest {
|
||||
|
||||
val rootDisposable = Disposer.newDisposable()
|
||||
try {
|
||||
val configuration = KotlinTestUtils.newConfiguration(ConfigurationKind.JDK_ONLY, TestJdkKind.FULL_JDK)
|
||||
val configuration = KotlinTestUtils.newConfiguration(if (includeKotlinRuntime) ConfigurationKind.ALL else ConfigurationKind.JDK_ONLY, TestJdkKind.FULL_JDK)
|
||||
configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, messageCollector)
|
||||
configuration.addKotlinSourceRoot(scriptPath)
|
||||
configuration.add(JVMConfigurationKeys.SCRIPT_DEFINITIONS, scriptDefinition)
|
||||
@@ -321,23 +327,13 @@ class TestKotlinScriptDependenciesResolver : TestKotlinScriptDummyDependenciesRe
|
||||
override val imports: Iterable<String> = listOf("org.jetbrains.kotlin.scripts.DependsOn", "org.jetbrains.kotlin.scripts.DependsOnTwo")
|
||||
}.asFuture()
|
||||
}
|
||||
|
||||
private fun classpathFromClassloader(): List<File> =
|
||||
(TestKotlinScriptDependenciesResolver::class.java.classLoader as? URLClassLoader)?.urLs
|
||||
?.mapNotNull { it.toFile() }
|
||||
?.filter { it.path.contains("out") && it.path.contains("test") }
|
||||
?: emptyList()
|
||||
|
||||
private fun URL.toFile() =
|
||||
try {
|
||||
File(toURI().schemeSpecificPart)
|
||||
}
|
||||
catch (e: URISyntaxException) {
|
||||
if (protocol != "file") null
|
||||
else File(file)
|
||||
}
|
||||
}
|
||||
|
||||
@ScriptTemplateDefinition(
|
||||
scriptFilePattern =".*\\.kts",
|
||||
resolver = TestKotlinScriptDummyDependenciesResolver::class)
|
||||
abstract class ScriptWithIntParamAndDummyResolver(val num: Int)
|
||||
|
||||
@ScriptTemplateDefinition(
|
||||
scriptFilePattern =".*\\.kts",
|
||||
resolver = TestKotlinScriptDependenciesResolver::class)
|
||||
|
||||
@@ -103,7 +103,7 @@ class ScriptTest : KtUsefulTestCase() {
|
||||
|
||||
val rootDisposable = Disposer.newDisposable()
|
||||
try {
|
||||
val configuration = KotlinTestUtils.newConfiguration(ConfigurationKind.JDK_ONLY, TestJdkKind.FULL_JDK)
|
||||
val configuration = KotlinTestUtils.newConfiguration(ConfigurationKind.ALL, TestJdkKind.FULL_JDK)
|
||||
configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, messageCollector)
|
||||
configuration.addKotlinSourceRoot(scriptPath)
|
||||
configuration.add(JVMConfigurationKeys.SCRIPT_DEFINITIONS, scriptDefinition)
|
||||
|
||||
@@ -43,4 +43,3 @@ internal fun captureOut(body: () -> Unit): String {
|
||||
System.setOut(prevOut)
|
||||
return outStream.toString()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user