From e71021d596622b4d16cbb00b14b911e6dfadcf88 Mon Sep 17 00:00:00 2001 From: Travis Wyatt Date: Tue, 22 Jun 2021 13:37:19 -0700 Subject: [PATCH] Add iOS targets to `test` module and bump dependencies (#61) --- README.md | 1 + build.gradle.kts | 42 +++++++++++++------ buildSrc/build.gradle.kts | 2 +- buildSrc/src/main/kotlin/Dependencies.kt | 4 +- gradle.properties | 4 ++ .../jvmMain/kotlin/StackTraceTagGenerator.kt | 15 ++----- .../kotlin/StackTraceTagGeneratorTests.kt | 15 ++++--- test/api/test.api | 6 +-- test/build.gradle.kts | 18 ++++++++ .../kotlin/runTest.kt | 0 10 files changed, 71 insertions(+), 36 deletions(-) rename test/src/{macosX64Main => appleMain}/kotlin/runTest.kt (100%) diff --git a/README.md b/README.md index 7c8a944a..d6f4e28c 100644 --- a/README.md +++ b/README.md @@ -96,6 +96,7 @@ _Note: Because this is built on top of [KotlinX DateTime], [core library desugar ## [Test](https://juullabs.github.io/tuulbox/test/index.html) +![badge-ios] ![badge-js] ![badge-jvm] ![badge-mac] diff --git a/build.gradle.kts b/build.gradle.kts index 5d260ee0..6da04191 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,41 +1,57 @@ -import org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL - buildscript { repositories { google() - jcenter() + mavenCentral() } } plugins { - kotlin("multiplatform") version "1.4.31" apply false - id("com.android.library") version "4.0.2" apply false - id("kotlinx-atomicfu") version "0.15.1" apply false - id("org.jmailen.kotlinter") version "3.2.0" apply false + kotlin("multiplatform") version "1.5.10" apply false + id("com.android.library") version "4.1.3" apply false + id("kotlinx-atomicfu") version "0.16.1" apply false + id("org.jmailen.kotlinter") version "3.4.4" apply false id("binary-compatibility-validator") version "0.2.3" - id("org.jetbrains.dokka") version "1.4.30" - id("com.vanniktech.maven.publish") version "0.14.2" apply false - id("net.mbonnin.one.eight") version "0.1" + id("org.jetbrains.dokka") version "1.4.32" + id("com.vanniktech.maven.publish") version "0.15.1" apply false + id("net.mbonnin.one.eight") version "0.2" } allprojects { repositories { google() - jcenter() - maven("https://kotlin.bintray.com/kotlinx/") + mavenCentral() } tasks.withType().configureEach { testLogging { events("started", "passed", "skipped", "failed", "standardOut", "standardError") - exceptionFormat = FULL + exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL showExceptions = true showStackTraces = true showCauses = true } } + + withPluginWhenEvaluated("jacoco") { + configure { + toolVersion = "0.8.7" + } + } } tasks.dokkaHtmlMultiModule.configure { outputDirectory.set(buildDir.resolve("gh-pages")) } + +fun Project.withPluginWhenEvaluated(plugin: String, action: Project.() -> Unit) { + pluginManager.withPlugin(plugin) { whenEvaluated(action) } +} + +// `afterEvaluate` does nothing when the project is already in executed state, so we need a special check for this case. +fun Project.whenEvaluated(action: Project.() -> T) { + if (state.executed) { + action() + } else { + afterEvaluate { action() } + } +} diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 3d7a9541..876c922b 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -3,5 +3,5 @@ plugins { } repositories { - jcenter() + mavenCentral() } diff --git a/buildSrc/src/main/kotlin/Dependencies.kt b/buildSrc/src/main/kotlin/Dependencies.kt index bb24573f..5abc8f89 100644 --- a/buildSrc/src/main/kotlin/Dependencies.kt +++ b/buildSrc/src/main/kotlin/Dependencies.kt @@ -2,11 +2,11 @@ object kotlinx { fun coroutines( module: String = "core", - version: String = "1.4.0" + version: String = "1.5.0" ) = "org.jetbrains.kotlinx:kotlinx-coroutines-$module:$version" fun datetime( - version: String = "0.1.1" + version: String = "0.2.1" ) = "org.jetbrains.kotlinx:kotlinx-datetime:$version" } diff --git a/gradle.properties b/gradle.properties index 9c3e1c94..d62b6497 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,9 @@ org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m +kotlin.mpp.enableGranularSourceSetsMetadata=true +kotlin.mpp.enableCompatibilityMetadataVariant=true +kotlin.native.enableDependencyPropagation=false + # Android Configuration android.useAndroidX=true diff --git a/logging/src/jvmMain/kotlin/StackTraceTagGenerator.kt b/logging/src/jvmMain/kotlin/StackTraceTagGenerator.kt index b6b8cdf0..4d6f2789 100644 --- a/logging/src/jvmMain/kotlin/StackTraceTagGenerator.kt +++ b/logging/src/jvmMain/kotlin/StackTraceTagGenerator.kt @@ -3,23 +3,14 @@ package com.juul.tuulbox.logging internal actual val defaultTagGenerator: TagGenerator = StackTraceTagGenerator internal object StackTraceTagGenerator : TagGenerator, HideFromStackTraceTag { - private val anonymousClassPattern = Regex("""(\$\d+)$""").toPattern() private val ignoreSubclassesOf = HideFromStackTraceTag::class.java - override fun getTag(): String { - val tagCandidate = Throwable().stackTrace.asSequence() + override fun getTag() = + Throwable().stackTrace.asSequence() .map { Class.forName(it.className) } .first { !ignoreSubclassesOf.isAssignableFrom(it) } .name .substringAfterLast('.') - // This bit of logic is stolen from Timber, so use of Java's Pattern/Matcher - // instead of Kotlin's Regex is to guarantee exact behavior match. - val matcher = anonymousClassPattern.matcher(tagCandidate) - return if (matcher.find()) { - matcher.replaceAll("") - } else { - tagCandidate - } - } + .substringBefore("$") } diff --git a/logging/src/jvmTest/kotlin/StackTraceTagGeneratorTests.kt b/logging/src/jvmTest/kotlin/StackTraceTagGeneratorTests.kt index 005c17d6..ad515c3e 100644 --- a/logging/src/jvmTest/kotlin/StackTraceTagGeneratorTests.kt +++ b/logging/src/jvmTest/kotlin/StackTraceTagGeneratorTests.kt @@ -17,14 +17,19 @@ class StackTraceTagGeneratorTests { fun tagStripsAnonymousClassNumber() { val supplier = Supplier { StackTraceTagGenerator.getTag() } + /* Examples of `class.java.name`: + * + * | Kotlin | supplier::class.java.name | + * |--------|-----------------------------------------------------------------------------------------------| + * | 1.4.31 | com.juul.tuulbox.logging.StackTraceTagGeneratorTests$tagStripsAnonymousClassNumber$supplier$1 | + * | 1.5.10 | com.juul.tuulbox.logging.StackTraceTagGeneratorTests$$Lambda$4/1813123723 | + */ + // Double check that the way we've written this actually generates // an anonymous class, instead of being optimized by the compiler. - assertTrue(supplier::class.java.name.endsWith("$1")) + assertTrue(supplier::class.java.name.contains("\$")) - val expected = supplier::class.java.name - .substringAfterLast('.') - .substringBefore("$1") - assertEquals(expected, supplier.get()) + assertEquals("StackTraceTagGeneratorTests", supplier.get()) } @Test diff --git a/test/api/test.api b/test/api/test.api index c75789fd..40e394df 100644 --- a/test/api/test.api +++ b/test/api/test.api @@ -8,9 +8,9 @@ public final class com/juul/tuulbox/test/AssertKt { public static final fun assertSimilar (FFF)V public static final fun assertSimilar (III)V public static final fun assertSimilar (JJJ)V - public static final fun assertSimilar-8Mi8wO0 (Lkotlinx/datetime/Instant;DLkotlinx/datetime/Instant;)V - public static final fun assertSimilar-dWUq8MI (Lkotlinx/datetime/LocalDateTime;DLkotlinx/datetime/LocalDateTime;Lkotlinx/datetime/TimeZone;)V - public static synthetic fun assertSimilar-dWUq8MI$default (Lkotlinx/datetime/LocalDateTime;DLkotlinx/datetime/LocalDateTime;Lkotlinx/datetime/TimeZone;ILjava/lang/Object;)V + public static final fun assertSimilar-8Mi8wO0 (Lkotlinx/datetime/Instant;JLkotlinx/datetime/Instant;)V + public static final fun assertSimilar-dWUq8MI (Lkotlinx/datetime/LocalDateTime;JLkotlinx/datetime/LocalDateTime;Lkotlinx/datetime/TimeZone;)V + public static synthetic fun assertSimilar-dWUq8MI$default (Lkotlinx/datetime/LocalDateTime;JLkotlinx/datetime/LocalDateTime;Lkotlinx/datetime/TimeZone;ILjava/lang/Object;)V } public final class com/juul/tuulbox/test/RunTestKt { diff --git a/test/build.gradle.kts b/test/build.gradle.kts index 4e83d0fb..d2a51816 100644 --- a/test/build.gradle.kts +++ b/test/build.gradle.kts @@ -11,6 +11,8 @@ kotlin { jvm() js().browser() macosX64() + iosX64() + iosArm64() sourceSets { val commonMain by getting { @@ -32,5 +34,21 @@ kotlin { implementation(kotlin("test-js")) } } + + val appleMain by creating { + dependsOn(commonMain) + } + + val macosX64Main by getting { + dependsOn(appleMain) + } + + val iosX64Main by getting { + dependsOn(appleMain) + } + + val iosArm64Main by getting { + dependsOn(appleMain) + } } } diff --git a/test/src/macosX64Main/kotlin/runTest.kt b/test/src/appleMain/kotlin/runTest.kt similarity index 100% rename from test/src/macosX64Main/kotlin/runTest.kt rename to test/src/appleMain/kotlin/runTest.kt