Skip to content

Commit

Permalink
Setup Kover for validation of each module
Browse files Browse the repository at this point in the history
Also, slightly increased coverage

Resolves #2634
  • Loading branch information
shanshin committed May 15, 2024
1 parent 194a188 commit 80eafa1
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 29 deletions.
52 changes: 48 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ plugins {
id("org.jetbrains.kotlinx.binary-compatibility-validator")
id("org.jetbrains.dokka")
id("benchmark-conventions")
id("org.jetbrains.kotlinx.kover")

alias(libs.plugins.serialization) apply false
}
Expand Down Expand Up @@ -55,6 +56,7 @@ allprojects {
}
repositories {
mavenCentral()
maven("https://oss.sonatype.org/content/repositories/orgjetbrainskotlinx-3303")
}
}

Expand Down Expand Up @@ -125,9 +127,50 @@ subprojects {
}

// == Kover setup ==
subprojects {
if (uncoveredProjects.contains(project.name)) return@subprojects
apply(plugin = "kover-conventions")
kover {
if (hasProperty("kover.enabled") && property("kover.enabled") != "true") {
disable()
}

currentProject {
projectsForCoverageVerification.forEach { (variantName, _) ->
copyVariant(variantName, "main")
}
}

merge {
subprojects { subproject ->
subproject.path !in uncoveredProjects
}

createVariant("main") { add("jvm", optional = true) }
}

reports {
total {
verify {
rule("Total coverage") {
minBound(90)
}
}
}

projectsForCoverageVerification.forEach { (variantName, projectPath) ->
variant(variantName) {
filters {
includes {
projects.add(projectPath)
}
}
verify {
onCheck = true
rule("Coverage for $projectPath") {
minBound(85)
}
}
}
}
}
}

// == Dokka setup ==
Expand Down Expand Up @@ -188,4 +231,5 @@ val documentedSubprojects get() = setOf("kotlinx-serialization-core",
"kotlinx-serialization-hocon",
"kotlinx-serialization-protobuf")

val uncoveredProjects get() = setOf("kotlinx-serialization-bom", "benchmark", "guide", "kotlinx-serialization-json-okio")
val uncoveredProjects get() = setOf(":kotlinx-serialization-bom", ":benchmark", ":guide")
val projectsForCoverageVerification get() = mapOf("core" to ":kotlinx-serialization-core", "json" to ":kotlinx-serialization-json", "jsonOkio" to ":kotlinx-serialization-json-okio", "cbor" to ":kotlinx-serialization-cbor", "hocon" to ":kotlinx-serialization-hocon", "properties" to ":kotlinx-serialization-properties", "protobuf" to ":kotlinx-serialization-protobuf")
2 changes: 2 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ repositories {

mavenCentral()
mavenLocal()

maven("https://oss.sonatype.org/content/repositories/orgjetbrainskotlinx-3303")
}

dependencies {
Expand Down
24 changes: 0 additions & 24 deletions buildSrc/src/main/kotlin/kover-conventions.gradle.kts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright 2017-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/

package kotlinx.serialization.json.okio.internal

import okio.*
import kotlin.test.*

class OkioSerialReaderTests {

@Test
fun testSurrogate() {
val text = "\uD83D\uDE03"
val originalChars = text.toCharArray()

val buffer = Buffer()
buffer.writeUtf8(text)
val reader = OkioSerialReader(buffer)

val readArray = CharArray(2)
assertEquals(1, reader.read(readArray, 0, 1) )
assertEquals(1, reader.read(readArray, 1, 1) )

assertContentEquals(originalChars, readArray)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package kotlinx.serialization.properties

import kotlinx.serialization.*
import kotlinx.serialization.builtins.*
import kotlinx.serialization.modules.*
import kotlin.test.*

class PropertiesTest {
Expand Down Expand Up @@ -107,6 +108,12 @@ class PropertiesTest {
assertEquals(emptyMap(), Properties.encodeToMap(Unit.serializer(), Unit))
}

@Test
fun testUnitIsEmptyMapModule() {
val module = SerializersModule {}
assertEquals(emptyMap(), Properties(module).encodeToMap(Unit.serializer(), Unit))
}

@Test
fun testList() {
val data = Data(listOf("element1"), "property")
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[versions]
kotlin = "1.9.22"
kover = "0.8.0-Beta2"
kover = "0.8.0-Serialization"
dokka = "1.9.20"
knit = "0.5.0"
bcv = "0.15.0-Beta.2"
Expand Down
2 changes: 2 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ pluginManagement {
gradlePluginPortal()
mavenCentral()
mavenLocal()

maven("https://oss.sonatype.org/content/repositories/orgjetbrainskotlinx-3302")
}
}

Expand Down

0 comments on commit 80eafa1

Please sign in to comment.