Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add iOS targets to test module and bump dependencies #61

Merged
merged 8 commits into from
Jun 22, 2021
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
42 changes: 29 additions & 13 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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<Test>().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<JacocoPluginExtension> {
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 <T> Project.whenEvaluated(action: Project.() -> T) {
if (state.executed) {
action()
} else {
afterEvaluate { action() }
}
}
2 changes: 1 addition & 1 deletion buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ plugins {
}

repositories {
jcenter()
mavenCentral()
}
4 changes: 2 additions & 2 deletions buildSrc/src/main/kotlin/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

Expand Down
4 changes: 4 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -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

Expand Down
15 changes: 3 additions & 12 deletions logging/src/jvmMain/kotlin/StackTraceTagGenerator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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("$")
}
15 changes: 10 additions & 5 deletions logging/src/jvmTest/kotlin/StackTraceTagGeneratorTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,19 @@ class StackTraceTagGeneratorTests {
fun tagStripsAnonymousClassNumber() {
val supplier = Supplier<String> { 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
Expand Down
6 changes: 3 additions & 3 deletions test/api/test.api
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
18 changes: 18 additions & 0 deletions test/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ kotlin {
jvm()
js().browser()
macosX64()
iosX64()
iosArm64()

sourceSets {
val commonMain by getting {
Expand All @@ -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)
}
}
}