From d777238d51c767f4e8bacb5b37c7d6b60043176c Mon Sep 17 00:00:00 2001 From: Oleksandr Karpovich Date: Mon, 23 Oct 2023 12:02:27 +0200 Subject: [PATCH] Add more tests for expect Composables (#3851) --- .../composable-test-cases/gradle.properties | 12 ++++++----- .../composable-test-cases/settings.gradle.kts | 2 +- .../lib/src/commonMain/kotlin/Dependencies.kt | 12 ++++++++++- .../main/src/commonTest/kotlin/Tests.kt | 20 +++++++++++++++++++ .../rememberAnonymousObj/lib/build.gradle.kts | 20 +------------------ .../main/build.gradle.kts | 20 +------------------ 6 files changed, 41 insertions(+), 45 deletions(-) diff --git a/compose/integrations/composable-test-cases/gradle.properties b/compose/integrations/composable-test-cases/gradle.properties index caaa0b5ecc..f563fbc462 100644 --- a/compose/integrations/composable-test-cases/gradle.properties +++ b/compose/integrations/composable-test-cases/gradle.properties @@ -1,15 +1,17 @@ org.gradle.jvmargs=-Xmx2048M -XX:MaxMetaspaceSize=512m kotlin.code.style=official -kotlin.native.enableDependencyPropagation=false android.useAndroidX=true -kotlin.version=1.9.10 +kotlin.version=1.9.20-RC agp.version=7.3.0 -compose.version=1.5.1 +compose.version=1.5.10-rc01 #empty by default - a default version will be used -compose.kotlinCompilerPluginVersion=1.5.2 +compose.kotlinCompilerPluginVersion=1.5.2.1-rc01 # default|failingJs - see enum class CasesToRun tests.casesToRun=default # comma separated names of test cases known to fail (either compilation or while running) with k/js. -tests.failing.kjs=rememberAnonymousObj +#tests.failing.kjs=rememberAnonymousObj + +# TODO: we should test with both K2 and K1 +#kotlin.experimental.tryK2=true \ No newline at end of file diff --git a/compose/integrations/composable-test-cases/settings.gradle.kts b/compose/integrations/composable-test-cases/settings.gradle.kts index 83bcc66de6..3e53198c5c 100644 --- a/compose/integrations/composable-test-cases/settings.gradle.kts +++ b/compose/integrations/composable-test-cases/settings.gradle.kts @@ -38,7 +38,7 @@ val casesToRun = CasesToRun.values().firstOrNull { } ?: CasesToRun.Default -val listOfFailingJsCases = (extra["tests.failing.kjs"] as String).split(",") +val listOfFailingJsCases = (extra.properties.getOrDefault("tests.failing.kjs", "") as String).split(",") val failingJsSuffix = "failingJs" fun getFailingSuffix(testCaseName: String): String? { diff --git a/compose/integrations/composable-test-cases/testcases/expectActual/lib/src/commonMain/kotlin/Dependencies.kt b/compose/integrations/composable-test-cases/testcases/expectActual/lib/src/commonMain/kotlin/Dependencies.kt index edb625e065..0d030f43b1 100644 --- a/compose/integrations/composable-test-cases/testcases/expectActual/lib/src/commonMain/kotlin/Dependencies.kt +++ b/compose/integrations/composable-test-cases/testcases/expectActual/lib/src/commonMain/kotlin/Dependencies.kt @@ -7,4 +7,14 @@ val Abc.commonIntVal: Int @Composable get() = 1000 expect val Abc.composableIntVal: Int - @Composable get \ No newline at end of file + @Composable get + +@Composable +fun GetIntVal(): Int { + return Abc().composableIntVal +} + +@Composable +fun GetIntValWithDefault(def: Int = Abc().composableIntVal): Int { + return def +} \ No newline at end of file diff --git a/compose/integrations/composable-test-cases/testcases/expectActual/main/src/commonTest/kotlin/Tests.kt b/compose/integrations/composable-test-cases/testcases/expectActual/main/src/commonTest/kotlin/Tests.kt index ec41e67c5b..46ceb31220 100644 --- a/compose/integrations/composable-test-cases/testcases/expectActual/main/src/commonTest/kotlin/Tests.kt +++ b/compose/integrations/composable-test-cases/testcases/expectActual/main/src/commonTest/kotlin/Tests.kt @@ -19,6 +19,26 @@ class Tests { assertEquals("root:{100}", root.dump()) } + @Test + fun composableImplicitExpectActualValGetter() = runTest { + val root = composeText { + val v = GetIntVal() + TextLeafNode("$v") + } + + assertEquals("root:{100}", root.dump()) + } + + @Test + fun composableImplicitExpectActualValGetterWithDefault() = runTest { + val root = composeText { + val v = GetIntValWithDefault() + TextLeafNode("$v") + } + + assertEquals("root:{100}", root.dump()) + } + @Test fun commonComposableValGetter() = runTest { val root = composeText { diff --git a/compose/integrations/composable-test-cases/testcases/rememberAnonymousObj/lib/build.gradle.kts b/compose/integrations/composable-test-cases/testcases/rememberAnonymousObj/lib/build.gradle.kts index 571458a007..b96e439ee7 100644 --- a/compose/integrations/composable-test-cases/testcases/rememberAnonymousObj/lib/build.gradle.kts +++ b/compose/integrations/composable-test-cases/testcases/rememberAnonymousObj/lib/build.gradle.kts @@ -3,26 +3,8 @@ plugins { id("org.jetbrains.compose") } -@OptIn(org.jetbrains.kotlin.gradle.kpm.external.ExternalVariantApi::class) -fun org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension.configureDefaultTargets() { - jvm("desktop") - ios() - iosArm64() - iosSimulatorArm64() - iosX64() - macosX64() - macosArm64() - // We use linux agents on CI. So it doesn't run the tests, but it builds the klib anyway which is time consuming. - if (project.isInIdea) mingwX64() - linuxX64() -} - kotlin { - if (project.isFailingJsCase) { - configureJsTargets() - } else { - configureDefaultTargets() - } + configureTargets() sourceSets { val commonMain by getting { diff --git a/compose/integrations/composable-test-cases/testcases/rememberAnonymousObj/main/build.gradle.kts b/compose/integrations/composable-test-cases/testcases/rememberAnonymousObj/main/build.gradle.kts index e04c9d85c4..d49878c7d2 100644 --- a/compose/integrations/composable-test-cases/testcases/rememberAnonymousObj/main/build.gradle.kts +++ b/compose/integrations/composable-test-cases/testcases/rememberAnonymousObj/main/build.gradle.kts @@ -3,26 +3,8 @@ plugins { id("org.jetbrains.compose") } -@OptIn(org.jetbrains.kotlin.gradle.kpm.external.ExternalVariantApi::class) -fun org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension.configureDefaultTargets() { - jvm("desktop") - ios() - iosArm64() - iosSimulatorArm64() - iosX64() - macosX64() - macosArm64() - // We use linux agents on CI. So it doesn't run the tests, but it builds the klib anyway which is time consuming. - if (project.isInIdea) mingwX64() - linuxX64() -} - kotlin { - if (project.isFailingJsCase) { - configureJsTargets() - } else { - configureDefaultTargets() - } + configureTargets() sourceSets { val commonMain by getting {