diff --git a/kotlin-native/klib/build.gradle b/kotlin-native/klib/build.gradle index ef8efd1ffdb..b6d13b56c16 100644 --- a/kotlin-native/klib/build.gradle +++ b/kotlin-native/klib/build.gradle @@ -2,33 +2,12 @@ * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license * that can be found in the LICENSE file. */ -import org.jetbrains.kotlin.UtilsKt buildscript { apply from: "$rootDir/kotlin-native/gradle/kotlinGradlePlugin.gradle" } apply plugin: 'kotlin' -apply plugin: 'konan' - -ext.useCustomDist = UtilsKt.getUseCustomDist(project) - -konanArtifacts { - def testFiles = fileTree('src/test/testData') { - include "*.kt" - } - testFiles.files.each { file -> - def name = file.name - library(name.take(name.lastIndexOf('.'))) { - srcFiles file.absolutePath - - // Build the compiler before building the test unless a custom path to the distribution is specified. - if (!useCustomDist) { - dependsOn ':dist' - } - } - } -} compileKotlin { kotlinOptions.freeCompilerArgs += ['-Xskip-prerelease-check'] @@ -51,13 +30,4 @@ dependencies { test { dependsOn 'cleanTest' // Specify a path to the distribution that is used in the tests. - systemProperty('konan.home', UtilsKt.getKotlinNativeDist(project)) - dependsOn konanArtifacts.collect { it.getByTarget('host') } - if (useCustomDist) { - // Use the klib utility from the distribution - def distClasspath = fileTree("${UtilsKt.getKotlinNativeDist(project)}/konan/lib") { - include "**/*.jar" - } - classpath = distClasspath + sourceSets.test.runtimeClasspath - sourceSets.main.runtimeClasspath - } } diff --git a/kotlin-native/klib/src/test/kotlin/org/jetbrains/kotlin/cli/klib/test/DumpMetadataTest.kt b/kotlin-native/klib/src/test/kotlin/org/jetbrains/kotlin/cli/klib/test/DumpMetadataTest.kt deleted file mode 100644 index 49bfca074ad..00000000000 --- a/kotlin-native/klib/src/test/kotlin/org/jetbrains/kotlin/cli/klib/test/DumpMetadataTest.kt +++ /dev/null @@ -1,348 +0,0 @@ -/* - * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license - * that can be found in the LICENSE file. - */ - -package org.jetbrains.kotlin.cli.klib.test - -import com.intellij.openapi.util.text.StringUtil -import kotlin.test.* -import org.jetbrains.kotlin.cli.klib.* -import org.jetbrains.kotlin.konan.target.Distribution -import org.jetbrains.kotlin.konan.target.HostManager -import java.nio.file.Paths - -class DumpMetadataTest { - - private fun testLibrary(name: String) = LIBRARY_DIRECTORY.resolve("$name.klib").toFile().absolutePath - - private fun dumpMetadata(library: String, printOutput: Boolean = false, expected: () -> String) { - val output = StringBuilder() - val lib = Library(library, null) - lib.dumpMetadata(output, false, null) - if (printOutput) { - println(output.trim().toString()) - } - assertEquals( - StringUtil.convertLineSeparators(expected()), - StringUtil.convertLineSeparators(output.trim().toString()), - "klib \"dump-metadata\" test failed for library: $library" - ) - } - - @Test - fun `Stdlib content should be printed without exceptions`() { - val output = StringBuilder() - val distributionPath = System.getProperty("konan.home") - Library(Distribution(distributionPath).stdlib, null).dumpMetadata(output, false, null) - } - - @Test - fun topLevelFunctions() = dumpMetadata(testLibrary("TopLevelFunctions")) { - """ - package { - annotation class A constructor() : Annotation - annotation class B constructor() : Annotation - class Foo constructor() - @A @B fun a() - fun Foo.e() - fun f1(x: Foo) - fun f2(x: Foo, y: Foo): Int - inline fun i1(block: () -> Foo) - inline fun i2(noinline block: () -> Foo) - inline fun i3(crossinline block: () -> Foo) - fun i4(block: (Foo) -> Int) - fun i5(block: (Foo, Foo) -> Int) - fun i6(block: Foo.() -> Int) - fun i7(block: Foo.(Foo) -> Int) - fun t1(x: Foo) - fun t2(x: T) - fun t3(x: T, y: F) - inline fun t4(x: T) - fun t5(x: T) - } - """.trimIndent() - } - - @Test - fun constructors() = dumpMetadata(testLibrary("Constructors")) { - """ - package { - annotation class A constructor() : Annotation - class Bar @A constructor(x: Int) - class Baz private constructor(x: Int) - - class Foo constructor(x: Int) { - constructor() - constructor(x: Double) - constructor(x: Double, y: Int) - protected constructor(x: String) - @A constructor(x: Foo) - } - - class Qux protected constructor(x: Int) - - class Typed constructor(x: Int) { - constructor() - constructor(x: Double) - constructor(x: Double, y: Int) - protected constructor(x: String) - @A constructor(x: Foo) - } - - } - """.trimIndent() - } - - @Test - fun objects() = dumpMetadata(testLibrary("Objects")) { - """ - package { - - object A { - fun a() - } - - class B constructor() { - - companion object { - fun b() - } - - object C { - fun c() - } - - } - - class D constructor() { - - companion object E { - fun e() - } - - } - - } - """.trimIndent() - } - - @Test - fun classes() = dumpMetadata(testLibrary("Classes")) { - """ - package { - - class A constructor() { - val aVal: Int = 0 - var aVar: String - fun aFun() - - inner class B constructor() { - val bVal: Int = 0 - var bVar: String - fun bFun() - - inner class C constructor() { - val cVal: Int = 0 - var cVar: String - fun cFun() - } - - } - - class E constructor() { - val eVal: Int = 0 - var eVar: String - fun eFun() - } - - } - - data class F constructor(fVal: Int, fVar: String) { - val fVal: Int - var fVar: String - operator fun component1(): Int - operator fun component2(): String - fun copy(fVal: Int = ..., fVar: String = ...): F - override fun equals(other: Any?): Boolean - fun fFun() - override fun hashCode(): Int - override fun toString(): String - } - - class FinalImpl constructor() : OpenImpl { - override val iVal: Int = 0 - override var iVar: String - override fun iFun() - } - - interface Interface { - val iVal: Int - var iVar: String - fun iFun() - } - - open class OpenImpl constructor() : Interface { - override val iVal: Int = 0 - override var iVar: String - override fun iFun() - } - - } - """.trimIndent() - } - - @Test - fun methodModality() = dumpMetadata(testLibrary("MethodModality")) { - """ - package { - - abstract class AbstractClass constructor() : Interface { - abstract fun abstractFun() - override fun interfaceFun() - } - - class FinalClass constructor() : OpenClass { - override fun openFun1() - final override fun openFun2() - } - - interface Interface { - fun interfaceFun() - } - - open class OpenClass constructor() : AbstractClass { - override fun abstractFun() - fun finalFun() - open fun openFun1() - open fun openFun2() - } - - } - """.trimIndent() - } - - @Test - fun functionModifiers() = dumpMetadata(testLibrary("FunctionModifiers")) { - """ - package { - - class Foo constructor() { - fun f1() - infix fun f2(x: Int) - suspend fun f3() - tailrec fun f4() - fun f5(vararg x: Int) - operator fun plus(x: Int) - } - - } - """.trimIndent() - } - - @Test - // TODO: Support enum entry methods in serialization/deserialization. - fun enum() = dumpMetadata(testLibrary("Enum")) { - """ - package { - - enum class E private constructor(x: Int = ...) : Enum { - enum entry A - enum entry B - enum entry C - val enumVal: Int = 0 - var enumVar: String - val x: Int - open fun enumFun(): Int - } - - } - """.trimIndent() - } - - @Test - // TODO: Support getter/setter annotations in serialization/deserialization. - fun accessors() = dumpMetadata(testLibrary("Accessors")) { - """ - package custom.pkg { - annotation class A constructor() : Annotation - - class Foo constructor() { - @A val annotated: Int = 0 - var annotatedAccessors: Int - @A get - @A set - val annotatedGetter: Int = 0 - @A get - var annotatedSetter: Int - @A set - var privateSetter: Int - private set - protected val protectedSimple: Int = 0 - val simple: Int = 0 - } - - } - """.trimIndent() - } - - @Test - fun topLevelPropertiesCustomPackage() = dumpMetadata(testLibrary("TopLevelPropertiesCustomPackage")) { - """ - package custom.pkg { - typealias MyTransformer = (String) -> Int - val v1: Int = 1 - val v2: String = "hello" - val v3: (String) -> Int - val v4: MyTransformer /* = (String) -> Int */ - } - """.trimIndent() - } - - @Test - fun topLevelPropertiesRootPackage() = dumpMetadata(testLibrary("TopLevelPropertiesRootPackage")) { - """ - package { - typealias MyTransformer = (String) -> Int - val v1: Int = 1 - val v2: String = "hello" - val v3: (String) -> Int - val v4: MyTransformer /* = (String) -> Int */ - } - """.trimIndent() - } - - @Test - fun topLevelPropertiesWithClassesCustomPackage() = dumpMetadata(testLibrary("TopLevelPropertiesWithClassesCustomPackage")) { - """ - package custom.pkg { - object Bar - class Foo constructor() - typealias MyTransformer = (String) -> Int - val v1: Int = 1 - val v2: String = "hello" - val v3: (String) -> Int - val v4: MyTransformer /* = (String) -> Int */ - } - """.trimIndent() - } - - @Test - fun topLevelPropertiesWithClassesRootPackage() = dumpMetadata(testLibrary("TopLevelPropertiesWithClassesRootPackage")) { - """ - package { - object Bar - class Foo constructor() - typealias MyTransformer = (String) -> Int - val v1: Int = 1 - val v2: String = "hello" - val v3: (String) -> Int - val v4: MyTransformer /* = (String) -> Int */ - } - """.trimIndent() - } - - companion object { - val LIBRARY_DIRECTORY = Paths.get("build/konan/libs").resolve(HostManager.hostName) - } -} \ No newline at end of file diff --git a/kotlin-native/klib/src/test/testData/Accessors.kt b/kotlin-native/klib/src/test/testData/Accessors.kt deleted file mode 100644 index bcbbd1c33e2..00000000000 --- a/kotlin-native/klib/src/test/testData/Accessors.kt +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2010-2018 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package custom.pkg - -annotation class A - -class Foo { - val simple = 0 - - private val privateSimple = 0 - - protected val protectedSimple = 0 - - var privateSetter = 0 - private set - - @A val annotated = 0 - - val annotatedGetter = 0 - @A get - - var annotatedSetter = 0 - @A set - - var annotatedAccessors = 0 - @A set - @A get -} diff --git a/kotlin-native/klib/src/test/testData/Enum.kt b/kotlin-native/klib/src/test/testData/Enum.kt deleted file mode 100644 index 76b9fbfe7e0..00000000000 --- a/kotlin-native/klib/src/test/testData/Enum.kt +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2010-2018 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -enum class E(val x: Int = 0) { - A, - B, - C(1) { - override fun enumFun() = 42 - }; - - open fun enumFun(): Int = 0 - val enumVal = 0 - var enumVar = "" -} \ No newline at end of file diff --git a/kotlin-native/klib/src/test/testData/FunctionModifiers.kt b/kotlin-native/klib/src/test/testData/FunctionModifiers.kt deleted file mode 100644 index d6df51571e8..00000000000 --- a/kotlin-native/klib/src/test/testData/FunctionModifiers.kt +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright 2010-2018 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -class Foo { - fun f1() {} - infix fun f2(x: Int) {} - suspend fun f3() {} - operator fun plus(x: Int) {} - tailrec fun f4() {} - fun f5(vararg x: Int) {} -} \ No newline at end of file diff --git a/kotlin-native/klib/src/test/testData/MethodModality.kt b/kotlin-native/klib/src/test/testData/MethodModality.kt deleted file mode 100644 index 72fba5f867d..00000000000 --- a/kotlin-native/klib/src/test/testData/MethodModality.kt +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2010-2018 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -interface Interface { - fun interfaceFun() -} - -abstract class AbstractClass: Interface { - override fun interfaceFun() {} - abstract fun abstractFun() -} - -open class OpenClass: AbstractClass() { - override fun abstractFun() {} - open fun openFun1() {} - open fun openFun2() {} - fun finalFun() {} -} - -class FinalClass: OpenClass() { - override fun openFun1() {} - final override fun openFun2() {} -} \ No newline at end of file diff --git a/kotlin-native/klib/src/test/testData/Objects.kt b/kotlin-native/klib/src/test/testData/Objects.kt deleted file mode 100644 index cebde7f171b..00000000000 --- a/kotlin-native/klib/src/test/testData/Objects.kt +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2010-2018 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -object A { - fun a() {} -} - -class B { - companion object { - fun b() {} - } - - object C { - fun c() {} - } -} - -class D { - companion object E { - fun e() {} - } -} diff --git a/kotlin-native/klib/src/test/testData/TopLevelPropertiesCustomPackage.kt b/kotlin-native/klib/src/test/testData/TopLevelPropertiesCustomPackage.kt deleted file mode 100644 index a31ce844488..00000000000 --- a/kotlin-native/klib/src/test/testData/TopLevelPropertiesCustomPackage.kt +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2010-2018 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -@file:Suppress("UNUSED_PARAMETER") - -package custom.pkg - -typealias MyTransformer = (String) -> Int - -// top-level properties -val v1 = 1 -val v2 = "hello" -val v3: (String) -> Int = { it.length } -val v4: MyTransformer = v3 - diff --git a/kotlin-native/klib/src/test/testData/TopLevelPropertiesRootPackage.kt b/kotlin-native/klib/src/test/testData/TopLevelPropertiesRootPackage.kt deleted file mode 100644 index 1937b6b6aa1..00000000000 --- a/kotlin-native/klib/src/test/testData/TopLevelPropertiesRootPackage.kt +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2010-2018 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -@file:Suppress("UNUSED_PARAMETER") - -typealias MyTransformer = (String) -> Int - -// top-level properties -val v1 = 1 -val v2 = "hello" -val v3: (String) -> Int = { it.length } -val v4: MyTransformer = v3 - diff --git a/kotlin-native/klib/src/test/testData/TopLevelPropertiesWithClassesCustomPackage.kt b/kotlin-native/klib/src/test/testData/TopLevelPropertiesWithClassesCustomPackage.kt deleted file mode 100644 index 49b1fc1c07c..00000000000 --- a/kotlin-native/klib/src/test/testData/TopLevelPropertiesWithClassesCustomPackage.kt +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2010-2018 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -@file:Suppress("UNUSED_PARAMETER") - -package custom.pkg - -class Foo - -typealias MyTransformer = (String) -> Int - -// top-level properties -val v1 = 1 -val v2 = "hello" -val v3: (String) -> Int = { it.length } -val v4: MyTransformer = v3 - -object Bar diff --git a/kotlin-native/klib/src/test/testData/TopLevelPropertiesWithClassesRootPackage.kt b/kotlin-native/klib/src/test/testData/TopLevelPropertiesWithClassesRootPackage.kt deleted file mode 100644 index 87e367adadb..00000000000 --- a/kotlin-native/klib/src/test/testData/TopLevelPropertiesWithClassesRootPackage.kt +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2010-2018 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -@file:Suppress("UNUSED_PARAMETER") - -class Foo - -typealias MyTransformer = (String) -> Int - -// top-level properties -val v1 = 1 -val v2 = "hello" -val v3: (String) -> Int = { it.length } -val v4: MyTransformer = v3 - -object Bar diff --git a/native/native.tests/testData/klib/dump-metadata/Accessors.kt b/native/native.tests/testData/klib/dump-metadata/Accessors.kt new file mode 100644 index 00000000000..705e1058ab6 --- /dev/null +++ b/native/native.tests/testData/klib/dump-metadata/Accessors.kt @@ -0,0 +1,26 @@ +package custom.pkg + +annotation class A + +class Foo { + val simple = 0 + + private val privateSimple = 0 + + protected val protectedSimple = 0 + + var privateSetter = 0 + private set + + @A val annotated = 0 + + val annotatedGetter = 0 + @A get + + var annotatedSetter = 0 + @A set + + var annotatedAccessors = 0 + @A set + @A get +} diff --git a/native/native.tests/testData/klib/dump-metadata/Accessors.txt b/native/native.tests/testData/klib/dump-metadata/Accessors.txt new file mode 100644 index 00000000000..a929e697af3 --- /dev/null +++ b/native/native.tests/testData/klib/dump-metadata/Accessors.txt @@ -0,0 +1,17 @@ +package custom.pkg { + annotation class A constructor() : Annotation + class Foo constructor() { + @A val annotated: Int = 0 + var annotatedAccessors: Int + @A get + @A set + val annotatedGetter: Int = 0 + @A get + var annotatedSetter: Int + @A set + var privateSetter: Int + private set + protected val protectedSimple: Int = 0 + val simple: Int = 0 + } +} \ No newline at end of file diff --git a/kotlin-native/klib/src/test/testData/Classes.kt b/native/native.tests/testData/klib/dump-metadata/Classes.kt similarity index 58% rename from kotlin-native/klib/src/test/testData/Classes.kt rename to native/native.tests/testData/klib/dump-metadata/Classes.kt index 9471b75ae02..e912e979cdb 100644 --- a/kotlin-native/klib/src/test/testData/Classes.kt +++ b/native/native.tests/testData/klib/dump-metadata/Classes.kt @@ -1,19 +1,3 @@ -/* - * Copyright 2010-2018 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - class A { fun aFun() {} val aVal = 0 diff --git a/native/native.tests/testData/klib/dump-metadata/Classes.txt b/native/native.tests/testData/klib/dump-metadata/Classes.txt new file mode 100644 index 00000000000..612ac3d348d --- /dev/null +++ b/native/native.tests/testData/klib/dump-metadata/Classes.txt @@ -0,0 +1,48 @@ +package { + class A constructor() { + val aVal: Int = 0 + var aVar: String + fun aFun() + inner class B constructor() { + val bVal: Int = 0 + var bVar: String + fun bFun() + inner class C constructor() { + val cVal: Int = 0 + var cVar: String + fun cFun() + } + } + class E constructor() { + val eVal: Int = 0 + var eVar: String + fun eFun() + } + } + data class F constructor(fVal: Int, fVar: String) { + val fVal: Int + var fVar: String + operator fun component1(): Int + operator fun component2(): String + fun copy(fVal: Int = ..., fVar: String = ...): F + override fun equals(other: Any?): Boolean + fun fFun() + override fun hashCode(): Int + override fun toString(): String + } + class FinalImpl constructor() : OpenImpl { + override val iVal: Int = 0 + override var iVar: String + override fun iFun() + } + interface Interface { + val iVal: Int + var iVar: String + fun iFun() + } + open class OpenImpl constructor() : Interface { + override val iVal: Int = 0 + override var iVar: String + override fun iFun() + } +} \ No newline at end of file diff --git a/kotlin-native/klib/src/test/testData/Constructors.kt b/native/native.tests/testData/klib/dump-metadata/Constructors.kt similarity index 53% rename from kotlin-native/klib/src/test/testData/Constructors.kt rename to native/native.tests/testData/klib/dump-metadata/Constructors.kt index 939f517b697..17bff119793 100644 --- a/kotlin-native/klib/src/test/testData/Constructors.kt +++ b/native/native.tests/testData/klib/dump-metadata/Constructors.kt @@ -1,19 +1,3 @@ -/* - * Copyright 2010-2018 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - @file:Suppress("UNUSED_PARAMETER") annotation class A diff --git a/native/native.tests/testData/klib/dump-metadata/Constructors.txt b/native/native.tests/testData/klib/dump-metadata/Constructors.txt new file mode 100644 index 00000000000..32112c71f24 --- /dev/null +++ b/native/native.tests/testData/klib/dump-metadata/Constructors.txt @@ -0,0 +1,20 @@ +package { + annotation class A constructor() : Annotation + class Bar @A constructor(x: Int) + class Baz private constructor(x: Int) + class Foo constructor(x: Int) { + constructor() + constructor(x: Double) + constructor(x: Double, y: Int) + protected constructor(x: String) + @A constructor(x: Foo) + } + class Qux protected constructor(x: Int) + class Typed constructor(x: Int) { + constructor() + constructor(x: Double) + constructor(x: Double, y: Int) + protected constructor(x: String) + @A constructor(x: Foo) + } +} \ No newline at end of file diff --git a/native/native.tests/testData/klib/dump-metadata/Enum.kt b/native/native.tests/testData/klib/dump-metadata/Enum.kt new file mode 100644 index 00000000000..e3f89de299d --- /dev/null +++ b/native/native.tests/testData/klib/dump-metadata/Enum.kt @@ -0,0 +1,11 @@ +enum class E(val x: Int = 0) { + A, + B, + C(1) { + override fun enumFun() = 42 + }; + + open fun enumFun(): Int = 0 + val enumVal = 0 + var enumVar = "" +} \ No newline at end of file diff --git a/native/native.tests/testData/klib/dump-metadata/Enum.txt b/native/native.tests/testData/klib/dump-metadata/Enum.txt new file mode 100644 index 00000000000..545b6b2d3a4 --- /dev/null +++ b/native/native.tests/testData/klib/dump-metadata/Enum.txt @@ -0,0 +1,11 @@ +package { + enum class E private constructor(x: Int = ...) : Enum { + enum entry A + enum entry B + enum entry C + val enumVal: Int = 0 + var enumVar: String + val x: Int + open fun enumFun(): Int + } +} \ No newline at end of file diff --git a/native/native.tests/testData/klib/dump-metadata/FunctionModifiers.kt b/native/native.tests/testData/klib/dump-metadata/FunctionModifiers.kt new file mode 100644 index 00000000000..80b83ab2f3b --- /dev/null +++ b/native/native.tests/testData/klib/dump-metadata/FunctionModifiers.kt @@ -0,0 +1,8 @@ +class Foo { + fun f1() {} + infix fun f2(x: Int) {} + suspend fun f3() {} + operator fun plus(x: Int) {} + tailrec fun f4() {} + fun f5(vararg x: Int) {} +} \ No newline at end of file diff --git a/native/native.tests/testData/klib/dump-metadata/FunctionModifiers.txt b/native/native.tests/testData/klib/dump-metadata/FunctionModifiers.txt new file mode 100644 index 00000000000..c72b4e00601 --- /dev/null +++ b/native/native.tests/testData/klib/dump-metadata/FunctionModifiers.txt @@ -0,0 +1,10 @@ +package { + class Foo constructor() { + fun f1() + infix fun f2(x: Int) + suspend fun f3() + tailrec fun f4() + fun f5(vararg x: Int) + operator fun plus(x: Int) + } +} \ No newline at end of file diff --git a/native/native.tests/testData/klib/dump-metadata/MethodModality.kt b/native/native.tests/testData/klib/dump-metadata/MethodModality.kt new file mode 100644 index 00000000000..01844360ede --- /dev/null +++ b/native/native.tests/testData/klib/dump-metadata/MethodModality.kt @@ -0,0 +1,20 @@ +interface Interface { + fun interfaceFun() +} + +abstract class AbstractClass: Interface { + override fun interfaceFun() {} + abstract fun abstractFun() +} + +open class OpenClass: AbstractClass() { + override fun abstractFun() {} + open fun openFun1() {} + open fun openFun2() {} + fun finalFun() {} +} + +class FinalClass: OpenClass() { + override fun openFun1() {} + final override fun openFun2() {} +} \ No newline at end of file diff --git a/native/native.tests/testData/klib/dump-metadata/MethodModality.txt b/native/native.tests/testData/klib/dump-metadata/MethodModality.txt new file mode 100644 index 00000000000..563daa79d5a --- /dev/null +++ b/native/native.tests/testData/klib/dump-metadata/MethodModality.txt @@ -0,0 +1,19 @@ +package { + abstract class AbstractClass constructor() : Interface { + abstract fun abstractFun() + override fun interfaceFun() + } + class FinalClass constructor() : OpenClass { + override fun openFun1() + final override fun openFun2() + } + interface Interface { + fun interfaceFun() + } + open class OpenClass constructor() : AbstractClass { + override fun abstractFun() + fun finalFun() + open fun openFun1() + open fun openFun2() + } +} \ No newline at end of file diff --git a/native/native.tests/testData/klib/dump-metadata/Objects.kt b/native/native.tests/testData/klib/dump-metadata/Objects.kt new file mode 100644 index 00000000000..a640f799816 --- /dev/null +++ b/native/native.tests/testData/klib/dump-metadata/Objects.kt @@ -0,0 +1,21 @@ +// B.Companion and B.C are serialized in a different order in K1 and K2 +// MUTED_WHEN: K1 +object A { + fun a() {} +} + +class B { + companion object { + fun b() {} + } + + object C { + fun c() {} + } +} + +class D { + companion object E { + fun e() {} + } +} diff --git a/native/native.tests/testData/klib/dump-metadata/Objects.txt b/native/native.tests/testData/klib/dump-metadata/Objects.txt new file mode 100644 index 00000000000..ff6dc6e8fdb --- /dev/null +++ b/native/native.tests/testData/klib/dump-metadata/Objects.txt @@ -0,0 +1,18 @@ +package { + object A { + fun a() + } + class B constructor() { + companion object { + fun b() + } + object C { + fun c() + } + } + class D constructor() { + companion object E { + fun e() + } + } +} \ No newline at end of file diff --git a/kotlin-native/klib/src/test/testData/TopLevelFunctions.kt b/native/native.tests/testData/klib/dump-metadata/TopLevelFunctions.kt similarity index 51% rename from kotlin-native/klib/src/test/testData/TopLevelFunctions.kt rename to native/native.tests/testData/klib/dump-metadata/TopLevelFunctions.kt index 0f05388ae10..6bec232a3dd 100644 --- a/kotlin-native/klib/src/test/testData/TopLevelFunctions.kt +++ b/native/native.tests/testData/klib/dump-metadata/TopLevelFunctions.kt @@ -1,19 +1,3 @@ -/* - * Copyright 2010-2018 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - @file:Suppress("UNUSED_PARAMETER") annotation class A diff --git a/native/native.tests/testData/klib/dump-metadata/TopLevelFunctions.txt b/native/native.tests/testData/klib/dump-metadata/TopLevelFunctions.txt new file mode 100644 index 00000000000..3b5fe84022b --- /dev/null +++ b/native/native.tests/testData/klib/dump-metadata/TopLevelFunctions.txt @@ -0,0 +1,21 @@ +package { + annotation class A constructor() : Annotation + annotation class B constructor() : Annotation + class Foo constructor() + @A @B fun a() + fun Foo.e() + fun f1(x: Foo) + fun f2(x: Foo, y: Foo): Int + inline fun i1(block: () -> Foo) + inline fun i2(noinline block: () -> Foo) + inline fun i3(crossinline block: () -> Foo) + fun i4(block: (Foo) -> Int) + fun i5(block: (Foo, Foo) -> Int) + fun i6(block: Foo.() -> Int) + fun i7(block: Foo.(Foo) -> Int) + fun t1(x: Foo) + fun t2(x: T) + fun t3(x: T, y: F) + inline fun t4(x: T) + fun t5(x: T) +} \ No newline at end of file diff --git a/native/native.tests/testData/klib/dump-metadata/TopLevelPropertiesCustomPackage.kt b/native/native.tests/testData/klib/dump-metadata/TopLevelPropertiesCustomPackage.kt new file mode 100644 index 00000000000..0e35b9252ad --- /dev/null +++ b/native/native.tests/testData/klib/dump-metadata/TopLevelPropertiesCustomPackage.kt @@ -0,0 +1,12 @@ +@file:Suppress("UNUSED_PARAMETER") + +package custom.pkg + +typealias MyTransformer = (String) -> Int + +// top-level properties +val v1 = 1 +val v2 = "hello" +val v3: (String) -> Int = { it.length } +val v4: MyTransformer = v3 + diff --git a/native/native.tests/testData/klib/dump-metadata/TopLevelPropertiesCustomPackage.txt b/native/native.tests/testData/klib/dump-metadata/TopLevelPropertiesCustomPackage.txt new file mode 100644 index 00000000000..2e83223fccd --- /dev/null +++ b/native/native.tests/testData/klib/dump-metadata/TopLevelPropertiesCustomPackage.txt @@ -0,0 +1,7 @@ +package custom.pkg { + typealias MyTransformer = (String) -> Int + val v1: Int = 1 + val v2: String = "hello" + val v3: (String) -> Int + val v4: MyTransformer /* = (String) -> Int */ +} \ No newline at end of file diff --git a/native/native.tests/testData/klib/dump-metadata/TopLevelPropertiesRootPackage.kt b/native/native.tests/testData/klib/dump-metadata/TopLevelPropertiesRootPackage.kt new file mode 100644 index 00000000000..fc2e27f6c8b --- /dev/null +++ b/native/native.tests/testData/klib/dump-metadata/TopLevelPropertiesRootPackage.kt @@ -0,0 +1,10 @@ +@file:Suppress("UNUSED_PARAMETER") + +typealias MyTransformer = (String) -> Int + +// top-level properties +val v1 = 1 +val v2 = "hello" +val v3: (String) -> Int = { it.length } +val v4: MyTransformer = v3 + diff --git a/native/native.tests/testData/klib/dump-metadata/TopLevelPropertiesRootPackage.txt b/native/native.tests/testData/klib/dump-metadata/TopLevelPropertiesRootPackage.txt new file mode 100644 index 00000000000..07f8f2ad4df --- /dev/null +++ b/native/native.tests/testData/klib/dump-metadata/TopLevelPropertiesRootPackage.txt @@ -0,0 +1,7 @@ +package { + typealias MyTransformer = (String) -> Int + val v1: Int = 1 + val v2: String = "hello" + val v3: (String) -> Int + val v4: MyTransformer /* = (String) -> Int */ +} \ No newline at end of file diff --git a/native/native.tests/testData/klib/dump-metadata/TopLevelPropertiesWithClassesCustomPackage.kt b/native/native.tests/testData/klib/dump-metadata/TopLevelPropertiesWithClassesCustomPackage.kt new file mode 100644 index 00000000000..e699714afad --- /dev/null +++ b/native/native.tests/testData/klib/dump-metadata/TopLevelPropertiesWithClassesCustomPackage.kt @@ -0,0 +1,15 @@ +@file:Suppress("UNUSED_PARAMETER") + +package custom.pkg + +class Foo + +typealias MyTransformer = (String) -> Int + +// top-level properties +val v1 = 1 +val v2 = "hello" +val v3: (String) -> Int = { it.length } +val v4: MyTransformer = v3 + +object Bar diff --git a/native/native.tests/testData/klib/dump-metadata/TopLevelPropertiesWithClassesCustomPackage.txt b/native/native.tests/testData/klib/dump-metadata/TopLevelPropertiesWithClassesCustomPackage.txt new file mode 100644 index 00000000000..2ddc001b15a --- /dev/null +++ b/native/native.tests/testData/klib/dump-metadata/TopLevelPropertiesWithClassesCustomPackage.txt @@ -0,0 +1,9 @@ +package custom.pkg { + object Bar + class Foo constructor() + typealias MyTransformer = (String) -> Int + val v1: Int = 1 + val v2: String = "hello" + val v3: (String) -> Int + val v4: MyTransformer /* = (String) -> Int */ +} \ No newline at end of file diff --git a/native/native.tests/testData/klib/dump-metadata/TopLevelPropertiesWithClassesRootPackage.kt b/native/native.tests/testData/klib/dump-metadata/TopLevelPropertiesWithClassesRootPackage.kt new file mode 100644 index 00000000000..ffdf56c0489 --- /dev/null +++ b/native/native.tests/testData/klib/dump-metadata/TopLevelPropertiesWithClassesRootPackage.kt @@ -0,0 +1,13 @@ +@file:Suppress("UNUSED_PARAMETER") + +class Foo + +typealias MyTransformer = (String) -> Int + +// top-level properties +val v1 = 1 +val v2 = "hello" +val v3: (String) -> Int = { it.length } +val v4: MyTransformer = v3 + +object Bar diff --git a/native/native.tests/testData/klib/dump-metadata/TopLevelPropertiesWithClassesRootPackage.txt b/native/native.tests/testData/klib/dump-metadata/TopLevelPropertiesWithClassesRootPackage.txt new file mode 100644 index 00000000000..7f43d07a76b --- /dev/null +++ b/native/native.tests/testData/klib/dump-metadata/TopLevelPropertiesWithClassesRootPackage.txt @@ -0,0 +1,9 @@ +package { + object Bar + class Foo constructor() + typealias MyTransformer = (String) -> Int + val v1: Int = 1 + val v2: String = "hello" + val v3: (String) -> Int + val v4: MyTransformer /* = (String) -> Int */ +} \ No newline at end of file diff --git a/native/native.tests/testData/klib/dump-metadata/annotations.txt b/native/native.tests/testData/klib/dump-metadata/annotations.txt index aabac49b991..17c855ffde5 100644 --- a/native/native.tests/testData/klib/dump-metadata/annotations.txt +++ b/native/native.tests/testData/klib/dump-metadata/annotations.txt @@ -1,3 +1,4 @@ +package test { annotation class AnnoBackingField constructor() : Annotation annotation class AnnoClass constructor() : Annotation @Target(allowedTargets = {AnnotationTarget.TYPE_PARAMETER}) annotation class AnnoClassTypeParameter constructor() : Annotation @@ -28,3 +29,4 @@ @AnnoPropertyExtensionReceiver val Foo.extProp: Int @AnnoFunction fun @receiver:AnnoFunctionExtensionReceiver Foo.extfun(@AnnoFunctionParam x: Int) fun <@AnnoFunctionTypeParameter T> f(x: B<@AnnoClassUsageTypeParameter Int>) +} \ No newline at end of file diff --git a/native/native.tests/testData/klib/dump-metadata/annotations_source_retention.txt b/native/native.tests/testData/klib/dump-metadata/annotations_source_retention.txt index 36ace1acaed..70557e975c8 100644 --- a/native/native.tests/testData/klib/dump-metadata/annotations_source_retention.txt +++ b/native/native.tests/testData/klib/dump-metadata/annotations_source_retention.txt @@ -1,3 +1,4 @@ +package test { @Retention(value = AnnotationRetention.SOURCE) annotation class AnnoBackingField constructor() : Annotation @Retention(value = AnnotationRetention.SOURCE) annotation class AnnoClass constructor() : Annotation @Retention(value = AnnotationRetention.SOURCE) annotation class AnnoConstructor constructor() : Annotation @@ -20,3 +21,4 @@ } val Foo.extProp: Int fun Foo.extfun(x: Int) +} \ No newline at end of file diff --git a/native/native.tests/testData/klib/dump-metadata/builtinsSerializer/annotatedEnumEntry.txt b/native/native.tests/testData/klib/dump-metadata/builtinsSerializer/annotatedEnumEntry.txt index 74d66a30149..3dcbb32045f 100644 --- a/native/native.tests/testData/klib/dump-metadata/builtinsSerializer/annotatedEnumEntry.txt +++ b/native/native.tests/testData/klib/dump-metadata/builtinsSerializer/annotatedEnumEntry.txt @@ -1,3 +1,4 @@ +package test { annotation class Anno constructor(value: String = ..., x: Int = ...) : Annotation { val value: String val x: Int @@ -8,4 +9,5 @@ enum entry Entry2 @Anno(value = "3") @Bnno enum entry Entry3 @Anno(value = "4", x = 4) enum entry Entry4 - } \ No newline at end of file + } +} \ No newline at end of file diff --git a/native/native.tests/testData/klib/dump-metadata/builtinsSerializer/annotationArguments/annotation.txt b/native/native.tests/testData/klib/dump-metadata/builtinsSerializer/annotationArguments/annotation.txt index d4026429c46..7d3131aa9aa 100644 --- a/native/native.tests/testData/klib/dump-metadata/builtinsSerializer/annotationArguments/annotation.txt +++ b/native/native.tests/testData/klib/dump-metadata/builtinsSerializer/annotationArguments/annotation.txt @@ -1,3 +1,4 @@ +package test { annotation class AnnotationArray constructor(annotationArray: Array) : Annotation { val annotationArray: Array } @@ -6,4 +7,5 @@ annotation class Empty constructor() : Annotation annotation class JustAnnotation constructor(annotation: Empty) : Annotation { val annotation: Empty - } \ No newline at end of file + } +} diff --git a/native/native.tests/testData/klib/dump-metadata/builtinsSerializer/annotationArguments/enum.txt b/native/native.tests/testData/klib/dump-metadata/builtinsSerializer/annotationArguments/enum.txt index 4e4d081bf9a..b0ab93d35a0 100644 --- a/native/native.tests/testData/klib/dump-metadata/builtinsSerializer/annotationArguments/enum.txt +++ b/native/native.tests/testData/klib/dump-metadata/builtinsSerializer/annotationArguments/enum.txt @@ -1,3 +1,4 @@ +package test { @JustEnum(weapon = Weapon.SCISSORS) @EnumArray(enumArray = {}) class C1 constructor() @EnumArray(enumArray = {Weapon.PAPER, Weapon.ROCK}) class C2 constructor() annotation class EnumArray constructor(enumArray: Array) : Annotation { @@ -10,4 +11,5 @@ enum entry ROCK enum entry PAPER enum entry SCISSORS - } \ No newline at end of file + } +} diff --git a/native/native.tests/testData/klib/dump-metadata/builtinsSerializer/annotationArguments/primitiveArrays.txt b/native/native.tests/testData/klib/dump-metadata/builtinsSerializer/annotationArguments/primitiveArrays.txt index 6bbfbf25695..8ff6d59d220 100644 --- a/native/native.tests/testData/klib/dump-metadata/builtinsSerializer/annotationArguments/primitiveArrays.txt +++ b/native/native.tests/testData/klib/dump-metadata/builtinsSerializer/annotationArguments/primitiveArrays.txt @@ -1,3 +1,4 @@ +package test { @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 { @@ -10,3 +11,4 @@ val longArray: LongArray val shortArray: ShortArray } +} diff --git a/native/native.tests/testData/klib/dump-metadata/builtinsSerializer/annotationArguments/primitives.txt b/native/native.tests/testData/klib/dump-metadata/builtinsSerializer/annotationArguments/primitives.txt index 8498178959d..e1d872a1286 100644 --- a/native/native.tests/testData/klib/dump-metadata/builtinsSerializer/annotationArguments/primitives.txt +++ b/native/native.tests/testData/klib/dump-metadata/builtinsSerializer/annotationArguments/primitives.txt @@ -1,3 +1,4 @@ +package test { @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 @@ -9,3 +10,4 @@ val long: Long val short: Short } +} diff --git a/native/native.tests/testData/klib/dump-metadata/builtinsSerializer/annotationArguments/string.txt b/native/native.tests/testData/klib/dump-metadata/builtinsSerializer/annotationArguments/string.txt index 62df3fbdd69..eb6ec27656d 100644 --- a/native/native.tests/testData/klib/dump-metadata/builtinsSerializer/annotationArguments/string.txt +++ b/native/native.tests/testData/klib/dump-metadata/builtinsSerializer/annotationArguments/string.txt @@ -1,3 +1,4 @@ +package test { @JustString(string = "kotlin") @StringArray(stringArray = {}) class C1 constructor() @StringArray(stringArray = {"java", ""}) class C2 constructor() annotation class JustString constructor(string: String) : Annotation { @@ -5,4 +6,5 @@ } annotation class StringArray constructor(stringArray: Array) : Annotation { val stringArray: Array - } \ No newline at end of file + } +} diff --git a/native/native.tests/testData/klib/dump-metadata/builtinsSerializer/annotationArguments/varargs.txt b/native/native.tests/testData/klib/dump-metadata/builtinsSerializer/annotationArguments/varargs.txt index 9cc17b69cf7..402298c680e 100644 --- a/native/native.tests/testData/klib/dump-metadata/builtinsSerializer/annotationArguments/varargs.txt +++ b/native/native.tests/testData/klib/dump-metadata/builtinsSerializer/annotationArguments/varargs.txt @@ -1,3 +1,4 @@ +package test { enum class My private constructor() : Enum { enum entry ALPHA enum entry BETA @@ -6,4 +7,5 @@ annotation class ann constructor(vararg m: My) : Annotation { val m: Array } - @ann(m = {My.ALPHA, My.BETA}) annotation class annotated constructor() : Annotation \ No newline at end of file + @ann(m = {My.ALPHA, My.BETA}) annotation class annotated constructor() : Annotation +} diff --git a/native/native.tests/testData/klib/dump-metadata/builtinsSerializer/annotationTargets.txt b/native/native.tests/testData/klib/dump-metadata/builtinsSerializer/annotationTargets.txt index 7d10277f41a..1e7a31be05d 100644 --- a/native/native.tests/testData/klib/dump-metadata/builtinsSerializer/annotationTargets.txt +++ b/native/native.tests/testData/klib/dump-metadata/builtinsSerializer/annotationTargets.txt @@ -1,3 +1,4 @@ +package test { @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 @@ -12,4 +13,5 @@ @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 \ No newline at end of file + @anno(x = "extension property") val Double.p2: Double +} \ No newline at end of file diff --git a/native/native.tests/testData/klib/dump-metadata/builtinsSerializer/binaryRetainedAnnotation.txt b/native/native.tests/testData/klib/dump-metadata/builtinsSerializer/binaryRetainedAnnotation.txt index 335e202bd51..c882c0cc694 100644 --- a/native/native.tests/testData/klib/dump-metadata/builtinsSerializer/binaryRetainedAnnotation.txt +++ b/native/native.tests/testData/klib/dump-metadata/builtinsSerializer/binaryRetainedAnnotation.txt @@ -1,7 +1,9 @@ +package test { @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 { @A enum entry ENTRY } @A class Klass @A constructor() @A fun <@A T> function(@A param: Unit) - @A val property: Unit \ No newline at end of file + @A val property: Unit +} \ No newline at end of file diff --git a/native/native.tests/testData/klib/dump-metadata/builtinsSerializer/compileTimeConstants.txt b/native/native.tests/testData/klib/dump-metadata/builtinsSerializer/compileTimeConstants.txt index 4d944c555d1..cdcdfda67f8 100644 --- a/native/native.tests/testData/klib/dump-metadata/builtinsSerializer/compileTimeConstants.txt +++ b/native/native.tests/testData/klib/dump-metadata/builtinsSerializer/compileTimeConstants.txt @@ -1,3 +1,4 @@ +package test { class Class constructor() { val arrayConst: Any = {1.toByte(), 2.toByte()} val booleanConst: Boolean = true @@ -27,3 +28,4 @@ val longConst: Long = 40.toLong() val shortConst: Short = 20.toShort() val stringConst: String = "abcd" +} \ No newline at end of file diff --git a/native/native.tests/testData/klib/dump-metadata/builtinsSerializer/nestedClassesAndObjects.txt b/native/native.tests/testData/klib/dump-metadata/builtinsSerializer/nestedClassesAndObjects.txt index 207859b5afb..2eff080a013 100644 --- a/native/native.tests/testData/klib/dump-metadata/builtinsSerializer/nestedClassesAndObjects.txt +++ b/native/native.tests/testData/klib/dump-metadata/builtinsSerializer/nestedClassesAndObjects.txt @@ -1,3 +1,4 @@ +package test { class ClassA constructor() { class classB constructor() { fun memberFromB(): Int @@ -25,3 +26,4 @@ val memberFromObjA: Int = 300 } } +} \ No newline at end of file diff --git a/native/native.tests/testData/klib/dump-metadata/builtinsSerializer/propertyAccessorAnnotations.txt b/native/native.tests/testData/klib/dump-metadata/builtinsSerializer/propertyAccessorAnnotations.txt index 130b60d8b50..e78cce52f88 100644 --- a/native/native.tests/testData/klib/dump-metadata/builtinsSerializer/propertyAccessorAnnotations.txt +++ b/native/native.tests/testData/klib/dump-metadata/builtinsSerializer/propertyAccessorAnnotations.txt @@ -1,7 +1,9 @@ +package test { 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 \ No newline at end of file + @Anno(value = "setter") set +} \ No newline at end of file diff --git a/native/native.tests/testData/klib/dump-metadata/builtinsSerializer/simple.txt b/native/native.tests/testData/klib/dump-metadata/builtinsSerializer/simple.txt index b2220221083..718f4e03cb4 100644 --- a/native/native.tests/testData/klib/dump-metadata/builtinsSerializer/simple.txt +++ b/native/native.tests/testData/klib/dump-metadata/builtinsSerializer/simple.txt @@ -1,6 +1,8 @@ +package test { class Class constructor() { fun member(): Nothing? } fun T.extension(): T? fun function(int: Int, string: String = ...): Class - val property: Unit \ No newline at end of file + val property: Unit +} \ No newline at end of file diff --git a/native/native.tests/testData/klib/dump-metadata/builtinsSerializer/sourceRetainedAnnotation.txt b/native/native.tests/testData/klib/dump-metadata/builtinsSerializer/sourceRetainedAnnotation.txt index 2f76428318c..9b491f26c9e 100644 --- a/native/native.tests/testData/klib/dump-metadata/builtinsSerializer/sourceRetainedAnnotation.txt +++ b/native/native.tests/testData/klib/dump-metadata/builtinsSerializer/sourceRetainedAnnotation.txt @@ -1,7 +1,9 @@ +package test { @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 entry ENTRY } class Klass constructor() fun function(param: Unit) - val property: Unit \ No newline at end of file + val property: Unit +} \ No newline at end of file diff --git a/native/native.tests/testData/klib/dump-metadata/builtinsSerializer/stringConcatenation.txt b/native/native.tests/testData/klib/dump-metadata/builtinsSerializer/stringConcatenation.txt index af65c1270af..e95aa8d5b9e 100644 --- a/native/native.tests/testData/klib/dump-metadata/builtinsSerializer/stringConcatenation.txt +++ b/native/native.tests/testData/klib/dump-metadata/builtinsSerializer/stringConcatenation.txt @@ -3,4 +3,5 @@ package { object Obj { const val O: String = "O" val concat: String = "OK" - } \ No newline at end of file + } +} \ No newline at end of file diff --git a/native/native.tests/testData/klib/dump-metadata/builtinsSerializer/typeParameterAnnotation.txt b/native/native.tests/testData/klib/dump-metadata/builtinsSerializer/typeParameterAnnotation.txt index a322c2e5c81..940a6869cef 100644 --- a/native/native.tests/testData/klib/dump-metadata/builtinsSerializer/typeParameterAnnotation.txt +++ b/native/native.tests/testData/klib/dump-metadata/builtinsSerializer/typeParameterAnnotation.txt @@ -1,4 +1,6 @@ +package test { @Retention(value = AnnotationRetention.BINARY) @Target(allowedTargets = {AnnotationTarget.TYPE_PARAMETER}) annotation class Ann constructor(value: String) : Annotation { val value: String } - inline fun foo() \ No newline at end of file + inline fun foo() +} \ No newline at end of file diff --git a/native/native.tests/testData/klib/dump-metadata/data_class.txt b/native/native.tests/testData/klib/dump-metadata/data_class.txt index ec55d50b826..6a477685a7b 100644 --- a/native/native.tests/testData/klib/dump-metadata/data_class.txt +++ b/native/native.tests/testData/klib/dump-metadata/data_class.txt @@ -1,3 +1,4 @@ +package test { data class DataClass constructor(intProp: Int, stringProp: String) { val intProp: Int val nonConstructorProp: Int = 0 @@ -13,4 +14,5 @@ override fun equals(other: Any?): Boolean override fun hashCode(): Int override fun toString(): String - } \ No newline at end of file + } +} \ No newline at end of file diff --git a/native/native.tests/testData/klib/dump-metadata/klib/fieldAnnotations.txt b/native/native.tests/testData/klib/dump-metadata/klib/fieldAnnotations.txt index 41631032534..2dce09c141e 100644 --- a/native/native.tests/testData/klib/dump-metadata/klib/fieldAnnotations.txt +++ b/native/native.tests/testData/klib/dump-metadata/klib/fieldAnnotations.txt @@ -1,7 +1,9 @@ +package test { 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 \ No newline at end of file + @delegate:Ann var y: Int +} \ No newline at end of file diff --git a/native/native.tests/testData/klib/dump-metadata/klib/receiverAnnotations.txt b/native/native.tests/testData/klib/dump-metadata/klib/receiverAnnotations.txt index deb434eff9d..fed8d36e370 100644 --- a/native/native.tests/testData/klib/dump-metadata/klib/receiverAnnotations.txt +++ b/native/native.tests/testData/klib/dump-metadata/klib/receiverAnnotations.txt @@ -1,7 +1,9 @@ +package test { 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 \ No newline at end of file + @Ann fun @receiver:Ann Int.foo(@Ann arg: Int): Int +} \ No newline at end of file diff --git a/native/native.tests/testData/klib/dump-metadata/kt55464_serializeTypeAnnotation.txt b/native/native.tests/testData/klib/dump-metadata/kt55464_serializeTypeAnnotation.txt index 2375c92ed3b..796537271c5 100644 --- a/native/native.tests/testData/klib/dump-metadata/kt55464_serializeTypeAnnotation.txt +++ b/native/native.tests/testData/klib/dump-metadata/kt55464_serializeTypeAnnotation.txt @@ -1,2 +1,4 @@ +package test { class C constructor() - fun C.builder(c: C.() -> Unit) \ No newline at end of file + fun C.builder(c: C.() -> Unit) +} \ No newline at end of file diff --git a/native/native.tests/testData/klib/dump-metadata/kt56018_value_parameters_annotations.txt b/native/native.tests/testData/klib/dump-metadata/kt56018_value_parameters_annotations.txt index a7241a770b3..e22ed2fa88b 100644 --- a/native/native.tests/testData/klib/dump-metadata/kt56018_value_parameters_annotations.txt +++ b/native/native.tests/testData/klib/dump-metadata/kt56018_value_parameters_annotations.txt @@ -1,2 +1,4 @@ +package test { annotation class Annotation constructor() : Annotation - fun foo(@Annotation arg: Int) \ No newline at end of file + fun foo(@Annotation arg: Int) +} \ No newline at end of file diff --git a/native/native.tests/testData/klib/dump-metadata/property_accessors.txt b/native/native.tests/testData/klib/dump-metadata/property_accessors.txt index 0bb7bfddd3f..8e87b4c9996 100644 --- a/native/native.tests/testData/klib/dump-metadata/property_accessors.txt +++ b/native/native.tests/testData/klib/dump-metadata/property_accessors.txt @@ -1,4 +1,5 @@ -abstract class A constructor() { +package test { + abstract class A constructor() { abstract val a: Int abstract var b: Int protected set @@ -13,3 +14,4 @@ abstract class A constructor() { open var l: Int protected set } +} \ No newline at end of file diff --git a/native/native.tests/testData/klib/dump-metadata/type_annotations.txt b/native/native.tests/testData/klib/dump-metadata/type_annotations.txt index 4fe67309b5f..a919adee25c 100644 --- a/native/native.tests/testData/klib/dump-metadata/type_annotations.txt +++ b/native/native.tests/testData/klib/dump-metadata/type_annotations.txt @@ -1,6 +1,8 @@ +package test { @Retention(value = AnnotationRetention.BINARY) @Target(allowedTargets = {AnnotationTarget.TYPE}) annotation class AnnoBinary constructor() : Annotation @Retention(value = AnnotationRetention.RUNTIME) @Target(allowedTargets = {AnnotationTarget.TYPE}) annotation class AnnoRuntime constructor() : Annotation @Retention(value = AnnotationRetention.SOURCE) @Target(allowedTargets = {AnnotationTarget.TYPE}) annotation class AnnoSource constructor() : Annotation fun withBinaryAnnotation(id: @AnnoBinary Int) fun withRuntimeAnnotation(id: @AnnoRuntime Int) - fun withSourceAnnotation(id: Int) \ No newline at end of file + fun withSourceAnnotation(id: Int) +} \ No newline at end of file diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeKlibDumpMetadataTestGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeKlibDumpMetadataTestGenerated.java index 587e743ab67..da98e64a0e2 100644 --- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeKlibDumpMetadataTestGenerated.java +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeKlibDumpMetadataTestGenerated.java @@ -23,6 +23,12 @@ import java.util.regex.Pattern; @Tag("frontend-fir") @FirPipeline() public class FirNativeKlibDumpMetadataTestGenerated extends AbstractNativeKlibDumpMetadataTest { + @Test + @TestMetadata("Accessors.kt") + public void testAccessors() throws Exception { + runTest("native/native.tests/testData/klib/dump-metadata/Accessors.kt"); + } + @Test public void testAllFilesPresentInDump_metadata() throws Exception { KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("native/native.tests/testData/klib/dump-metadata"), Pattern.compile("^([^_](.+)).kt$"), null, true); @@ -40,12 +46,36 @@ public class FirNativeKlibDumpMetadataTestGenerated extends AbstractNativeKlibDu runTest("native/native.tests/testData/klib/dump-metadata/annotations_source_retention.kt"); } + @Test + @TestMetadata("Classes.kt") + public void testClasses() throws Exception { + runTest("native/native.tests/testData/klib/dump-metadata/Classes.kt"); + } + + @Test + @TestMetadata("Constructors.kt") + public void testConstructors() throws Exception { + runTest("native/native.tests/testData/klib/dump-metadata/Constructors.kt"); + } + @Test @TestMetadata("data_class.kt") public void testData_class() throws Exception { runTest("native/native.tests/testData/klib/dump-metadata/data_class.kt"); } + @Test + @TestMetadata("Enum.kt") + public void testEnum() throws Exception { + runTest("native/native.tests/testData/klib/dump-metadata/Enum.kt"); + } + + @Test + @TestMetadata("FunctionModifiers.kt") + public void testFunctionModifiers() throws Exception { + runTest("native/native.tests/testData/klib/dump-metadata/FunctionModifiers.kt"); + } + @Test @TestMetadata("kt55464_serializeTypeAnnotation.kt") public void testKt55464_serializeTypeAnnotation() throws Exception { @@ -58,12 +88,54 @@ public class FirNativeKlibDumpMetadataTestGenerated extends AbstractNativeKlibDu runTest("native/native.tests/testData/klib/dump-metadata/kt56018_value_parameters_annotations.kt"); } + @Test + @TestMetadata("MethodModality.kt") + public void testMethodModality() throws Exception { + runTest("native/native.tests/testData/klib/dump-metadata/MethodModality.kt"); + } + + @Test + @TestMetadata("Objects.kt") + public void testObjects() throws Exception { + runTest("native/native.tests/testData/klib/dump-metadata/Objects.kt"); + } + @Test @TestMetadata("property_accessors.kt") public void testProperty_accessors() throws Exception { runTest("native/native.tests/testData/klib/dump-metadata/property_accessors.kt"); } + @Test + @TestMetadata("TopLevelFunctions.kt") + public void testTopLevelFunctions() throws Exception { + runTest("native/native.tests/testData/klib/dump-metadata/TopLevelFunctions.kt"); + } + + @Test + @TestMetadata("TopLevelPropertiesCustomPackage.kt") + public void testTopLevelPropertiesCustomPackage() throws Exception { + runTest("native/native.tests/testData/klib/dump-metadata/TopLevelPropertiesCustomPackage.kt"); + } + + @Test + @TestMetadata("TopLevelPropertiesRootPackage.kt") + public void testTopLevelPropertiesRootPackage() throws Exception { + runTest("native/native.tests/testData/klib/dump-metadata/TopLevelPropertiesRootPackage.kt"); + } + + @Test + @TestMetadata("TopLevelPropertiesWithClassesCustomPackage.kt") + public void testTopLevelPropertiesWithClassesCustomPackage() throws Exception { + runTest("native/native.tests/testData/klib/dump-metadata/TopLevelPropertiesWithClassesCustomPackage.kt"); + } + + @Test + @TestMetadata("TopLevelPropertiesWithClassesRootPackage.kt") + public void testTopLevelPropertiesWithClassesRootPackage() throws Exception { + runTest("native/native.tests/testData/klib/dump-metadata/TopLevelPropertiesWithClassesRootPackage.kt"); + } + @Test @TestMetadata("type_annotations.kt") public void testType_annotations() throws Exception { diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/NativeKlibDumpMetadataTestGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/NativeKlibDumpMetadataTestGenerated.java index 53bfed4d969..a282de94c76 100644 --- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/NativeKlibDumpMetadataTestGenerated.java +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/NativeKlibDumpMetadataTestGenerated.java @@ -19,6 +19,12 @@ import java.util.regex.Pattern; @TestMetadata("native/native.tests/testData/klib/dump-metadata") @TestDataPath("$PROJECT_ROOT") public class NativeKlibDumpMetadataTestGenerated extends AbstractNativeKlibDumpMetadataTest { + @Test + @TestMetadata("Accessors.kt") + public void testAccessors() throws Exception { + runTest("native/native.tests/testData/klib/dump-metadata/Accessors.kt"); + } + @Test public void testAllFilesPresentInDump_metadata() throws Exception { KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("native/native.tests/testData/klib/dump-metadata"), Pattern.compile("^([^_](.+)).kt$"), null, true); @@ -36,12 +42,36 @@ public class NativeKlibDumpMetadataTestGenerated extends AbstractNativeKlibDumpM runTest("native/native.tests/testData/klib/dump-metadata/annotations_source_retention.kt"); } + @Test + @TestMetadata("Classes.kt") + public void testClasses() throws Exception { + runTest("native/native.tests/testData/klib/dump-metadata/Classes.kt"); + } + + @Test + @TestMetadata("Constructors.kt") + public void testConstructors() throws Exception { + runTest("native/native.tests/testData/klib/dump-metadata/Constructors.kt"); + } + @Test @TestMetadata("data_class.kt") public void testData_class() throws Exception { runTest("native/native.tests/testData/klib/dump-metadata/data_class.kt"); } + @Test + @TestMetadata("Enum.kt") + public void testEnum() throws Exception { + runTest("native/native.tests/testData/klib/dump-metadata/Enum.kt"); + } + + @Test + @TestMetadata("FunctionModifiers.kt") + public void testFunctionModifiers() throws Exception { + runTest("native/native.tests/testData/klib/dump-metadata/FunctionModifiers.kt"); + } + @Test @TestMetadata("kt55464_serializeTypeAnnotation.kt") public void testKt55464_serializeTypeAnnotation() throws Exception { @@ -54,12 +84,54 @@ public class NativeKlibDumpMetadataTestGenerated extends AbstractNativeKlibDumpM runTest("native/native.tests/testData/klib/dump-metadata/kt56018_value_parameters_annotations.kt"); } + @Test + @TestMetadata("MethodModality.kt") + public void testMethodModality() throws Exception { + runTest("native/native.tests/testData/klib/dump-metadata/MethodModality.kt"); + } + + @Test + @TestMetadata("Objects.kt") + public void testObjects() throws Exception { + runTest("native/native.tests/testData/klib/dump-metadata/Objects.kt"); + } + @Test @TestMetadata("property_accessors.kt") public void testProperty_accessors() throws Exception { runTest("native/native.tests/testData/klib/dump-metadata/property_accessors.kt"); } + @Test + @TestMetadata("TopLevelFunctions.kt") + public void testTopLevelFunctions() throws Exception { + runTest("native/native.tests/testData/klib/dump-metadata/TopLevelFunctions.kt"); + } + + @Test + @TestMetadata("TopLevelPropertiesCustomPackage.kt") + public void testTopLevelPropertiesCustomPackage() throws Exception { + runTest("native/native.tests/testData/klib/dump-metadata/TopLevelPropertiesCustomPackage.kt"); + } + + @Test + @TestMetadata("TopLevelPropertiesRootPackage.kt") + public void testTopLevelPropertiesRootPackage() throws Exception { + runTest("native/native.tests/testData/klib/dump-metadata/TopLevelPropertiesRootPackage.kt"); + } + + @Test + @TestMetadata("TopLevelPropertiesWithClassesCustomPackage.kt") + public void testTopLevelPropertiesWithClassesCustomPackage() throws Exception { + runTest("native/native.tests/testData/klib/dump-metadata/TopLevelPropertiesWithClassesCustomPackage.kt"); + } + + @Test + @TestMetadata("TopLevelPropertiesWithClassesRootPackage.kt") + public void testTopLevelPropertiesWithClassesRootPackage() throws Exception { + runTest("native/native.tests/testData/klib/dump-metadata/TopLevelPropertiesWithClassesRootPackage.kt"); + } + @Test @TestMetadata("type_annotations.kt") public void testType_annotations() throws Exception { diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/AbstractNativeKlibDumpMetadataTest.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/AbstractNativeKlibDumpMetadataTest.kt index 03089748343..70e64e295d0 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/AbstractNativeKlibDumpMetadataTest.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/AbstractNativeKlibDumpMetadataTest.kt @@ -34,8 +34,11 @@ abstract class AbstractNativeKlibDumpMetadataTest : AbstractNativeSimpleTest() { val kotlinNativeClassLoader = testRunSettings.get() val metadata = testCompilationResult.assertSuccess().resultingArtifact.dumpMetadata(kotlinNativeClassLoader.classLoader) - val metadataFiltered = filterContentsOutput(metadata, linestoExclude = listOf("package test {", "}", "")) - assertEqualsToFile(File("${testPathFull.canonicalPath.substringBeforeLast(".")}.txt"), StringUtilRt.convertLineSeparators(metadataFiltered)) + val metadataFiltered = filterOutput(metadata) + assertEqualsToFile( + File("${testPathFull.canonicalPath.substringBeforeLast(".")}.txt"), + StringUtilRt.convertLineSeparators(metadataFiltered) + ) } private fun generateTestCaseWithSingleSource(source: File, extraArgs: List): TestCase { @@ -56,9 +59,25 @@ abstract class AbstractNativeKlibDumpMetadataTest : AbstractNativeSimpleTest() { } } - private fun filterContentsOutput(contents: String, linestoExclude: List) = - contents.lines() - .filterNot { line -> - linestoExclude.any { exclude -> exclude == line } - }.joinToString(separator = "\n") + // Remove intermediate "}\n\npackage ABC {\n" parts. + private fun filterOutput(contents: String): String { + var packageLineMet = false + return contents.lineSequence() + .dropWhile { line -> line.isBlank() } + .filter { line -> + when { + line.isBlank() -> false + line.startsWith("package ") -> { + if (packageLineMet) + false + else { + packageLineMet = true + true + } + } + line == "}" -> false + else -> true + } + }.joinToString(separator = "\n", postfix = "\n}") + } }