[minor] refactor scripting tests: extract cli testdata into separate dir, remove annotation
This commit is contained in:
Vendored
Vendored
Vendored
@@ -36,28 +36,24 @@ import kotlin.script.experimental.jvm.defaultJvmScriptingHostConfiguration
|
|||||||
import kotlin.script.experimental.jvm.dependenciesFromCurrentContext
|
import kotlin.script.experimental.jvm.dependenciesFromCurrentContext
|
||||||
import kotlin.script.experimental.jvm.jvm
|
import kotlin.script.experimental.jvm.jvm
|
||||||
|
|
||||||
private const val testDataPath = "compiler/testData/script/"
|
private const val testDataPath = "compiler/testData/script/cliCompilation"
|
||||||
|
|
||||||
class ScriptCliCompilationTest : KtUsefulTestCase() {
|
class ScriptCliCompilationTest : KtUsefulTestCase() {
|
||||||
|
|
||||||
@Test
|
|
||||||
fun testPrerequisites() {
|
fun testPrerequisites() {
|
||||||
Assert.assertTrue(thisClasspath.isNotEmpty())
|
Assert.assertTrue(thisClasspath.isNotEmpty())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
fun testSimpleScript() {
|
fun testSimpleScript() {
|
||||||
val out = checkRun("hello.kts")
|
val out = checkRun("hello.kts")
|
||||||
Assert.assertEquals("Hello from basic script!", out)
|
Assert.assertEquals("Hello from basic script!", out)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
fun testSimpleScriptWithArgs() {
|
fun testSimpleScriptWithArgs() {
|
||||||
val out = checkRun("hello_args.kts", listOf("kotlin"))
|
val out = checkRun("hello_args.kts", listOf("kotlin"))
|
||||||
Assert.assertEquals("Hello, kotlin!", out)
|
Assert.assertEquals("Hello, kotlin!", out)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
fun testScriptWithRequire() {
|
fun testScriptWithRequire() {
|
||||||
val out = checkRun("hello.req1.kts", scriptDef = TestScriptWithRequire::class)
|
val out = checkRun("hello.req1.kts", scriptDef = TestScriptWithRequire::class)
|
||||||
Assert.assertEquals("Hello from required!", out)
|
Assert.assertEquals("Hello from required!", out)
|
||||||
@@ -128,9 +124,12 @@ object TestScriptWithRequireConfiguration : ScriptCompilationConfiguration(
|
|||||||
}
|
}
|
||||||
refineConfiguration {
|
refineConfiguration {
|
||||||
onAnnotations(Import::class) { context: ScriptConfigurationRefinementContext ->
|
onAnnotations(Import::class) { context: ScriptConfigurationRefinementContext ->
|
||||||
|
val scriptBaseDir = (context.script as? FileScriptSource)?.file?.parentFile
|
||||||
val sources = context.collectedData?.get(ScriptCollectedData.foundAnnotations)
|
val sources = context.collectedData?.get(ScriptCollectedData.foundAnnotations)
|
||||||
?.flatMap {
|
?.flatMap {
|
||||||
(it as? Import)?.sources?.map { sourceName -> FileScriptSource(File(testDataPath, sourceName)) } ?: emptyList()
|
(it as? Import)?.sources?.map { sourceName ->
|
||||||
|
FileScriptSource(scriptBaseDir?.resolve(sourceName) ?: File(sourceName))
|
||||||
|
} ?: emptyList()
|
||||||
}
|
}
|
||||||
?.takeIf { it.isNotEmpty() }
|
?.takeIf { it.isNotEmpty() }
|
||||||
?: return@onAnnotations context.compilationConfiguration.asSuccess()
|
?: return@onAnnotations context.compilationConfiguration.asSuccess()
|
||||||
|
|||||||
Reference in New Issue
Block a user