[K/N][tests] Migrate console runtime tests to new testing infra ^KT-61259

This commit is contained in:
Alexander Shabalin
2023-11-01 13:32:25 +01:00
committed by Space Team
parent 2abf9bccba
commit 6ca8f546fe
62 changed files with 311 additions and 347 deletions
+1
View File
@@ -52,6 +52,7 @@ val cinteropTest = nativeTest("cinteropTest", "cinterop")
val debuggerTest = nativeTest("debuggerTest", "debugger")
val cachesTest = nativeTest("cachesTest", "caches")
val klibTest = nativeTest("klibTest", "klib")
val standaloneTest = nativeTest("standaloneTest", "standalone")
val testTags = findProperty("kotlin.native.tests.tags")?.toString()
// Note: arbitrary JUnit tag expressions can be used in this property.
@@ -0,0 +1,2 @@
*.in binary
*.out binary
@@ -0,0 +1,28 @@
// OUTPUT_DATA_FILE: println.out
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
import kotlinx.cinterop.toKString
fun main() {
println("Hello, world!")
println(123.toByte())
println(239)
println(true)
println(3.14159)
println('A')
println("Привет")
println("\uD800\uDC00")
println("")
// Illegal surrogate pair -> default output
println("\uDC00\uD800")
// Lone surrogate -> default output
println("\uD80012")
println("\uDC0012")
println("12\uD800")
// https://github.com/JetBrains/kotlin-native/issues/1091
val array = byteArrayOf(0xF0.toByte(), 0x9F.toByte(), 0x98.toByte(), 0xA5.toByte())
array.decodeToString().apply { println(this) }
array.toKString().apply { println(this) }
}
@@ -0,0 +1,15 @@
Hello, world!
123
239
true
3.14159
A
Привет
𐀀
12
12
12
😥
😥
@@ -0,0 +1 @@
Hello World
@@ -0,0 +1,8 @@
// INPUT_DATA_FILE: readLine.in
import kotlin.test.*
fun main() {
assertEquals("Hello World", readLine())
assertNull(readLine())
}
@@ -0,0 +1,7 @@
// INPUT_DATA_FILE: readLineEmpty.in
import kotlin.test.*
fun main() {
assertNull(readLine())
}
@@ -0,0 +1 @@
@@ -0,0 +1,8 @@
// INPUT_DATA_FILE: readLineSingleEmptyLine.in
import kotlin.test.*
fun main() {
assertEquals("", readLine())
assertNull(readLine())
}
@@ -0,0 +1,7 @@
first
second
aaaaaa bbb
c
Привет!
A very long line of input with length of more than initial buffer size
@@ -0,0 +1,16 @@
// INPUT_DATA_FILE: readln.in
import kotlin.test.*
fun main() {
assertEquals("first", readln())
assertEquals("", readln())
assertEquals("second", readln())
// NOTE: Between `bbb` and `c` is "\r\n". `readln()` treats it as a single line separator on all platforms.
assertContentEquals("aaaaaa\rbbb".encodeToByteArray(), readln().encodeToByteArray())
assertEquals("c", readln())
assertEquals("Привет!", readln())
assertEquals("A very long line of input with length of more than initial buffer size", readln())
assertNull(readlnOrNull())
assertFailsWith<RuntimeException> { readln() }
}
@@ -0,0 +1,8 @@
// INPUT_DATA_FILE: readlnEmpty.in
import kotlin.test.*
fun main() {
assertFailsWith<RuntimeException> { readln() }
assertFailsWith<RuntimeException> { readln() }
}
@@ -0,0 +1,8 @@
// INPUT_DATA_FILE: readlnOrNullEmpty.in
import kotlin.test.*
fun main() {
assertNull(readlnOrNull())
assertNull(readlnOrNull())
}
@@ -0,0 +1,93 @@
/*
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.konan.test.blackbox;
import com.intellij.testFramework.TestDataPath;
import org.jetbrains.kotlin.test.util.KtTestUtil;
import org.junit.jupiter.api.Tag;
import org.jetbrains.kotlin.konan.test.blackbox.support.EnforcedProperty;
import org.jetbrains.kotlin.konan.test.blackbox.support.ClassLevelProperty;
import org.jetbrains.kotlin.konan.test.blackbox.support.group.UseStandardTestCaseGroupProvider;
import org.jetbrains.kotlin.konan.test.blackbox.support.group.FirPipeline;
import org.jetbrains.kotlin.test.TestMetadata;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import java.io.File;
import java.util.regex.Pattern;
/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.GenerateNativeTestsKt}. DO NOT MODIFY MANUALLY */
@SuppressWarnings("all")
@TestMetadata("native/native.tests/testData/standalone")
@TestDataPath("$PROJECT_ROOT")
@Tag("standalone")
@EnforcedProperty(property = ClassLevelProperty.TEST_KIND, propertyValue = "STANDALONE_NO_TR")
@UseStandardTestCaseGroupProvider()
@Tag("frontend-fir")
@FirPipeline()
public class FirNativeStandaloneTestGenerated extends AbstractNativeBlackBoxTest {
@Test
public void testAllFilesPresentInStandalone() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("native/native.tests/testData/standalone"), Pattern.compile("^(.+)\\.kt$"), null, true);
}
@Nested
@TestMetadata("native/native.tests/testData/standalone/console")
@TestDataPath("$PROJECT_ROOT")
@Tag("standalone")
@EnforcedProperty(property = ClassLevelProperty.TEST_KIND, propertyValue = "STANDALONE_NO_TR")
@UseStandardTestCaseGroupProvider()
@Tag("frontend-fir")
@FirPipeline()
public class Console {
@Test
public void testAllFilesPresentInConsole() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("native/native.tests/testData/standalone/console"), Pattern.compile("^(.+)\\.kt$"), null, true);
}
@Test
@TestMetadata("println.kt")
public void testPrintln() throws Exception {
runTest("native/native.tests/testData/standalone/console/println.kt");
}
@Test
@TestMetadata("readLine.kt")
public void testReadLine() throws Exception {
runTest("native/native.tests/testData/standalone/console/readLine.kt");
}
@Test
@TestMetadata("readLineEmpty.kt")
public void testReadLineEmpty() throws Exception {
runTest("native/native.tests/testData/standalone/console/readLineEmpty.kt");
}
@Test
@TestMetadata("readLineSingleEmptyLine.kt")
public void testReadLineSingleEmptyLine() throws Exception {
runTest("native/native.tests/testData/standalone/console/readLineSingleEmptyLine.kt");
}
@Test
@TestMetadata("readln.kt")
public void testReadln() throws Exception {
runTest("native/native.tests/testData/standalone/console/readln.kt");
}
@Test
@TestMetadata("readlnEmpty.kt")
public void testReadlnEmpty() throws Exception {
runTest("native/native.tests/testData/standalone/console/readlnEmpty.kt");
}
@Test
@TestMetadata("readlnOrNullEmpty.kt")
public void testReadlnOrNullEmpty() throws Exception {
runTest("native/native.tests/testData/standalone/console/readlnOrNullEmpty.kt");
}
}
}
@@ -0,0 +1,88 @@
/*
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.konan.test.blackbox;
import com.intellij.testFramework.TestDataPath;
import org.jetbrains.kotlin.test.util.KtTestUtil;
import org.junit.jupiter.api.Tag;
import org.jetbrains.kotlin.konan.test.blackbox.support.EnforcedProperty;
import org.jetbrains.kotlin.konan.test.blackbox.support.ClassLevelProperty;
import org.jetbrains.kotlin.konan.test.blackbox.support.group.UseStandardTestCaseGroupProvider;
import org.jetbrains.kotlin.test.TestMetadata;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import java.io.File;
import java.util.regex.Pattern;
/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.GenerateNativeTestsKt}. DO NOT MODIFY MANUALLY */
@SuppressWarnings("all")
@TestMetadata("native/native.tests/testData/standalone")
@TestDataPath("$PROJECT_ROOT")
@Tag("standalone")
@EnforcedProperty(property = ClassLevelProperty.TEST_KIND, propertyValue = "STANDALONE_NO_TR")
@UseStandardTestCaseGroupProvider()
public class NativeStandaloneTestGenerated extends AbstractNativeBlackBoxTest {
@Test
public void testAllFilesPresentInStandalone() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("native/native.tests/testData/standalone"), Pattern.compile("^(.+)\\.kt$"), null, true);
}
@Nested
@TestMetadata("native/native.tests/testData/standalone/console")
@TestDataPath("$PROJECT_ROOT")
@Tag("standalone")
@EnforcedProperty(property = ClassLevelProperty.TEST_KIND, propertyValue = "STANDALONE_NO_TR")
@UseStandardTestCaseGroupProvider()
public class Console {
@Test
public void testAllFilesPresentInConsole() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("native/native.tests/testData/standalone/console"), Pattern.compile("^(.+)\\.kt$"), null, true);
}
@Test
@TestMetadata("println.kt")
public void testPrintln() throws Exception {
runTest("native/native.tests/testData/standalone/console/println.kt");
}
@Test
@TestMetadata("readLine.kt")
public void testReadLine() throws Exception {
runTest("native/native.tests/testData/standalone/console/readLine.kt");
}
@Test
@TestMetadata("readLineEmpty.kt")
public void testReadLineEmpty() throws Exception {
runTest("native/native.tests/testData/standalone/console/readLineEmpty.kt");
}
@Test
@TestMetadata("readLineSingleEmptyLine.kt")
public void testReadLineSingleEmptyLine() throws Exception {
runTest("native/native.tests/testData/standalone/console/readLineSingleEmptyLine.kt");
}
@Test
@TestMetadata("readln.kt")
public void testReadln() throws Exception {
runTest("native/native.tests/testData/standalone/console/readln.kt");
}
@Test
@TestMetadata("readlnEmpty.kt")
public void testReadlnEmpty() throws Exception {
runTest("native/native.tests/testData/standalone/console/readlnEmpty.kt");
}
@Test
@TestMetadata("readlnOrNullEmpty.kt")
public void testReadlnOrNullEmpty() throws Exception {
runTest("native/native.tests/testData/standalone/console/readlnOrNullEmpty.kt");
}
}
}
@@ -399,6 +399,29 @@ fun main() {
model("klib/header-klibs/compilation", extension = null, recursive = false)
}
}
// Plain executable tests
testGroup("native/native.tests/tests-gen", "native/native.tests/testData") {
testClass<AbstractNativeBlackBoxTest>(
suiteTestClassName = "NativeStandaloneTestGenerated",
annotations = listOf(
*standalone(),
provider<UseStandardTestCaseGroupProvider>(),
)
) {
model("standalone")
}
testClass<AbstractNativeBlackBoxTest>(
suiteTestClassName = "FirNativeStandaloneTestGenerated",
annotations = listOf(
*standalone(),
provider<UseStandardTestCaseGroupProvider>(),
*frontendFir(),
)
) {
model("standalone")
}
}
}
}
@@ -441,3 +464,11 @@ private fun infrastructure() = annotation(Tag::class.java, "infrastructure")
private fun k1libContents() = annotation(Tag::class.java, "k1libContents")
private fun k2libContents() = annotation(Tag::class.java, "k2libContents")
private fun atomicfuNative() = annotation(Tag::class.java, "atomicfu-native")
private fun standalone() = arrayOf(
annotation(Tag::class.java, "standalone"),
annotation(
EnforcedProperty::class.java,
"property" to ClassLevelProperty.TEST_KIND,
"propertyValue" to "STANDALONE_NO_TR"
)
)