[Native][tests] Move input data outside of Gradle build file

This commit is contained in:
Dmitriy Dolovov
2021-08-30 17:56:53 +03:00
parent 1a863106e6
commit bf82db5ee2
6 changed files with 27 additions and 8 deletions
@@ -717,13 +717,13 @@ task stringTrim(type: KonanLocalTest) {
standaloneTest("hello1") { standaloneTest("hello1") {
useGoldenData = true useGoldenData = true
testData = "Hello World\n" useTestData = true
source = "runtime/basic/hello1.kt" source = "runtime/basic/hello1.kt"
} }
standaloneTest("hello2") { standaloneTest("hello2") {
useGoldenData = true useGoldenData = true
testData = "Hello World\n" useTestData = true
source = "runtime/basic/hello2.kt" source = "runtime/basic/hello2.kt"
} }
@@ -775,13 +775,13 @@ standaloneTest("entry4") {
standaloneTest("readline0") { standaloneTest("readline0") {
useGoldenData = true useGoldenData = true
testData = "41\r\n" useTestData = true
source = "runtime/basic/readline0.kt" source = "runtime/basic/readline0.kt"
} }
standaloneTest("readline1") { standaloneTest("readline1") {
useGoldenData = true useGoldenData = true
testData = "\n" useTestData = true
source = "runtime/basic/readline1.kt" source = "runtime/basic/readline1.kt"
} }
@@ -5694,7 +5694,7 @@ if (UtilsKt.supportsRunningTestsOnDevice(target)) {
// Exclude tasks that cannot be run on device // Exclude tasks that cannot be run on device
project.tasks project.tasks
.withType(KonanTest.class) .withType(KonanTest.class)
.matching { (it instanceof KonanLocalTest && ((KonanLocalTest) it).testData != null) || .matching { (it instanceof KonanLocalTest && ((KonanLocalTest) it).useTestData) ||
// Filter out tests that depend on libs. TODO: copy them too // Filter out tests that depend on libs. TODO: copy them too
it instanceof KonanInteropTest || it instanceof KonanInteropTest ||
it instanceof KonanDynamicTest || it instanceof KonanDynamicTest ||
@@ -0,0 +1 @@
Hello World
@@ -0,0 +1 @@
Hello World
@@ -0,0 +1 @@
41
@@ -0,0 +1 @@
@@ -250,11 +250,25 @@ open class KonanLocalTest : KonanTest() {
} }
/** /**
* Input test data to be passed to process' stdin. * Input test data to be passed to process stdin.
*/ */
@Input @Input
@Optional @Optional
var testData: String? = null var useTestData: Boolean = false
@get:InputFile
val testDataFile: File
get() {
val sourceFile = project.file(source)
return sourceFile.parentFile.resolve(sourceFile.nameWithoutExtension + ".in")
}
private val testData: String?
get() = if (useTestData) {
check(testDataFile.isFile) { "Task $name. Test data file does not exist: $testDataFile" }
testDataFile.readText(Charsets.UTF_8)
} else
null
/** /**
* Should compiler message be read and validated with output checker or gold value. * Should compiler message be read and validated with output checker or gold value.
@@ -278,8 +292,9 @@ open class KonanLocalTest : KonanTest() {
var output = ProcessOutput("", "", 0) var output = ProcessOutput("", "", 0)
for (i in 1..times) { for (i in 1..times) {
val args = arguments + (multiArguments?.get(i - 1) ?: emptyList()) val args = arguments + (multiArguments?.get(i - 1) ?: emptyList())
val testData = this.testData
output += if (testData != null) output += if (testData != null)
runProcessWithInput({ project.executor.execute(it) }, executable, args, testData!!) runProcessWithInput({ project.executor.execute(it) }, executable, args, testData)
else else
runProcess({ project.executor.execute(it) }, executable, args) runProcess({ project.executor.execute(it) }, executable, args)
} }