Enable K2 scripting tests
This commit is contained in:
committed by
Space Team
parent
266a223460
commit
480ea80fc4
@@ -56,5 +56,5 @@ projectTest(parallel = true) {
|
||||
projectTest(taskName = "testWithK2", parallel = true) {
|
||||
dependsOn(":dist")
|
||||
workingDir = rootDir
|
||||
systemProperty("kotlin.script.base.compiler.arguments", "-Xuse-k2")
|
||||
systemProperty("kotlin.script.base.compiler.arguments", "-language-version 2.0")
|
||||
}
|
||||
|
||||
+5
-5
@@ -43,7 +43,7 @@ class CachingTest : TestCase() {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testSimpleImportWithMemoryCache() {
|
||||
fun testSimpleImportWithMemoryCache() = expectTestToFailOnK2 {
|
||||
val cache = SimpleMemoryScriptsCache()
|
||||
checkWithCache(
|
||||
cache, scriptWithImport, scriptWithImportExpectedOutput,
|
||||
@@ -63,7 +63,7 @@ class CachingTest : TestCase() {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testSimpleImportWithFileCache() {
|
||||
fun testSimpleImportWithFileCache() = expectTestToFailOnK2 {
|
||||
withTempDir("scriptingTestCache") { cacheDir ->
|
||||
val cache = FileBasedScriptCache(cacheDir)
|
||||
Assert.assertEquals(true, cache.baseDir.listFiles()?.isEmpty())
|
||||
@@ -90,7 +90,7 @@ class CachingTest : TestCase() {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testSimpleImportWithJarCache() {
|
||||
fun testSimpleImportWithJarCache() = expectTestToFailOnK2 {
|
||||
withTempDir("scriptingTestJarCache") { cacheDir ->
|
||||
val cache = TestCompiledScriptJarsCache(cacheDir)
|
||||
Assert.assertTrue(cache.baseDir.listFiles()!!.isEmpty())
|
||||
@@ -110,7 +110,7 @@ class CachingTest : TestCase() {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testImplicitReceiversWithJarCache() {
|
||||
fun testImplicitReceiversWithJarCache() = expectTestToFailOnK2 {
|
||||
withTempDir("scriptingTestJarCache") { cacheDir ->
|
||||
val cache = TestCompiledScriptJarsCache(cacheDir)
|
||||
Assert.assertTrue(cache.baseDir.listFiles()!!.isEmpty())
|
||||
@@ -181,7 +181,7 @@ class CachingTest : TestCase() {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testLocalDependencyWithExternalLoadAndCache() {
|
||||
fun testLocalDependencyWithExternalLoadAndCache() = expectTestToFailOnK2 {
|
||||
withTempDir("scriptingTestDepDir") { depDir ->
|
||||
val standardJars = KotlinJars.kotlinScriptStandardJars
|
||||
val outJar = makeDependenciesJar(depDir, standardJars)
|
||||
|
||||
+2
-2
@@ -13,7 +13,7 @@ import kotlin.test.assertTrue
|
||||
class CapturingTest {
|
||||
|
||||
@Test
|
||||
fun testScriptWithImplicitReceiverAndSimpleCapturing() {
|
||||
fun testScriptWithImplicitReceiverAndSimpleCapturing() = expectTestToFailOnK2 {
|
||||
// Reproducing (a bit extended) scenario from KT-53947: without the fix, in the presence of the implicit receiver
|
||||
// of the same type as the receiver in the `apply` function body, the lowering was incorrectly substituting
|
||||
// the correct receiver with the accessor to the implicit one
|
||||
@@ -36,7 +36,7 @@ class CapturingTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testScriptWithImplicitReceiverAndNoCapturing() {
|
||||
fun testScriptWithImplicitReceiverAndNoCapturing() = expectTestToFailOnK2 {
|
||||
// Reproducing (a bit extended) scenario from KT-53947: without the fix, in the presence of the implicit receiver
|
||||
// of the same type as the receiver in the `C2.apply` function body, the lowering was incorrectly substituting
|
||||
// the correct receiver with the accessor to the implicit one
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ import kotlin.script.experimental.jvmhost.createJvmEvaluationConfigurationFromTe
|
||||
class ConfigurationDslTest : TestCase() {
|
||||
|
||||
@Test
|
||||
fun testComposableRefinementHandlers() {
|
||||
fun testComposableRefinementHandlers() = expectTestToFailOnK2 {
|
||||
val baseConfig = createJvmCompilationConfigurationFromTemplate<SimpleScript> {
|
||||
updateClasspath(classpathFromClass<SimpleScript>())
|
||||
defaultImports(MyTestAnnotation1::class, MyTestAnnotation2::class)
|
||||
|
||||
+2
-2
@@ -24,7 +24,7 @@ class ConstructorArgumentsOrderTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testScriptWithImplicitReceiver() {
|
||||
fun testScriptWithImplicitReceiver() = expectTestToFailOnK2 {
|
||||
val res = evalString<ScriptWithImplicitReceiver>("""println(receiverString)""") {
|
||||
implicitReceivers(ImplicitReceiverClass("Hello Receiver!"))
|
||||
}
|
||||
@@ -36,7 +36,7 @@ class ConstructorArgumentsOrderTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testScriptWithBoth() {
|
||||
fun testScriptWithBoth() = expectTestToFailOnK2 {
|
||||
val res = evalString<ScriptWithBoth>("""println(providedString + receiverString)""") {
|
||||
providedProperties("providedString" to "Hello")
|
||||
implicitReceivers(ImplicitReceiverClass(" Both!"))
|
||||
|
||||
+2
-1
@@ -34,7 +34,8 @@ import kotlin.script.experimental.jvmhost.JvmScriptCompiler
|
||||
* underlying module will be introduced.
|
||||
*/
|
||||
class ImplicitsFromScriptResultTest : TestCase() {
|
||||
fun testImplicits() {
|
||||
|
||||
fun testImplicits() = expectTestToFailOnK2 {
|
||||
// the implementation of the Compiler Host doesn't work with IR - the inter-script symbol table
|
||||
// should be maintained to make it run (see latest REPL compiler implementations for details
|
||||
// TODO: consider either fix it or rewrite to the REPL compiler
|
||||
|
||||
+8
-7
@@ -41,26 +41,27 @@ class ResolveDependenciesTest : TestCase() {
|
||||
""".trimMargin()
|
||||
private val funAndValImportScript = funAndValImportScriptText.toScriptSource()
|
||||
|
||||
// All tests with dependencies from classloader are expected to fail until the KT-60443 is implemented
|
||||
@Test
|
||||
fun testResolveClassFromClassloader() {
|
||||
fun testResolveClassFromClassloader() = expectTestToFailOnK2 {
|
||||
runScriptAndCheckResult(classAccessScript, configurationWithDependenciesFromClassloader, null, 42)
|
||||
runScriptAndCheckResult(classImportScript, configurationWithDependenciesFromClassloader, null, 42)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testResolveClassFromClasspath() {
|
||||
fun testResolveClassFromClasspath() = expectTestToFailOnK2 {
|
||||
runScriptAndCheckResult(classAccessScript, configurationWithDependenciesFromClasspath, null, 42)
|
||||
runScriptAndCheckResult(classImportScript, configurationWithDependenciesFromClasspath, null, 42)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testResolveFunAndValFromClassloader() {
|
||||
fun testResolveFunAndValFromClassloader() = expectTestToFailOnK2 {
|
||||
runScriptAndCheckResult(funAndValAccessScript, configurationWithDependenciesFromClassloader, null, 42)
|
||||
runScriptAndCheckResult(funAndValImportScript, configurationWithDependenciesFromClassloader, null, 42)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testReplResolveFunAndValFromClassloader() {
|
||||
fun testReplResolveFunAndValFromClassloader() = expectTestToFailOnK2 {
|
||||
checkEvaluateInRepl(
|
||||
sequenceOf(funAndValAccessScriptText, funAndValAccessScriptText), sequenceOf(42, 42),
|
||||
configurationWithDependenciesFromClassloader,
|
||||
@@ -75,13 +76,13 @@ class ResolveDependenciesTest : TestCase() {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testResolveFunAndValFromClasspath() {
|
||||
fun testResolveFunAndValFromClasspath() = expectTestToFailOnK2 {
|
||||
runScriptAndCheckResult(funAndValAccessScript, configurationWithDependenciesFromClasspath, null, 42)
|
||||
runScriptAndCheckResult(funAndValImportScript, configurationWithDependenciesFromClasspath, null, 42)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testResolveClassFromClassloaderIsolated() {
|
||||
fun testResolveClassFromClassloaderIsolated() = expectTestToFailOnK2 {
|
||||
val evaluationConfiguration = ScriptEvaluationConfiguration {
|
||||
jvm {
|
||||
baseClassLoader(null)
|
||||
@@ -91,7 +92,7 @@ class ResolveDependenciesTest : TestCase() {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testResolveClassesFromClassloaderAndClassPath() {
|
||||
fun testResolveClassesFromClassloaderAndClassPath() = expectTestToFailOnK2 {
|
||||
val script = """
|
||||
org.jetbrains.kotlin.mainKts.MainKtsConfigurator()
|
||||
${thisPackage}.ShouldBeVisibleFromScript().x
|
||||
|
||||
+7
-7
@@ -65,7 +65,7 @@ class ScriptingHostTest : TestCase() {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testValueResult() {
|
||||
fun testValueResult() = expectTestToFailOnK2 {
|
||||
val evalScriptWithResult = evalScriptWithResult("42")
|
||||
val resVal = evalScriptWithResult as ResultValue.Value
|
||||
Assert.assertEquals(42, resVal.value)
|
||||
@@ -91,7 +91,7 @@ class ScriptingHostTest : TestCase() {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testCustomResultField() {
|
||||
fun testCustomResultField() = expectTestToFailOnK2 {
|
||||
val resVal = evalScriptWithResult("42") {
|
||||
resultField("outcome")
|
||||
} as ResultValue.Value
|
||||
@@ -190,7 +190,7 @@ class ScriptingHostTest : TestCase() {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testSimpleImport() {
|
||||
fun testSimpleImport() = expectTestToFailOnK2 {
|
||||
val greeting = listOf("Hello from helloWithVal script!", "Hello from imported helloWithVal script!")
|
||||
val script = "println(\"Hello from imported \$helloScriptName script!\")"
|
||||
val compilationConfiguration = createJvmCompilationConfigurationFromTemplate<SimpleScriptTemplate> {
|
||||
@@ -203,7 +203,7 @@ class ScriptingHostTest : TestCase() {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testSimpleImportWithImplicitReceiver() {
|
||||
fun testSimpleImportWithImplicitReceiver() = expectTestToFailOnK2 {
|
||||
val greeting = listOf("Hello from helloWithVal script!", "Hello from imported helloWithVal script!")
|
||||
val script = "println(\"Hello from imported \$helloScriptName script!\")"
|
||||
val definition = createJvmScriptDefinitionFromTemplate<SimpleScriptTemplate>(
|
||||
@@ -224,7 +224,7 @@ class ScriptingHostTest : TestCase() {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testProvidedPropertiesNullability() {
|
||||
fun testProvidedPropertiesNullability() = expectTestToFailOnK2 {
|
||||
val stringType = KotlinType(String::class)
|
||||
val definition = createJvmScriptDefinitionFromTemplate<SimpleScriptTemplate>(
|
||||
compilation = {
|
||||
@@ -273,14 +273,14 @@ class ScriptingHostTest : TestCase() {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testDiamondImportWithoutSharing() {
|
||||
fun testDiamondImportWithoutSharing() = expectTestToFailOnK2 {
|
||||
val greeting = listOf("Hi from common", "Hi from middle", "Hi from common", "sharedVar == 3")
|
||||
val output = doDiamondImportTest()
|
||||
Assert.assertEquals(greeting, output)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testDiamondImportWithSharing() {
|
||||
fun testDiamondImportWithSharing() = expectTestToFailOnK2 {
|
||||
val greeting = listOf("Hi from common", "Hi from middle", "sharedVar == 5")
|
||||
val output = doDiamondImportTest(
|
||||
ScriptEvaluationConfiguration {
|
||||
|
||||
+13
@@ -5,6 +5,7 @@
|
||||
|
||||
package kotlin.script.experimental.jvmhost.test
|
||||
|
||||
import org.jetbrains.kotlin.scripting.compiler.plugin.impl.SCRIPT_BASE_COMPILER_ARGUMENTS_PROPERTY
|
||||
import java.io.File
|
||||
import java.nio.file.Files
|
||||
|
||||
@@ -19,3 +20,15 @@ internal fun <R> withTempDir(keyName: String = "tmp", body: (File) -> R) {
|
||||
}
|
||||
}
|
||||
|
||||
fun expectTestToFailOnK2(test: () -> Unit) {
|
||||
val isK2 = System.getProperty(SCRIPT_BASE_COMPILER_ARGUMENTS_PROPERTY)?.contains("-language-version 2.0") == true
|
||||
var testFailure: Throwable? = null
|
||||
try {
|
||||
test()
|
||||
} catch (e: Throwable) {
|
||||
testFailure = e
|
||||
}
|
||||
if (isK2 && testFailure == null) throw AssertionError("The test is expected to fail on K2")
|
||||
else if (!isK2 && testFailure != null) throw testFailure
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user