From 8e91da7aad143c6250c511f47d431806a785a685 Mon Sep 17 00:00:00 2001 From: Ilya Matveev Date: Mon, 13 Mar 2017 16:43:26 +0300 Subject: [PATCH] build/tests: Import box() function package in the launcher --- .../org/jetbrains/kotlin/KonanTest.groovy | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/buildSrc/src/main/groovy/org/jetbrains/kotlin/KonanTest.groovy b/buildSrc/src/main/groovy/org/jetbrains/kotlin/KonanTest.groovy index 007da1ee4f9..0e123e94d4f 100644 --- a/buildSrc/src/main/groovy/org/jetbrains/kotlin/KonanTest.groovy +++ b/buildSrc/src/main/groovy/org/jetbrains/kotlin/KonanTest.groovy @@ -314,20 +314,20 @@ class RunExternalTestGroup extends RunKonanTest { } List buildCompileList() { - def packagePattern = ~/(?m)package\s*([a-zA-z-][a-zA-Z0-9._-]*)/ - def boxPattern = ~/(?m)fun\s*box\s*\(\s*\)/ - def boxPackage = "" + def packagePattern = ~/(?m)^\s*package\s+([a-zA-z-][a-zA-Z0-9._-]+)/ + def boxPattern = ~/(?m)fun\s+box\s*\(\s*\)/ + def imports = [] def result = super.buildCompileList() for (String filePath : result) { def text = project.file(filePath).text if (text =~ boxPattern && text =~ packagePattern){ - boxPackage = (text =~ packagePattern)[0][1] - boxPackage += '.' + def pkg = (text =~ packagePattern)[0][1] + imports.add("$pkg.*") break } } - createLauncherFile("$outputDirectory/_launcher.kt", boxPackage) + createLauncherFile("$outputDirectory/_launcher.kt", imports) result.add("$outputDirectory/_launcher.kt") result.add(project.file("testUtils.kt")) return result @@ -336,19 +336,23 @@ class RunExternalTestGroup extends RunKonanTest { /** * There are tests that require non-trivial 'package foo' in test launcher. */ - void createLauncherFile(String file, String pkg) { - createFile(file, """ -import kotlin.test.TestFailedException - + void createLauncherFile(String file, List imports) { + StringBuilder text = new StringBuilder("import kotlin.test.TestFailedException\n") + for (v in imports) { + text.append("import ").append(v).append('\n') + } + text.append( +""" fun main(args : Array) { @Suppress("USELESS_ELVIS") - val result = ${pkg}box()?:"null" + val result = box()?:"null" println(result) if (result != "OK") { throw TestFailedException(result) } } """) + createFile(file, text.toString()) } List findLinesWithPrefixesRemoved(String text, String prefix) {