[minor] refactor scripting tests: extract cli testdata into separate dir, remove annotation

This commit is contained in:
Ilya Chernikov
2018-12-18 18:03:56 +01:00
parent c165666d94
commit 48965fb64a
5 changed files with 5 additions and 6 deletions
@@ -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()