diff --git a/kotlin-native/backend.native/tests/build.gradle b/kotlin-native/backend.native/tests/build.gradle index 2f67d8245dc..124cef3e80a 100644 --- a/kotlin-native/backend.native/tests/build.gradle +++ b/kotlin-native/backend.native/tests/build.gradle @@ -717,13 +717,13 @@ task stringTrim(type: KonanLocalTest) { standaloneTest("hello1") { useGoldenData = true - testData = "Hello World\n" + useTestData = true source = "runtime/basic/hello1.kt" } standaloneTest("hello2") { useGoldenData = true - testData = "Hello World\n" + useTestData = true source = "runtime/basic/hello2.kt" } @@ -775,13 +775,13 @@ standaloneTest("entry4") { standaloneTest("readline0") { useGoldenData = true - testData = "41\r\n" + useTestData = true source = "runtime/basic/readline0.kt" } standaloneTest("readline1") { useGoldenData = true - testData = "\n" + useTestData = true source = "runtime/basic/readline1.kt" } @@ -5694,7 +5694,7 @@ if (UtilsKt.supportsRunningTestsOnDevice(target)) { // Exclude tasks that cannot be run on device project.tasks .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 it instanceof KonanInteropTest || it instanceof KonanDynamicTest || diff --git a/kotlin-native/backend.native/tests/runtime/basic/hello1.in b/kotlin-native/backend.native/tests/runtime/basic/hello1.in new file mode 100644 index 00000000000..557db03de99 --- /dev/null +++ b/kotlin-native/backend.native/tests/runtime/basic/hello1.in @@ -0,0 +1 @@ +Hello World diff --git a/kotlin-native/backend.native/tests/runtime/basic/hello2.in b/kotlin-native/backend.native/tests/runtime/basic/hello2.in new file mode 100644 index 00000000000..557db03de99 --- /dev/null +++ b/kotlin-native/backend.native/tests/runtime/basic/hello2.in @@ -0,0 +1 @@ +Hello World diff --git a/kotlin-native/backend.native/tests/runtime/basic/readline0.in b/kotlin-native/backend.native/tests/runtime/basic/readline0.in new file mode 100644 index 00000000000..87523dd7a06 --- /dev/null +++ b/kotlin-native/backend.native/tests/runtime/basic/readline0.in @@ -0,0 +1 @@ +41 diff --git a/kotlin-native/backend.native/tests/runtime/basic/readline1.in b/kotlin-native/backend.native/tests/runtime/basic/readline1.in new file mode 100644 index 00000000000..8b137891791 --- /dev/null +++ b/kotlin-native/backend.native/tests/runtime/basic/readline1.in @@ -0,0 +1 @@ + diff --git a/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/KotlinNativeTest.kt b/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/KotlinNativeTest.kt index 2a9daa18152..c9e39893528 100644 --- a/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/KotlinNativeTest.kt +++ b/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/KotlinNativeTest.kt @@ -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 @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. @@ -278,8 +292,9 @@ open class KonanLocalTest : KonanTest() { var output = ProcessOutput("", "", 0) for (i in 1..times) { val args = arguments + (multiArguments?.get(i - 1) ?: emptyList()) + val testData = this.testData output += if (testData != null) - runProcessWithInput({ project.executor.execute(it) }, executable, args, testData!!) + runProcessWithInput({ project.executor.execute(it) }, executable, args, testData) else runProcess({ project.executor.execute(it) }, executable, args) }