diff --git a/src/functionalTest/kotlin/kotlinx/validation/api/TestDsl.kt b/src/functionalTest/kotlin/kotlinx/validation/api/TestDsl.kt index 6c83d163..51c107bd 100644 --- a/src/functionalTest/kotlin/kotlinx/validation/api/TestDsl.kt +++ b/src/functionalTest/kotlin/kotlinx/validation/api/TestDsl.kt @@ -27,8 +27,10 @@ internal fun BaseKotlinGradleTest.test( createNewFile() } - scope.files.forEach { + scope.files.forEachIndexed { index, it -> val fileContent = readFileList(it) + + if (index > 0) fileWriteTo.appendText("\n") fileWriteTo.appendText(fileContent) } } diff --git a/src/functionalTest/kotlin/kotlinx/validation/test/DefaultConfigTests.kt b/src/functionalTest/kotlin/kotlinx/validation/test/DefaultConfigTests.kt index adfca8c2..78e13b17 100644 --- a/src/functionalTest/kotlin/kotlinx/validation/test/DefaultConfigTests.kt +++ b/src/functionalTest/kotlin/kotlinx/validation/test/DefaultConfigTests.kt @@ -132,7 +132,7 @@ internal class DefaultConfigTests : BaseKotlinGradleTest() { runner.buildAndFail().apply { val dumpOutput = - " @@ -1,1 +1,7 @@\n" + + " @@ -1,1 +1,6 @@\n" + " +public final class com/company/BuildConfig {\n" + " +\tpublic fun ()V\n" + " +\tpublic final fun function ()I\n" + diff --git a/src/functionalTest/resources/examples/classes/AnotherBuildConfig.dump b/src/functionalTest/resources/examples/classes/AnotherBuildConfig.dump index 7741799c..b3485c6d 100644 --- a/src/functionalTest/resources/examples/classes/AnotherBuildConfig.dump +++ b/src/functionalTest/resources/examples/classes/AnotherBuildConfig.dump @@ -3,4 +3,3 @@ public final class org/different/pack/BuildConfig { public final fun f1 ()I public final fun getP1 ()I } - diff --git a/src/functionalTest/resources/examples/classes/BuildCon.dump b/src/functionalTest/resources/examples/classes/BuildCon.dump index b21a6b70..329c54c6 100644 --- a/src/functionalTest/resources/examples/classes/BuildCon.dump +++ b/src/functionalTest/resources/examples/classes/BuildCon.dump @@ -3,4 +3,3 @@ public final class com/company/BuildCon { public final fun f1 ()I public final fun getP1 ()I } - diff --git a/src/functionalTest/resources/examples/classes/ClassWithPublicMarkers.dump b/src/functionalTest/resources/examples/classes/ClassWithPublicMarkers.dump index 89b68dbe..abbe64df 100644 --- a/src/functionalTest/resources/examples/classes/ClassWithPublicMarkers.dump +++ b/src/functionalTest/resources/examples/classes/ClassWithPublicMarkers.dump @@ -20,4 +20,3 @@ public final class foo/api/ClassInPublicPackage { public final class foo/api/ClassInPublicPackage$Inner { public fun ()V } - diff --git a/src/functionalTest/resources/examples/classes/JavaLib.dump b/src/functionalTest/resources/examples/classes/JavaLib.dump index 3e9c2425..e1043048 100644 --- a/src/functionalTest/resources/examples/classes/JavaLib.dump +++ b/src/functionalTest/resources/examples/classes/JavaLib.dump @@ -9,4 +9,3 @@ public final class org/jetbrains/kotlinx/android/java/library/BuildConfig { public static final field LIBRARY_PACKAGE_NAME Ljava/lang/String; public fun ()V } - diff --git a/src/functionalTest/resources/examples/classes/KotlinLib.dump b/src/functionalTest/resources/examples/classes/KotlinLib.dump index 2ff97443..b24a95cd 100644 --- a/src/functionalTest/resources/examples/classes/KotlinLib.dump +++ b/src/functionalTest/resources/examples/classes/KotlinLib.dump @@ -9,4 +9,3 @@ public final class org/jetbrains/kotlinx/android/kotlin/library/BuildConfig { public static final field LIBRARY_PACKAGE_NAME Ljava/lang/String; public fun ()V } - diff --git a/src/functionalTest/resources/examples/classes/MixedAnnotations.dump b/src/functionalTest/resources/examples/classes/MixedAnnotations.dump index 9d7982fc..0067d7fc 100644 --- a/src/functionalTest/resources/examples/classes/MixedAnnotations.dump +++ b/src/functionalTest/resources/examples/classes/MixedAnnotations.dump @@ -2,4 +2,3 @@ public final class mixed/MarkedPublicWithPrivateMembers { public fun ()V public final fun otherFun ()V } - diff --git a/src/functionalTest/resources/examples/classes/Properties.dump b/src/functionalTest/resources/examples/classes/Properties.dump index f5c21ac9..07adbf80 100644 --- a/src/functionalTest/resources/examples/classes/Properties.dump +++ b/src/functionalTest/resources/examples/classes/Properties.dump @@ -7,4 +7,3 @@ public abstract interface annotation class foo/HiddenField : java/lang/annotatio public abstract interface annotation class foo/HiddenProperty : java/lang/annotation/Annotation { } - diff --git a/src/functionalTest/resources/examples/classes/PropertiesJarTransformed.dump b/src/functionalTest/resources/examples/classes/PropertiesJarTransformed.dump index dc02831c..65713769 100644 --- a/src/functionalTest/resources/examples/classes/PropertiesJarTransformed.dump +++ b/src/functionalTest/resources/examples/classes/PropertiesJarTransformed.dump @@ -5,4 +5,3 @@ public final class foo/ClassWithProperties { public final fun setBar1 (I)V public final fun setBar2 (I)V } - diff --git a/src/functionalTest/resources/examples/classes/Subsub1Class.dump b/src/functionalTest/resources/examples/classes/Subsub1Class.dump index 4e18e8d0..0e368960 100644 --- a/src/functionalTest/resources/examples/classes/Subsub1Class.dump +++ b/src/functionalTest/resources/examples/classes/Subsub1Class.dump @@ -2,4 +2,3 @@ public final class com/company/subsub1/Subsub1Class { public fun ()V public final fun getProp ()I } - diff --git a/src/functionalTest/resources/examples/classes/Subsub2Class.dump b/src/functionalTest/resources/examples/classes/Subsub2Class.dump index ad74324e..4ec20de9 100644 --- a/src/functionalTest/resources/examples/classes/Subsub2Class.dump +++ b/src/functionalTest/resources/examples/classes/Subsub2Class.dump @@ -2,4 +2,3 @@ public final class com/company/subsub2/Subsub2Class { public fun ()V public final fun getProp ()I } - diff --git a/src/main/kotlin/KotlinApiBuildTask.kt b/src/main/kotlin/KotlinApiBuildTask.kt index 0df744bb..b7fff279 100644 --- a/src/main/kotlin/KotlinApiBuildTask.kt +++ b/src/main/kotlin/KotlinApiBuildTask.kt @@ -107,13 +107,7 @@ public open class KotlinApiBuildTask @Inject constructor( outputApiDir.resolve("$projectName.api").bufferedWriter().use { writer -> filteredSignatures .sortedBy { it.name } - .forEach { api -> - writer.append(api.signature).appendLine(" {") - api.memberSignatures - .sortedWith(MEMBER_SORT_ORDER) - .forEach { writer.append("\t").appendLine(it.signature) } - writer.appendLine("}\n") - } + .dump(writer) } } diff --git a/src/main/kotlin/api/KotlinSignaturesLoading.kt b/src/main/kotlin/api/KotlinSignaturesLoading.kt index ebefee00..6d6246d6 100644 --- a/src/main/kotlin/api/KotlinSignaturesLoading.kt +++ b/src/main/kotlin/api/KotlinSignaturesLoading.kt @@ -313,13 +313,15 @@ public fun List.dump(): PrintStream = dump(to = System.out @ExternalApi public fun List.dump(to: T): T { - forEach { classApi -> + forEachIndexed { index, classApi -> with(to) { + if (index > 0) appendLine() + append(classApi.signature).appendLine(" {") classApi.memberSignatures .sortedWith(MEMBER_SORT_ORDER) .forEach { append("\t").appendLine(it.signature) } - appendLine("}\n") + appendLine("}") } } return to diff --git a/src/test/kotlin/cases/annotations/annotations.txt b/src/test/kotlin/cases/annotations/annotations.txt index b084dbcc..b807a501 100644 --- a/src/test/kotlin/cases/annotations/annotations.txt +++ b/src/test/kotlin/cases/annotations/annotations.txt @@ -1,4 +1,3 @@ public abstract interface annotation class cases/annotations/Foo : java/lang/annotation/Annotation { public abstract fun i ()I } - diff --git a/src/test/kotlin/cases/companions/companions.txt b/src/test/kotlin/cases/companions/companions.txt index 9138da81..f4d9294f 100644 --- a/src/test/kotlin/cases/companions/companions.txt +++ b/src/test/kotlin/cases/companions/companions.txt @@ -113,4 +113,3 @@ public final class cases/companions/PublishedApiClasses$PublishedApiCompanion { public final class cases/companions/PublishedApiClasses$PublishedApiCompanion$Companion { } - diff --git a/src/test/kotlin/cases/default/default.txt b/src/test/kotlin/cases/default/default.txt index 6e6eb8a9..0780e6ec 100644 --- a/src/test/kotlin/cases/default/default.txt +++ b/src/test/kotlin/cases/default/default.txt @@ -22,4 +22,3 @@ public final class cases/default/PublishedApiWithDefaultsKt { public static final fun twoDefaults (ILjava/lang/Object;Ljava/lang/String;)V public static synthetic fun twoDefaults$default (ILjava/lang/Object;Ljava/lang/String;ILjava/lang/Object;)V } - diff --git a/src/test/kotlin/cases/enums/enums.txt b/src/test/kotlin/cases/enums/enums.txt index d086c780..0773b9c4 100644 --- a/src/test/kotlin/cases/enums/enums.txt +++ b/src/test/kotlin/cases/enums/enums.txt @@ -18,4 +18,3 @@ public final class cases/enums/JavaEnum : java/lang/Enum { public static fun valueOf (Ljava/lang/String;)Lcases/enums/JavaEnum; public static fun values ()[Lcases/enums/JavaEnum; } - diff --git a/src/test/kotlin/cases/inline/inline.txt b/src/test/kotlin/cases/inline/inline.txt index 4a29e9b0..3f8aa1fb 100644 --- a/src/test/kotlin/cases/inline/inline.txt +++ b/src/test/kotlin/cases/inline/inline.txt @@ -9,4 +9,3 @@ public final class cases/inline/InternalClassExposed { public final fun getPropertyExposed ()Ljava/lang/String; public final fun setPropertyExposed (Ljava/lang/String;)V } - diff --git a/src/test/kotlin/cases/interfaces/interfaces.txt b/src/test/kotlin/cases/interfaces/interfaces.txt index 4f37b42f..d9352ac7 100644 --- a/src/test/kotlin/cases/interfaces/interfaces.txt +++ b/src/test/kotlin/cases/interfaces/interfaces.txt @@ -24,4 +24,3 @@ public final class cases/interfaces/DerivedWithoutImpl$DefaultImpls { public abstract interface class cases/interfaces/EmptyImpls { public abstract fun getProperty ()Ljava/lang/String; } - diff --git a/src/test/kotlin/cases/internal/internal.txt b/src/test/kotlin/cases/internal/internal.txt index d352937c..e39fb648 100644 --- a/src/test/kotlin/cases/internal/internal.txt +++ b/src/test/kotlin/cases/internal/internal.txt @@ -13,4 +13,3 @@ public final class cases/internal/PublicClassInternalCompanionWithNameShadowing public final class cases/internal/PublicClassNamedInternalCompanion { public fun ()V } - diff --git a/src/test/kotlin/cases/java/java.txt b/src/test/kotlin/cases/java/java.txt index 75bfd317..5276daa0 100644 --- a/src/test/kotlin/cases/java/java.txt +++ b/src/test/kotlin/cases/java/java.txt @@ -3,4 +3,3 @@ public class cases/java/Facade { public static fun publicMethod (I)V public static fun publicMethod (Ljava/lang/String;)V } - diff --git a/src/test/kotlin/cases/localClasses/localClasses.txt b/src/test/kotlin/cases/localClasses/localClasses.txt index da0d668c..49ac14a8 100644 --- a/src/test/kotlin/cases/localClasses/localClasses.txt +++ b/src/test/kotlin/cases/localClasses/localClasses.txt @@ -15,4 +15,3 @@ public final class cases/localClasses/L { public final class cases/localClasses/LambdasKt { public static final fun box ()V } - diff --git a/src/test/kotlin/cases/marker/marker.txt b/src/test/kotlin/cases/marker/marker.txt index 31054470..5a4125ea 100644 --- a/src/test/kotlin/cases/marker/marker.txt +++ b/src/test/kotlin/cases/marker/marker.txt @@ -10,4 +10,3 @@ public abstract interface annotation class cases/marker/HiddenMethod : java/lang public abstract interface annotation class cases/marker/HiddenProperty : java/lang/annotation/Annotation { } - diff --git a/src/test/kotlin/cases/nestedClasses/nestedClasses.txt b/src/test/kotlin/cases/nestedClasses/nestedClasses.txt index 4ba38c78..099e3e43 100644 --- a/src/test/kotlin/cases/nestedClasses/nestedClasses.txt +++ b/src/test/kotlin/cases/nestedClasses/nestedClasses.txt @@ -83,4 +83,3 @@ protected abstract interface class cases/nestedClasses/PublicOpenClass$NestedPro protected final class cases/nestedClasses/PublicOpenClass$ObjProtected { public static final field INSTANCE Lcases/nestedClasses/PublicOpenClass$ObjProtected; } - diff --git a/src/test/kotlin/cases/packageAnnotations/packageAnnotations.txt b/src/test/kotlin/cases/packageAnnotations/packageAnnotations.txt index d63454ac..1d6f5807 100644 --- a/src/test/kotlin/cases/packageAnnotations/packageAnnotations.txt +++ b/src/test/kotlin/cases/packageAnnotations/packageAnnotations.txt @@ -5,4 +5,3 @@ public final class cases/packageAnnotations/b/b/ShouldRemainPublic { public final class cases/packageAnnotations/b/c/ShouldNotBeRemoved { public fun ()V } - diff --git a/src/test/kotlin/cases/protected/protected.txt b/src/test/kotlin/cases/protected/protected.txt index 3c28d7e1..6335deca 100644 --- a/src/test/kotlin/cases/protected/protected.txt +++ b/src/test/kotlin/cases/protected/protected.txt @@ -16,4 +16,3 @@ public class cases/protected/PublicOpenClass { protected final fun protectedFun ()I protected final fun setProtectedVar (I)V } - diff --git a/src/test/kotlin/cases/public/public.txt b/src/test/kotlin/cases/public/public.txt index c9dd5dd2..f0182974 100644 --- a/src/test/kotlin/cases/public/public.txt +++ b/src/test/kotlin/cases/public/public.txt @@ -6,4 +6,3 @@ public final class cases/public/MultifileKt { public final class cases/public/PublicPartKt { public static final fun publicFun ()V } - diff --git a/src/test/kotlin/cases/special/special.txt b/src/test/kotlin/cases/special/special.txt index 242f2d57..789ce391 100644 --- a/src/test/kotlin/cases/special/special.txt +++ b/src/test/kotlin/cases/special/special.txt @@ -46,4 +46,3 @@ public final class cases/special/JvmNamesKt { public static final fun publicVarGetter ()I public static final fun publicVarSetter (I)V } - diff --git a/src/test/kotlin/cases/whenMappings/whenMappings.txt b/src/test/kotlin/cases/whenMappings/whenMappings.txt index ca17a5ef..31e67473 100644 --- a/src/test/kotlin/cases/whenMappings/whenMappings.txt +++ b/src/test/kotlin/cases/whenMappings/whenMappings.txt @@ -31,4 +31,3 @@ public final class cases/whenMappings/SealedClassWhenKt { public static final fun deacronimize (Lcases/whenMappings/SampleSealed;)Ljava/lang/String; public static final fun switch (Lcases/whenMappings/SampleSealed;Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function0;)V } - diff --git a/src/test/kotlin/tests/utils.kt b/src/test/kotlin/tests/utils.kt index 7dba24d0..183b3e16 100644 --- a/src/test/kotlin/tests/utils.kt +++ b/src/test/kotlin/tests/utils.kt @@ -18,14 +18,13 @@ fun List.dumpAndCompareWith(to: File) { to.bufferedWriter().use { dump(to = it) } fail("Expected data file did not exist. Generating: $to") } else { - val actual = dump(to = StringBuilder()) + val actual = dump(to = StringBuilder()).toString() assertEqualsToFile(to, actual) } } -private fun assertEqualsToFile(expectedFile: File, actual: CharSequence) { - val actualText = actual.trimTrailingWhitespacesAndAddNewlineAtEOF() - val expectedText = expectedFile.readText().trimTrailingWhitespacesAndAddNewlineAtEOF() +private fun assertEqualsToFile(expectedFile: File, actualText: String) { + val expectedText = expectedFile.readText() if (OVERWRITE_EXPECTED_OUTPUT && expectedText != actualText) { expectedFile.writeText(actualText) @@ -34,8 +33,3 @@ private fun assertEqualsToFile(expectedFile: File, actual: CharSequence) { assertEquals(expectedText, actualText, "Actual data differs from file content: ${expectedFile.name}\nTo overwrite the expected API rerun with -Doverwrite.output=true parameter\n") } - -private fun CharSequence.trimTrailingWhitespacesAndAddNewlineAtEOF(): String = - this.lineSequence().map { it.trimEnd() }.joinToString(separator = "\n").let { - if (it.endsWith("\n")) it else it + "\n" - }