Skip to content

Commit

Permalink
test: add a test for kotlin multiplatform
Browse files Browse the repository at this point in the history
  • Loading branch information
DanySK committed Jun 17, 2022
1 parent b0c6117 commit b7c2f2e
Show file tree
Hide file tree
Showing 10 changed files with 223 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
@file:Suppress("UnstableApiUsage")

import org.danilopianini.gradle.mavencentral.JavadocJar
import org.jetbrains.kotlin.gradle.plugin.KotlinTarget
import org.jetbrains.kotlin.util.capitalizeDecapitalize.toLowerCaseAsciiOnly

@Suppress("DSL_SCOPE_VIOLATION")
plugins {
alias(libs.plugins.kotlin.multiplatform)
alias(libs.plugins.dokka)
alias(libs.plugins.gitSemVer)
alias(libs.plugins.kotlin.qa)
alias(libs.plugins.multiJvmTesting)
alias(libs.plugins.taskTree)
id("org.danilopianini.publish-on-central")
}

group = "org.danilopianini"

repositories {
google()
mavenCentral()
}

kotlin {
jvm {
compilations.all {
kotlinOptions.jvmTarget = "1.8"
}
testRuns["test"].executionTask.configure {
useJUnitPlatform()
}
}
js(IR) {
browser()
nodejs()
binaries.library()
}
val hostOs = System.getProperty("os.name").trim().toLowerCaseAsciiOnly()
val hostArch = System.getProperty("os.arch").trim().toLowerCaseAsciiOnly()
val nativeTarget: (String, org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget.() -> Unit) -> KotlinTarget =
when (hostOs to hostArch) {
"linux" to "aarch64" -> ::linuxArm64
"linux" to "amd64" -> ::linuxX64
"linux" to "arm", "linux" to "arm32" -> ::linuxArm32Hfp
"linux" to "mips", "linux" to "mips32" -> ::linuxMips32
"linux" to "mipsel", "linux" to "mips32el" -> ::linuxMipsel32
"mac os x" to "aarch64" -> ::macosArm64
"mac os x" to "amd64", "mac os x" to "x86_64" -> ::macosX64
"windows" to "amd64", "windows server 2022" to "amd64" -> ::mingwX64
"windows" to "x86" -> ::mingwX86
else -> throw GradleException("Host OS '$hostOs' with arch '$hostArch' is not supported in Kotlin/Native.")
}
nativeTarget("native") {
binaries {
sharedLib()
staticLib()
// Remove if it is not executable
"main".let { executable ->
executable {
entryPoint = executable
}
// Enable wasm32
wasm32 {
binaries {
executable {
entryPoint = executable
}
}
}
}
}
}
sourceSets {
val commonMain by getting {
dependencies {
implementation(libs.kotlin.stdlib)
}
}
val commonTest by getting {
dependencies {
implementation(libs.bundles.kotlin.testing.common)
}
}
val jvmTest by getting {
dependencies {
implementation(libs.bundles.kotlin.testing.jvm)
}
}
val nativeMain by getting {
dependsOn(commonMain)
}
val nativeTest by getting {
dependsOn(commonTest)
}
}
targets.all {
compilations.all {
kotlinOptions {
allWarningsAsErrors = true
}
}
}
}

tasks.dokkaJavadoc {
enabled = false
}

tasks.withType<JavadocJar>().configureEach {
val dokka = tasks.dokkaHtml.get()
dependsOn(dokka)
from(dokka.outputDirectory)
}

signing {
if (System.getenv("CI") == "true") {
val signingKey: String? by project
val signingPassword: String? by project
useInMemoryPgpKeys(signingKey, signingPassword)
}
}

publishOnCentral {
projectLongName.set("Template for Kotlin Multiplatform Project")
projectDescription.set("A template repository for Kotlin Multiplatform projects")
repository("https://maven.pkg.github.com/danysk/${rootProject.name}".toLowerCase()) {
user.set("DanySK")
password.set(System.getenv("GITHUB_TOKEN"))
}
publishing {
publications {
withType<MavenPublication> {
pom {
developers {
developer {
name.set("Danilo Pianini")
email.set("[email protected]")
url.set("http://www.danilopianini.org/")
}
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[versions]
android-plugins = "7.0.0"
kotest = "5.3.1"
kotlin = "1.7.0"

[libraries]
kotest-assertions-core = { module = "io.kotest:kotest-assertions-core", version.ref = "kotest" }
kotest-assertions-core-jvm = { module = "io.kotest:kotest-assertions-core-jvm", version.ref = "kotest" }
kotest-framework-engine = { module = "io.kotest:kotest-framework-engine", version.ref = "kotest" }
kotest-framework-datatest = { module = "io.kotest:kotest-framework-datatest", version.ref = "kotest" }
kotest-runner-junit5-jvm = { module = "io.kotest:kotest-runner-junit5-jvm", version.ref = "kotest" }
kotlin-reflect = { module = "org.jetbrains.kotlin:kotlin-stdlib-reflect", version.ref = "kotlin" }
kotlin-stdlib = { module = "org.jetbrains.kotlin:kotlin-stdlib", version.ref = "kotlin" }
kotlin-stdlib-jdk8 = { module = "org.jetbrains.kotlin:kotlin-stdlib-jdk8", version.ref = "kotlin" }
kotlin-test-common = { module = "org.jetbrains.kotlin:kotlin-test-common", version.ref = "kotlin" }
kotlin-test-annotations-common = { module = "org.jetbrains.kotlin:kotlin-test-annotations-common", version.ref = "kotlin" }


[bundles]
kotlin-testing-common = [
"kotest-assertions-core",
"kotest-framework-engine",
"kotest-framework-datatest",
"kotlin-test-common",
"kotlin-test-annotations-common",
]
kotlin-testing-jvm = [ "kotest-assertions-core-jvm", "kotest-runner-junit5-jvm" ]

[plugins]
dokka = "org.jetbrains.dokka:1.6.21"
gitSemVer = { id = "org.danilopianini.git-sensitive-semantic-versioning", version = "0.3.0" }
kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
kotlin-qa = "org.danilopianini.gradle-kotlin-qa:0.19.1"
multiJvmTesting = "org.danilopianini.multi-jvm-test-plugin:0.4.3"
npm-publish = "dev.petuska.npm.publish:3.0.0"
taskTree = "com.dorongold.task-tree:2.1.0"
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fun main() {
println("Hello, ${Platform.name}!")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
expect object Platform {
val name: String
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import io.kotest.core.spec.style.StringSpec
import io.kotest.matchers.shouldNotBe

class Test : StringSpec(
{
"a simple test" {
true shouldNotBe false
}
}
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
actual object Platform {
actual val name = "JS"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
actual object Platform {
actual val name = "JVM"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
actual object Platform {
actual val name = "Native"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
actual object Platform {
actual val name = "WASM"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
tests:
- description: "gradle should generate metadata files in kotlin-multiplatform projects"
configuration:
tasks: &tasks
- 'generateMetadataFileForJavaMavenPublication'
- 'generateMetadataFileForJvmPublication'
- 'generateMetadataFileForKotlinMavenPublication'
- 'generateMetadataFileForKotlinMultiplatformPublication'
- 'generateMetadataFileForNativePublication'
- 'generateMetadataFileForWasm32Publication'
expectation:
success: *tasks

0 comments on commit b7c2f2e

Please sign in to comment.