From f0407e5ed9413add3718eb656df6adaeb1773a75 Mon Sep 17 00:00:00 2001 From: Brian Norman Date: Mon, 2 Mar 2020 12:40:18 -0600 Subject: [PATCH] Update sample to be a multiplatform project --- sample/build.gradle.kts | 77 ++++++++++++++++--- .../kotlin/com/bnorm/power/Person.kt | 26 +++++++ .../kotlin/com/bnorm/power/PowerAssertTest.kt | 16 +--- .../com/bnorm/power/JvmPowerAssertTest.kt | 26 +++++++ 4 files changed, 122 insertions(+), 23 deletions(-) create mode 100644 sample/src/commonMain/kotlin/com/bnorm/power/Person.kt rename sample/src/{test => commonTest}/kotlin/com/bnorm/power/PowerAssertTest.kt (74%) create mode 100644 sample/src/jvmTest/kotlin/com/bnorm/power/JvmPowerAssertTest.kt diff --git a/sample/build.gradle.kts b/sample/build.gradle.kts index c43489b1192..e4686d7fe6b 100644 --- a/sample/build.gradle.kts +++ b/sample/build.gradle.kts @@ -1,11 +1,11 @@ buildscript { dependencies { - classpath("gradle.plugin.com.bnorm.power:kotlin-power-assert-gradle:0.2.0") + classpath("gradle.plugin.com.bnorm.power:kotlin-power-assert-gradle:0.3.0") } } plugins { - kotlin("jvm") version "1.3.70" + kotlin("multiplatform") version "1.3.70" } apply(plugin = "com.bnorm.power.kotlin-power-assert") @@ -13,14 +13,73 @@ repositories { mavenCentral() } -dependencies { - implementation(kotlin("stdlib-jdk8")) - testImplementation(kotlin("test-junit")) -} -tasks.compileTestKotlin { - kotlinOptions.jvmTarget = "1.8" - kotlinOptions.useIR = true +kotlin { + jvm { + compilations.all { + kotlinOptions { + kotlinOptions.jvmTarget = "1.8" + kotlinOptions.useIR = true + } + } + } + js { + browser() + nodejs() + + compilations.all { + kotlinOptions { + kotlinOptions.freeCompilerArgs += listOf("-Xir-produce-klib-dir", "-Xir-produce-js") + } + } + } + + val osName = System.getProperty("os.name") + when { + "Windows" in osName -> mingwX64("native") + "Mac OS" in osName -> macosX64("native") + else -> linuxX64("native") + } + + sourceSets { + val commonMain by getting { + dependencies { + implementation(kotlin("stdlib")) + } + } + val commonTest by getting { + dependencies { + implementation(kotlin("test-common")) + implementation(kotlin("test-annotations-common")) + } + } + val jvmMain by getting { + dependencies { + implementation(kotlin("stdlib-jdk8")) + } + } + val jvmTest by getting { + dependencies { + implementation(kotlin("test-junit")) + } + } + val jsMain by getting { + dependencies { + implementation(kotlin("stdlib-js")) + } + } + val jsTest by getting { + dependencies { + implementation(kotlin("test-js")) + } + } + val nativeMain by getting { + dependsOn(commonMain) + } + val nativeTest by getting { + dependsOn(commonTest) + } + } } configure { diff --git a/sample/src/commonMain/kotlin/com/bnorm/power/Person.kt b/sample/src/commonMain/kotlin/com/bnorm/power/Person.kt new file mode 100644 index 00000000000..09d10c4f0e0 --- /dev/null +++ b/sample/src/commonMain/kotlin/com/bnorm/power/Person.kt @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2020 Brian Norman + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.bnorm.power + +data class Person( + val firstName: String, + val lastName: String +) { + companion object { + val UNKNOWN = listOf(Person("John", "Doe"), Person("Jane", "Doe")) + } +} diff --git a/sample/src/test/kotlin/com/bnorm/power/PowerAssertTest.kt b/sample/src/commonTest/kotlin/com/bnorm/power/PowerAssertTest.kt similarity index 74% rename from sample/src/test/kotlin/com/bnorm/power/PowerAssertTest.kt rename to sample/src/commonTest/kotlin/com/bnorm/power/PowerAssertTest.kt index 2c3a5765104..5db665d2628 100644 --- a/sample/src/test/kotlin/com/bnorm/power/PowerAssertTest.kt +++ b/sample/src/commonTest/kotlin/com/bnorm/power/PowerAssertTest.kt @@ -19,26 +19,14 @@ package com.bnorm.power import kotlin.test.Test import kotlin.test.assertTrue -data class Person( - val firstName: String, - val lastName: String -) - class PowerAssertTest { - private val people = listOf(Person("John", "Doe"), Person("Jane", "Doe")) - @Test fun assertTrue() { - assertTrue(people.size == 1) - } - - @Test - fun assert() { - assert(people.size == 1) + assertTrue(Person.UNKNOWN.size == 1) } @Test fun require() { - require(people.size == 1) + require(Person.UNKNOWN.size == 1) } } diff --git a/sample/src/jvmTest/kotlin/com/bnorm/power/JvmPowerAssertTest.kt b/sample/src/jvmTest/kotlin/com/bnorm/power/JvmPowerAssertTest.kt new file mode 100644 index 00000000000..233d3de951a --- /dev/null +++ b/sample/src/jvmTest/kotlin/com/bnorm/power/JvmPowerAssertTest.kt @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2020 Brian Norman + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.bnorm.power + +import kotlin.test.Test + +class JvmPowerAssertTest { + @Test + fun assert() { + assert(Person.UNKNOWN.size == 1) + } +}