[K2/N] Add klib contents serialization tests from old testinfra

Merge-request: KT-MR-8509
Merged-by: Vladimir Sukharev <Vladimir.Sukharev@jetbrains.com>
This commit is contained in:
Vladimir Sukharev
2023-01-27 23:30:45 +00:00
committed by Space Team
parent 8bc2aaa295
commit debbfa8397
41 changed files with 838 additions and 7 deletions
@@ -0,0 +1,14 @@
package test
annotation class Anno(val value: String = "0", val x: Int = 0)
annotation class Bnno
enum class Eee {
@Anno()
Entry1,
Entry2,
@Anno("3") @Bnno
Entry3,
@Anno("4", 4)
Entry4,
}
@@ -0,0 +1,11 @@
annotation class Anno constructor(value: String = ..., x: Int = ...) : Annotation {
val value: String
val x: Int
}
annotation class Bnno constructor() : Annotation
enum class Eee private constructor() : Enum<Eee> {
@Anno enum entry Entry1
enum entry Entry2
@Anno(value = "3") @Bnno enum entry Entry3
@Anno(value = "4", x = 4) enum entry Entry4
}
@@ -0,0 +1,14 @@
package test
annotation class Empty
annotation class JustAnnotation(val annotation: Empty)
annotation class AnnotationArray(val annotationArray: Array<JustAnnotation>)
@JustAnnotation(Empty())
@AnnotationArray(arrayOf())
class C1
@AnnotationArray(arrayOf(JustAnnotation(Empty()), JustAnnotation(Empty())))
class C2
@@ -0,0 +1,9 @@
annotation class AnnotationArray constructor(annotationArray: Array<JustAnnotation>) : Annotation {
val annotationArray: Array<JustAnnotation>
}
@JustAnnotation(annotation = Empty) @AnnotationArray(annotationArray = {}) class C1 constructor()
@AnnotationArray(annotationArray = {JustAnnotation(annotation = Empty), JustAnnotation(annotation = Empty)}) class C2 constructor()
annotation class Empty constructor() : Annotation
annotation class JustAnnotation constructor(annotation: Empty) : Annotation {
val annotation: Empty
}
@@ -0,0 +1,18 @@
package test
enum class Weapon {
ROCK,
PAPER,
SCISSORS
}
annotation class JustEnum(val weapon: Weapon)
annotation class EnumArray(val enumArray: Array<Weapon>)
@JustEnum(Weapon.SCISSORS)
@EnumArray(arrayOf())
class C1
@EnumArray(arrayOf(Weapon.PAPER, Weapon.ROCK))
class C2
@@ -0,0 +1,13 @@
@JustEnum(weapon = Weapon.SCISSORS) @EnumArray(enumArray = {}) class C1 constructor()
@EnumArray(enumArray = {Weapon.PAPER, Weapon.ROCK}) class C2 constructor()
annotation class EnumArray constructor(enumArray: Array<Weapon>) : Annotation {
val enumArray: Array<Weapon>
}
annotation class JustEnum constructor(weapon: Weapon) : Annotation {
val weapon: Weapon
}
enum class Weapon private constructor() : Enum<Weapon> {
enum entry ROCK
enum entry PAPER
enum entry SCISSORS
}
@@ -0,0 +1,38 @@
// KT-56189 -3.14 is not constant
// MUTED_WHEN: K2
package test
annotation class PrimitiveArrays(
val byteArray: ByteArray,
val charArray: CharArray,
val shortArray: ShortArray,
val intArray: IntArray,
val longArray: LongArray,
val floatArray: FloatArray,
val doubleArray: DoubleArray,
val booleanArray: BooleanArray
)
@PrimitiveArrays(
byteArray = byteArrayOf(-7, 7),
charArray = charArrayOf('%', 'z'),
shortArray = shortArrayOf(239),
intArray = intArrayOf(239017, -1),
longArray = longArrayOf(123456789123456789L),
floatArray = floatArrayOf(2.72f, 0f),
doubleArray = doubleArrayOf(-3.14),
booleanArray = booleanArrayOf(true, false, true)
)
class C1
@PrimitiveArrays(
byteArray = byteArrayOf(),
charArray = charArrayOf(),
shortArray = shortArrayOf(),
intArray = intArrayOf(),
longArray = longArrayOf(),
floatArray = floatArrayOf(),
doubleArray = doubleArrayOf(),
booleanArray = booleanArrayOf()
)
class C2
@@ -0,0 +1,12 @@
@PrimitiveArrays(booleanArray = {true, false, true}, byteArray = {-7.toByte(), 7.toByte()}, charArray = {\u0025 ('%'), \u007A ('z')}, doubleArray = {-3.14.toDouble()}, floatArray = {2.72.toFloat(), 0.0.toFloat()}, intArray = {239017, -1}, longArray = {123456789123456789.toLong()}, shortArray = {239.toShort()}) class C1 constructor()
@PrimitiveArrays(booleanArray = {}, byteArray = {}, charArray = {}, doubleArray = {}, floatArray = {}, intArray = {}, longArray = {}, shortArray = {}) class C2 constructor()
annotation class PrimitiveArrays constructor(byteArray: ByteArray, charArray: CharArray, shortArray: ShortArray, intArray: IntArray, longArray: LongArray, floatArray: FloatArray, doubleArray: DoubleArray, booleanArray: BooleanArray) : Annotation {
val booleanArray: BooleanArray
val byteArray: ByteArray
val charArray: CharArray
val doubleArray: DoubleArray
val floatArray: FloatArray
val intArray: IntArray
val longArray: LongArray
val shortArray: ShortArray
}
@@ -0,0 +1,27 @@
// KT-56189 error: an annotation argument must be a compile-time constant
// -3.14 is not constant
// MUTED_WHEN: K2
package test
annotation class Primitives(
val byte: Byte,
val char: Char,
val short: Short,
val int: Int,
val long: Long,
val float: Float,
val double: Double,
val boolean: Boolean
)
@Primitives(
byte = 7,
char = '%',
short = 239,
int = 239017,
long = 123456789123456789L,
float = 2.72f,
double = -3.14,
boolean = true
)
class C
@@ -0,0 +1,11 @@
@Primitives(boolean = true, byte = 7.toByte(), char = \u0025 ('%'), double = -3.14.toDouble(), float = 2.72.toFloat(), int = 239017, long = 123456789123456789.toLong(), short = 239.toShort()) class C constructor()
annotation class Primitives constructor(byte: Byte, char: Char, short: Short, int: Int, long: Long, float: Float, double: Double, boolean: Boolean) : Annotation {
val boolean: Boolean
val byte: Byte
val char: Char
val double: Double
val float: Float
val int: Int
val long: Long
val short: Short
}
@@ -0,0 +1,12 @@
package test
annotation class JustString(val string: String)
annotation class StringArray(val stringArray: Array<String>)
@JustString("kotlin")
@StringArray(arrayOf())
class C1
@StringArray(arrayOf("java", ""))
class C2
@@ -0,0 +1,8 @@
@JustString(string = "kotlin") @StringArray(stringArray = {}) class C1 constructor()
@StringArray(stringArray = {"java", ""}) class C2 constructor()
annotation class JustString constructor(string: String) : Annotation {
val string: String
}
annotation class StringArray constructor(stringArray: Array<String>) : Annotation {
val stringArray: Array<String>
}
@@ -0,0 +1,7 @@
package test
enum class My { ALPHA, BETA, OMEGA }
annotation class ann(vararg val m: My)
@ann(My.ALPHA, My.BETA) annotation class annotated
@@ -0,0 +1,9 @@
enum class My private constructor() : Enum<My> {
enum entry ALPHA
enum entry BETA
enum entry OMEGA
}
annotation class ann constructor(vararg m: My) : Annotation {
val m: Array<out My>
}
@ann(m = {My.ALPHA, My.BETA}) annotation class annotated constructor() : Annotation
@@ -0,0 +1,37 @@
package test
annotation class anno(val x: String)
@anno("top level function")
fun f1(@anno("top level function parameter") p: Int) {}
@anno("top level property")
val p1 = null
@anno("extension function")
fun Long.f2(@anno("extension function parameter") p: Int) {}
@anno("extension property")
val Double.p2: Double get() = 0.0
@anno("top level class")
class C1 @anno("constructor") constructor() {
@anno("member function")
fun f3(@anno("member function parameter") p: Int) {}
@anno("member property")
val p3 = null
@anno("member extension function")
fun String.f4() {}
@anno("member extension property")
val Int.v4: Int get() = this
@anno("nested class")
class C2
@anno("companion object")
companion object {}
}
@@ -0,0 +1,15 @@
@anno(x = "top level class") class C1 @anno(x = "constructor") constructor() {
@anno(x = "member property") val p3: Nothing?
@anno(x = "member extension property") val Int.v4: Int
@anno(x = "member function") fun f3(@anno(x = "member function parameter") p: Int)
@anno(x = "member extension function") fun String.f4()
@anno(x = "nested class") class C2 constructor()
@anno(x = "companion object") companion object
}
annotation class anno constructor(x: String) : Annotation {
val x: String
}
@anno(x = "top level function") fun f1(@anno(x = "top level function parameter") p: Int)
@anno(x = "extension function") fun Long.f2(@anno(x = "extension function parameter") p: Int)
@anno(x = "top level property") val p1: Nothing?
@anno(x = "extension property") val Double.p2: Double
@@ -0,0 +1,21 @@
package test
import kotlin.annotation.AnnotationTarget.*
@Retention(AnnotationRetention.BINARY)
@Target(CLASS, CONSTRUCTOR, FUNCTION, PROPERTY, VALUE_PARAMETER, TYPE, TYPE_PARAMETER)
annotation class A
@A
class Klass @A constructor()
@A
fun <@A T> function(@A param: Unit): @A Unit {}
@A
val property = Unit
enum class Enum {
@A
ENTRY
}
@@ -0,0 +1,7 @@
@Retention(value = AnnotationRetention.BINARY) @Target(allowedTargets = {AnnotationTarget.CLASS, AnnotationTarget.CONSTRUCTOR, AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY, AnnotationTarget.VALUE_PARAMETER, AnnotationTarget.TYPE, AnnotationTarget.TYPE_PARAMETER}) annotation class A constructor() : Annotation
enum class Enum private constructor() : Enum<Enum> {
@A enum entry ENTRY
}
@A class Klass @A constructor()
@A fun <@A T> function(@A param: Unit)
@A val property: Unit
@@ -0,0 +1,41 @@
// KT-56190 K2 does not emit const initializers
// MUTED_WHEN: K2
package test
enum class Weapon {
ROCK,
PAPER,
SCISSORS
}
val byteConst: Byte = 10
val shortConst: Short = 20
val intConst: Int = 30
val longConst: Long = 40
val charConst: Char = 'A'
val stringConst: String = "abcd"
val booleanConst: Boolean = true
val floatConst: Float = 2.0f
val doubleConst: Double = 3.0
val enumConst: Weapon? = Weapon.ROCK
val arrayConst: Any = byteArrayOf(1,2)
val a = 10
val b = a + 20
class Class {
val byteConst: Byte = 10
val shortConst: Short = 20
val intConst: Int = 30
val longConst: Long = 40
val charConst: Char = 'A'
val stringConst: String = "abcd"
val booleanConst: Boolean = true
val floatConst: Float = 2.0f
val doubleConst: Double = 3.0
val enumConst: Weapon? = Weapon.ROCK
val arrayConst: Any = byteArrayOf(1,2)
val a = 10
val b = a + 20
}
@@ -0,0 +1,33 @@
class Class constructor() {
val a: Int = 10
val arrayConst: Any = {1.toByte(), 2.toByte()}
val b: Int = 30
val booleanConst: Boolean = true
val byteConst: Byte = 10.toByte()
val charConst: Char = \u0041 ('A')
val doubleConst: Double = 3.0.toDouble()
val enumConst: Weapon? = Weapon.ROCK
val floatConst: Float = 2.0.toFloat()
val intConst: Int = 30
val longConst: Long = 40.toLong()
val shortConst: Short = 20.toShort()
val stringConst: String = "abcd"
}
enum class Weapon private constructor() : Enum<Weapon> {
enum entry ROCK
enum entry PAPER
enum entry SCISSORS
}
val a: Int = 10
val arrayConst: Any = {1.toByte(), 2.toByte()}
val b: Int = 30
val booleanConst: Boolean = true
val byteConst: Byte = 10.toByte()
val charConst: Char = \u0041 ('A')
val doubleConst: Double = 3.0.toDouble()
val enumConst: Weapon? = Weapon.ROCK
val floatConst: Float = 2.0.toFloat()
val intConst: Int = 30
val longConst: Long = 40.toLong()
val shortConst: Short = 20.toShort()
val stringConst: String = "abcd"
@@ -0,0 +1,33 @@
// KT-56190 K2 does not emit const initializers
// MUTED_WHEN: K2
package test
class ClassA {
class classB {
fun memberFromB(): Int = 100
class BC {
val memberFromBB: Int = 150
}
object BO {
val memberFromBO: Int = 175
}
}
inner class classC {
val memberFromC: Int = 200
}
companion object {
val stat: Int = 250
class D {
val memberFromD: Int = 275
}
}
object ObjA {
val memberFromObjA: Int = 300
}
}
@@ -0,0 +1,23 @@
class ClassA constructor() {
companion object {
val stat: Int = 250
class D constructor() {
val memberFromD: Int = 275
}
}
object ObjA {
val memberFromObjA: Int = 300
}
class classB constructor() {
fun memberFromB(): Int
class BC constructor() {
val memberFromBB: Int = 150
}
object BO {
val memberFromBO: Int = 175
}
}
inner class classC constructor() {
val memberFromC: Int = 200
}
}
@@ -0,0 +1,12 @@
// KT-56190 K2 does not emit const initializers
// MUTED_WHEN: K2
package test
annotation class Anno(val value: String)
@Anno("property") val v1 = ""
var v2: String
@Anno("getter") get() = ""
@Anno("setter") set(@Anno("setparam") value) {
}
@@ -0,0 +1,7 @@
annotation class Anno constructor(value: String) : Annotation {
val value: String
}
@Anno(value = "property") val v1: String = ""
var v2: String
@Anno(value = "getter") get
@Anno(value = "setter") set
@@ -0,0 +1,11 @@
package test
class Class {
fun member() = null
}
fun function(int: Int, string: String = "default"): Class = Class()
fun <T> T.extension(): T? = null
val property: Unit = Unit
@@ -0,0 +1,6 @@
class Class constructor() {
fun member(): Nothing?
}
fun <T> T.extension(): T?
fun function(int: Int, string: String = ...): Class
val property: Unit
@@ -0,0 +1,21 @@
package test
import kotlin.annotation.AnnotationTarget.*
@Retention(AnnotationRetention.SOURCE)
@Target(CLASS, CONSTRUCTOR, FUNCTION, PROPERTY, VALUE_PARAMETER, TYPE, TYPE_PARAMETER)
annotation class A
@A
class Klass @A constructor()
@A
fun <@A T> function(@A param: Unit): @A Unit {}
@A
val property = Unit
enum class Enum {
@A
ENTRY
}
@@ -0,0 +1,7 @@
@Retention(value = AnnotationRetention.SOURCE) @Target(allowedTargets = {AnnotationTarget.CLASS, AnnotationTarget.CONSTRUCTOR, AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY, AnnotationTarget.VALUE_PARAMETER, AnnotationTarget.TYPE, AnnotationTarget.TYPE_PARAMETER}) annotation class A constructor() : Annotation
enum class Enum private constructor() : Enum<Enum> {
enum entry ENTRY
}
class Klass constructor()
fun <T> function(param: Unit)
val property: Unit
@@ -0,0 +1,6 @@
package test
@Retention(AnnotationRetention.BINARY)
@Target(AnnotationTarget.TYPE_PARAMETER)
annotation class Ann(val value: String)
inline fun <reified @Ann("abc") T> foo() {}
@@ -0,0 +1,4 @@
@Retention(value = AnnotationRetention.BINARY) @Target(allowedTargets = {AnnotationTarget.TYPE_PARAMETER}) annotation class Ann constructor(value: String) : Annotation {
val value: String
}
inline fun <reified @Ann(value = "abc") T> foo()
@@ -0,0 +1,15 @@
package test
annotation class Ann
@field:Ann
var x: Int = 5
@delegate:Ann
var y: Int by ::x
class A {
@field:Ann
var x: Int = 5
@delegate:Ann
var y: Int by ::x
}
@@ -0,0 +1,7 @@
class A constructor() {
@field:Ann var x: Int
@delegate:Ann var y: Int
}
annotation class Ann constructor() : Annotation
@field:Ann var x: Int
@delegate:Ann var y: Int
@@ -0,0 +1,14 @@
// KT-56218: Fix receiver annotations for properties
// MUTED_WHEN: K2
package test
annotation class Ann
@Ann fun @receiver:Ann Int.foo(@Ann arg: Int) = 10
@Ann val @receiver:Ann Int.bar
get() = 5
class A {
@Ann fun @receiver:Ann Int.foo(@Ann arg: Int) = 10
@Ann val @receiver:Ann Int.bar
get() = 5
}
@@ -0,0 +1,7 @@
class A constructor() {
@Ann val @receiver:Ann Int.bar: Int
@Ann fun @receiver:Ann Int.foo(@Ann arg: Int): Int
}
annotation class Ann constructor() : Annotation
@Ann val @receiver:Ann Int.bar: Int
@Ann fun @receiver:Ann Int.foo(@Ann arg: Int): Int
@@ -21,7 +21,7 @@ import java.util.regex.Pattern;
public class NativeK1LibContentsTestGenerated extends AbstractNativeKlibContentsTest {
@Test
public void testAllFilesPresentInKlibContents() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("native/native.tests/testData/klibContents"), Pattern.compile("^([^_](.+)).kt$"), null, false);
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("native/native.tests/testData/klibContents"), Pattern.compile("^([^_](.+)).kt$"), null, true);
}
@Test
@@ -53,4 +53,136 @@ public class NativeK1LibContentsTestGenerated extends AbstractNativeKlibContents
public void testType_annotations() throws Exception {
runTest("native/native.tests/testData/klibContents/type_annotations.kt");
}
@Nested
@TestMetadata("native/native.tests/testData/klibContents/builtinsSerializer")
@TestDataPath("$PROJECT_ROOT")
public class BuiltinsSerializer {
@Test
public void testAllFilesPresentInBuiltinsSerializer() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("native/native.tests/testData/klibContents/builtinsSerializer"), Pattern.compile("^([^_](.+)).kt$"), null, true);
}
@Test
@TestMetadata("annotatedEnumEntry.kt")
public void testAnnotatedEnumEntry() throws Exception {
runTest("native/native.tests/testData/klibContents/builtinsSerializer/annotatedEnumEntry.kt");
}
@Test
@TestMetadata("annotationTargets.kt")
public void testAnnotationTargets() throws Exception {
runTest("native/native.tests/testData/klibContents/builtinsSerializer/annotationTargets.kt");
}
@Test
@TestMetadata("binaryRetainedAnnotation.kt")
public void testBinaryRetainedAnnotation() throws Exception {
runTest("native/native.tests/testData/klibContents/builtinsSerializer/binaryRetainedAnnotation.kt");
}
@Test
@TestMetadata("compileTimeConstants.kt")
public void testCompileTimeConstants() throws Exception {
runTest("native/native.tests/testData/klibContents/builtinsSerializer/compileTimeConstants.kt");
}
@Test
@TestMetadata("nestedClassesAndObjects.kt")
public void testNestedClassesAndObjects() throws Exception {
runTest("native/native.tests/testData/klibContents/builtinsSerializer/nestedClassesAndObjects.kt");
}
@Test
@TestMetadata("propertyAccessorAnnotations.kt")
public void testPropertyAccessorAnnotations() throws Exception {
runTest("native/native.tests/testData/klibContents/builtinsSerializer/propertyAccessorAnnotations.kt");
}
@Test
@TestMetadata("simple.kt")
public void testSimple() throws Exception {
runTest("native/native.tests/testData/klibContents/builtinsSerializer/simple.kt");
}
@Test
@TestMetadata("sourceRetainedAnnotation.kt")
public void testSourceRetainedAnnotation() throws Exception {
runTest("native/native.tests/testData/klibContents/builtinsSerializer/sourceRetainedAnnotation.kt");
}
@Test
@TestMetadata("typeParameterAnnotation.kt")
public void testTypeParameterAnnotation() throws Exception {
runTest("native/native.tests/testData/klibContents/builtinsSerializer/typeParameterAnnotation.kt");
}
@Nested
@TestMetadata("native/native.tests/testData/klibContents/builtinsSerializer/annotationArguments")
@TestDataPath("$PROJECT_ROOT")
public class AnnotationArguments {
@Test
public void testAllFilesPresentInAnnotationArguments() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("native/native.tests/testData/klibContents/builtinsSerializer/annotationArguments"), Pattern.compile("^([^_](.+)).kt$"), null, true);
}
@Test
@TestMetadata("annotation.kt")
public void testAnnotation() throws Exception {
runTest("native/native.tests/testData/klibContents/builtinsSerializer/annotationArguments/annotation.kt");
}
@Test
@TestMetadata("enum.kt")
public void testEnum() throws Exception {
runTest("native/native.tests/testData/klibContents/builtinsSerializer/annotationArguments/enum.kt");
}
@Test
@TestMetadata("primitiveArrays.kt")
public void testPrimitiveArrays() throws Exception {
runTest("native/native.tests/testData/klibContents/builtinsSerializer/annotationArguments/primitiveArrays.kt");
}
@Test
@TestMetadata("primitives.kt")
public void testPrimitives() throws Exception {
runTest("native/native.tests/testData/klibContents/builtinsSerializer/annotationArguments/primitives.kt");
}
@Test
@TestMetadata("string.kt")
public void testString() throws Exception {
runTest("native/native.tests/testData/klibContents/builtinsSerializer/annotationArguments/string.kt");
}
@Test
@TestMetadata("varargs.kt")
public void testVarargs() throws Exception {
runTest("native/native.tests/testData/klibContents/builtinsSerializer/annotationArguments/varargs.kt");
}
}
}
@Nested
@TestMetadata("native/native.tests/testData/klibContents/klib")
@TestDataPath("$PROJECT_ROOT")
public class Klib {
@Test
public void testAllFilesPresentInKlib() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("native/native.tests/testData/klibContents/klib"), Pattern.compile("^([^_](.+)).kt$"), null, true);
}
@Test
@TestMetadata("fieldAnnotations.kt")
public void testFieldAnnotations() throws Exception {
runTest("native/native.tests/testData/klibContents/klib/fieldAnnotations.kt");
}
@Test
@TestMetadata("receiverAnnotations.kt")
public void testReceiverAnnotations() throws Exception {
runTest("native/native.tests/testData/klibContents/klib/receiverAnnotations.kt");
}
}
}
@@ -23,7 +23,7 @@ import java.util.regex.Pattern;
public class NativeK2LibContentsTestGenerated extends AbstractNativeKlibContentsTest {
@Test
public void testAllFilesPresentInKlibContents() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("native/native.tests/testData/klibContents"), Pattern.compile("^([^_](.+)).kt$"), null, false);
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("native/native.tests/testData/klibContents"), Pattern.compile("^([^_](.+)).kt$"), null, true);
}
@Test
@@ -55,4 +55,139 @@ public class NativeK2LibContentsTestGenerated extends AbstractNativeKlibContents
public void testType_annotations() throws Exception {
runTest("native/native.tests/testData/klibContents/type_annotations.kt");
}
@Nested
@TestMetadata("native/native.tests/testData/klibContents/builtinsSerializer")
@TestDataPath("$PROJECT_ROOT")
@K2Pipeline()
public class BuiltinsSerializer {
@Test
public void testAllFilesPresentInBuiltinsSerializer() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("native/native.tests/testData/klibContents/builtinsSerializer"), Pattern.compile("^([^_](.+)).kt$"), null, true);
}
@Test
@TestMetadata("annotatedEnumEntry.kt")
public void testAnnotatedEnumEntry() throws Exception {
runTest("native/native.tests/testData/klibContents/builtinsSerializer/annotatedEnumEntry.kt");
}
@Test
@TestMetadata("annotationTargets.kt")
public void testAnnotationTargets() throws Exception {
runTest("native/native.tests/testData/klibContents/builtinsSerializer/annotationTargets.kt");
}
@Test
@TestMetadata("binaryRetainedAnnotation.kt")
public void testBinaryRetainedAnnotation() throws Exception {
runTest("native/native.tests/testData/klibContents/builtinsSerializer/binaryRetainedAnnotation.kt");
}
@Test
@TestMetadata("compileTimeConstants.kt")
public void testCompileTimeConstants() throws Exception {
runTest("native/native.tests/testData/klibContents/builtinsSerializer/compileTimeConstants.kt");
}
@Test
@TestMetadata("nestedClassesAndObjects.kt")
public void testNestedClassesAndObjects() throws Exception {
runTest("native/native.tests/testData/klibContents/builtinsSerializer/nestedClassesAndObjects.kt");
}
@Test
@TestMetadata("propertyAccessorAnnotations.kt")
public void testPropertyAccessorAnnotations() throws Exception {
runTest("native/native.tests/testData/klibContents/builtinsSerializer/propertyAccessorAnnotations.kt");
}
@Test
@TestMetadata("simple.kt")
public void testSimple() throws Exception {
runTest("native/native.tests/testData/klibContents/builtinsSerializer/simple.kt");
}
@Test
@TestMetadata("sourceRetainedAnnotation.kt")
public void testSourceRetainedAnnotation() throws Exception {
runTest("native/native.tests/testData/klibContents/builtinsSerializer/sourceRetainedAnnotation.kt");
}
@Test
@TestMetadata("typeParameterAnnotation.kt")
public void testTypeParameterAnnotation() throws Exception {
runTest("native/native.tests/testData/klibContents/builtinsSerializer/typeParameterAnnotation.kt");
}
@Nested
@TestMetadata("native/native.tests/testData/klibContents/builtinsSerializer/annotationArguments")
@TestDataPath("$PROJECT_ROOT")
@K2Pipeline()
public class AnnotationArguments {
@Test
public void testAllFilesPresentInAnnotationArguments() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("native/native.tests/testData/klibContents/builtinsSerializer/annotationArguments"), Pattern.compile("^([^_](.+)).kt$"), null, true);
}
@Test
@TestMetadata("annotation.kt")
public void testAnnotation() throws Exception {
runTest("native/native.tests/testData/klibContents/builtinsSerializer/annotationArguments/annotation.kt");
}
@Test
@TestMetadata("enum.kt")
public void testEnum() throws Exception {
runTest("native/native.tests/testData/klibContents/builtinsSerializer/annotationArguments/enum.kt");
}
@Test
@TestMetadata("primitiveArrays.kt")
public void testPrimitiveArrays() throws Exception {
runTest("native/native.tests/testData/klibContents/builtinsSerializer/annotationArguments/primitiveArrays.kt");
}
@Test
@TestMetadata("primitives.kt")
public void testPrimitives() throws Exception {
runTest("native/native.tests/testData/klibContents/builtinsSerializer/annotationArguments/primitives.kt");
}
@Test
@TestMetadata("string.kt")
public void testString() throws Exception {
runTest("native/native.tests/testData/klibContents/builtinsSerializer/annotationArguments/string.kt");
}
@Test
@TestMetadata("varargs.kt")
public void testVarargs() throws Exception {
runTest("native/native.tests/testData/klibContents/builtinsSerializer/annotationArguments/varargs.kt");
}
}
}
@Nested
@TestMetadata("native/native.tests/testData/klibContents/klib")
@TestDataPath("$PROJECT_ROOT")
@K2Pipeline()
public class Klib {
@Test
public void testAllFilesPresentInKlib() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("native/native.tests/testData/klibContents/klib"), Pattern.compile("^([^_](.+)).kt$"), null, true);
}
@Test
@TestMetadata("fieldAnnotations.kt")
public void testFieldAnnotations() throws Exception {
runTest("native/native.tests/testData/klibContents/klib/fieldAnnotations.kt");
}
@Test
@TestMetadata("receiverAnnotations.kt")
public void testReceiverAnnotations() throws Exception {
runTest("native/native.tests/testData/klibContents/klib/receiverAnnotations.kt");
}
}
}
@@ -105,7 +105,7 @@ fun main() {
testClass<AbstractNativeKlibContentsTest>(
suiteTestClassName = "NativeK1LibContentsTestGenerated"
) {
model("klibContents", pattern = "^([^_](.+)).kt$", recursive = false)
model("klibContents", pattern = "^([^_](.+)).kt$", recursive = true)
}
}
testGroup("native/native.tests/tests-gen", "native/native.tests/testData") {
@@ -113,7 +113,7 @@ fun main() {
suiteTestClassName = "NativeK2LibContentsTestGenerated",
annotations = listOf(provider<K2Pipeline>())
) {
model("klibContents", pattern = "^([^_](.+)).kt$", recursive = false)
model("klibContents", pattern = "^([^_](.+)).kt$", recursive = true)
}
}
@@ -15,6 +15,7 @@ import org.jetbrains.kotlin.konan.blackboxtest.support.runner.*
import org.jetbrains.kotlin.konan.blackboxtest.support.settings.*
import org.jetbrains.kotlin.konan.blackboxtest.support.util.*
import org.jetbrains.kotlin.test.services.JUnit5Assertions.assertEquals
import org.junit.jupiter.api.Assumptions
import org.junit.jupiter.api.Tag
import java.io.File
@@ -23,6 +24,7 @@ abstract class AbstractNativeKlibContentsTest : AbstractNativeSimpleTest() {
protected fun runTest(@TestDataFile testPath: String) {
val testPathFull = getAbsoluteFile(testPath)
muteTestIfNecessary(testPathFull)
val testCase: TestCase = generateTestCaseWithSingleSource(testPathFull, listOf())
val testCompilationResult: TestCompilationResult.Success<out KLIB> = compileToLibrary(testCase)
@@ -5,10 +5,12 @@
package org.jetbrains.kotlin.konan.blackboxtest
import com.intellij.openapi.util.io.FileUtil
import org.jetbrains.kotlin.konan.blackboxtest.support.PackageName
import org.jetbrains.kotlin.konan.blackboxtest.support.TestCase
import org.jetbrains.kotlin.konan.blackboxtest.support.TestCaseId
import org.jetbrains.kotlin.konan.blackboxtest.support.TestCompilerArgs
import org.jetbrains.kotlin.konan.blackboxtest.support.TestDirectives
import org.jetbrains.kotlin.konan.blackboxtest.support.TestFile
import org.jetbrains.kotlin.konan.blackboxtest.support.TestKind
import org.jetbrains.kotlin.konan.blackboxtest.support.TestModule
@@ -23,9 +25,12 @@ import org.jetbrains.kotlin.konan.blackboxtest.support.compilation.TestCompilati
import org.jetbrains.kotlin.konan.blackboxtest.support.compilation.TestCompilationResult.Companion.assertSuccess
import org.jetbrains.kotlin.konan.blackboxtest.support.runner.TestRunChecks
import org.jetbrains.kotlin.konan.blackboxtest.support.settings.KotlinNativeTargets
import org.jetbrains.kotlin.konan.blackboxtest.support.settings.PipelineType
import org.jetbrains.kotlin.konan.blackboxtest.support.settings.SimpleTestDirectories
import org.jetbrains.kotlin.konan.blackboxtest.support.settings.Timeouts
import org.jetbrains.kotlin.konan.blackboxtest.support.util.LAUNCHER_MODULE_NAME
import org.jetbrains.kotlin.test.InTextDirectivesUtils
import org.junit.jupiter.api.Assumptions
import java.io.File
private val DEFAULT_EXTRAS = TestCase.WithTestRunnerExtras(TestRunnerType.DEFAULT)
@@ -125,3 +130,17 @@ private fun getLibraryArtifact(testCase: TestCase, dir: File) =
private fun AbstractNativeSimpleTest.getExecutableArtifact() =
TestCompilationArtifact.Executable(buildDir.resolve("app." + testRunSettings.get<KotlinNativeTargets>().testTarget.family.exeSuffix))
private fun directiveValues(testDataFileContents: String, directive: String) =
InTextDirectivesUtils.findListWithPrefixes(testDataFileContents, "// $directive: ")
internal fun AbstractNativeSimpleTest.muteTestIfNecessary(testDataFile: File) = muteTestIfNecessary(FileUtil.loadFile(testDataFile))
internal fun AbstractNativeSimpleTest.muteTestIfNecessary(testDataFileContents: String) {
val pipelineType = testRunSettings.get<PipelineType>()
val mutedWhenValues = directiveValues(testDataFileContents, TestDirectives.MUTED_WHEN.name)
Assumptions.assumeFalse(mutedWhenValues.any { it == pipelineType.mutedOption.name })
}
internal fun AbstractNativeSimpleTest.freeCompilerArgs(testDataFile: File) = freeCompilerArgs(FileUtil.loadFile(testDataFile))
internal fun AbstractNativeSimpleTest.freeCompilerArgs(testDataFileContents: String) =
directiveValues(testDataFileContents, TestDirectives.FREE_COMPILER_ARGS.name)
@@ -133,6 +133,13 @@ internal object TestDirectives : SimpleDirectivesContainer() {
Specify a filename containing the LLDB commands and the patterns that
the output should match""".trimIndent(),
)
// TODO "MUTED_WHEN" directive should be supported not only in AbstractNativeSimpleTest, but also in other hierarchies
val MUTED_WHEN by enumDirective<MutedOption>(
description = """
Usage: // MUTED_WHEN: [K1, K2]
In native simple tests, specify the pipeline types to mute the test""".trimIndent(),
)
}
internal enum class TestKind {
@@ -148,6 +155,11 @@ internal enum class TestRunnerType {
NO_EXIT
}
internal enum class MutedOption {
K1,
K2
}
internal class TestCompilerArgs(val compilerArgs: List<String>) {
private val uniqueCompilerArgs = compilerArgs.toSet()
override fun hashCode() = uniqueCompilerArgs.hashCode()
@@ -5,6 +5,7 @@
package org.jetbrains.kotlin.konan.blackboxtest.support.settings
import org.jetbrains.kotlin.konan.blackboxtest.support.MutedOption
import org.jetbrains.kotlin.konan.blackboxtest.support.TestKind
import org.jetbrains.kotlin.konan.blackboxtest.support.runner.LocalTestRunner
import org.jetbrains.kotlin.konan.blackboxtest.support.runner.NoopTestRunner
@@ -239,9 +240,9 @@ internal sealed interface CacheMode {
}
}
internal enum class PipelineType(val compilerFlags: List<String>) {
K1(emptyList()),
K2(listOf("-language-version", "2.0"));
internal enum class PipelineType(val mutedOption: MutedOption, val compilerFlags: List<String>) {
K1(MutedOption.K1, emptyList()),
K2(MutedOption.K2, listOf("-language-version", "2.0"));
override fun toString() = if (compilerFlags.isEmpty()) "" else compilerFlags.joinToString(prefix = "(", postfix = ")", separator = " ")
}