build/tests: Import box() function package in the launcher
This commit is contained in:
@@ -314,20 +314,20 @@ class RunExternalTestGroup extends RunKonanTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
List<String> buildCompileList() {
|
List<String> buildCompileList() {
|
||||||
def packagePattern = ~/(?m)package\s*([a-zA-z-][a-zA-Z0-9._-]*)/
|
def packagePattern = ~/(?m)^\s*package\s+([a-zA-z-][a-zA-Z0-9._-]+)/
|
||||||
def boxPattern = ~/(?m)fun\s*box\s*\(\s*\)/
|
def boxPattern = ~/(?m)fun\s+box\s*\(\s*\)/
|
||||||
def boxPackage = ""
|
def imports = []
|
||||||
|
|
||||||
def result = super.buildCompileList()
|
def result = super.buildCompileList()
|
||||||
for (String filePath : result) {
|
for (String filePath : result) {
|
||||||
def text = project.file(filePath).text
|
def text = project.file(filePath).text
|
||||||
if (text =~ boxPattern && text =~ packagePattern){
|
if (text =~ boxPattern && text =~ packagePattern){
|
||||||
boxPackage = (text =~ packagePattern)[0][1]
|
def pkg = (text =~ packagePattern)[0][1]
|
||||||
boxPackage += '.'
|
imports.add("$pkg.*")
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
createLauncherFile("$outputDirectory/_launcher.kt", boxPackage)
|
createLauncherFile("$outputDirectory/_launcher.kt", imports)
|
||||||
result.add("$outputDirectory/_launcher.kt")
|
result.add("$outputDirectory/_launcher.kt")
|
||||||
result.add(project.file("testUtils.kt"))
|
result.add(project.file("testUtils.kt"))
|
||||||
return result
|
return result
|
||||||
@@ -336,19 +336,23 @@ class RunExternalTestGroup extends RunKonanTest {
|
|||||||
/**
|
/**
|
||||||
* There are tests that require non-trivial 'package foo' in test launcher.
|
* There are tests that require non-trivial 'package foo' in test launcher.
|
||||||
*/
|
*/
|
||||||
void createLauncherFile(String file, String pkg) {
|
void createLauncherFile(String file, List<String> imports) {
|
||||||
createFile(file, """
|
StringBuilder text = new StringBuilder("import kotlin.test.TestFailedException\n")
|
||||||
import kotlin.test.TestFailedException
|
for (v in imports) {
|
||||||
|
text.append("import ").append(v).append('\n')
|
||||||
|
}
|
||||||
|
text.append(
|
||||||
|
"""
|
||||||
fun main(args : Array<String>) {
|
fun main(args : Array<String>) {
|
||||||
@Suppress("USELESS_ELVIS")
|
@Suppress("USELESS_ELVIS")
|
||||||
val result = ${pkg}box()?:"null"
|
val result = box()?:"null"
|
||||||
println(result)
|
println(result)
|
||||||
if (result != "OK") {
|
if (result != "OK") {
|
||||||
throw TestFailedException(result)
|
throw TestFailedException(result)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
""")
|
""")
|
||||||
|
createFile(file, text.toString())
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> findLinesWithPrefixesRemoved(String text, String prefix) {
|
List<String> findLinesWithPrefixesRemoved(String text, String prefix) {
|
||||||
|
|||||||
Reference in New Issue
Block a user