From 4e673239a7cf88bd53d245af955dd045df91bd45 Mon Sep 17 00:00:00 2001 From: Alexey Tsvetkov Date: Fri, 19 Mar 2021 07:22:10 +0300 Subject: [PATCH] Split integration and unit Gradle plugin tests Previously some tests (e.g. FileHashTest) were executed multiple times in each test task. This change splits tests in the following way: * `testGradle-` task only runs `org.jetbrains.compose.gradle.*` tests with the corresponding Gradle version; * `test` runs all other tests once; * `check` runs all tests and checks; --- gradle-plugins/compose/build.gradle.kts | 34 ++++++++++++------- .../{ => gradle}/DesktopApplicationTest.kt | 2 +- .../compose/{ => gradle}/GradlePluginTest.kt | 2 +- 3 files changed, 23 insertions(+), 15 deletions(-) rename gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/{ => gradle}/DesktopApplicationTest.kt (99%) rename gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/{ => gradle}/GradlePluginTest.kt (95%) diff --git a/gradle-plugins/compose/build.gradle.kts b/gradle-plugins/compose/build.gradle.kts index 6632036c84..3359ceeac3 100644 --- a/gradle-plugins/compose/build.gradle.kts +++ b/gradle-plugins/compose/build.gradle.kts @@ -59,8 +59,9 @@ val jar = tasks.named("jar") { } // __SUPPORTED_GRADLE_VERSIONS__ -val minGradleVersionForTests = "6.4" -val maxGradleVersionForTests = "6.8.3" +testGradleVersion("6.4") +testGradleVersion("6.8.3") + val javaHomeForTests: String? = when { // __COMPOSE_NATIVE_DISTRIBUTIONS_MIN_JAVA_VERSION__ JavaVersion.current() >= JavaVersion.VERSION_15 -> System.getProperty("java.home") @@ -69,18 +70,29 @@ val javaHomeForTests: String? = when { } val isWindows = getCurrentOperatingSystem().isWindows +val gradleTestsPattern = "org.jetbrains.compose.gradle.*" tasks.test { - configureTest(maxGradleVersionForTests) + filter { + excludeTestsMatching(gradleTestsPattern) + } } - -val testMinGradleVersion by tasks.registering(Test::class) { - tasks.test.get().let { defaultTest -> - classpath = defaultTest.classpath +fun testGradleVersion(gradleVersion: String) { + val taskProvider = tasks.register("testGradle-$gradleVersion", Test::class) { + tasks.test.get().let { defaultTest -> + classpath = defaultTest.classpath + } + systemProperty("gradle.version.for.tests", gradleVersion) + filter { + includeTestsMatching(gradleTestsPattern) + } + dependsOn("validateTaskProperties") + } + tasks.named("check") { + dependsOn(taskProvider) } - configureTest(minGradleVersionForTests) } -fun Test.configureTest(gradleVersion: String) { +tasks.withType().configureEach { useJUnitPlatform() testLogging { events("passed", "skipped", "failed") @@ -88,7 +100,6 @@ fun Test.configureTest(gradleVersion: String) { dependsOn("publishToMavenLocal") systemProperty("compose.plugin.version", BuildProperties.deployVersion(project)) - systemProperty("gradle.version.for.tests", gradleVersion) if (javaHomeForTests != null) { val executableFileName = if (isWindows) "java.exe" else "java" @@ -96,10 +107,7 @@ fun Test.configureTest(gradleVersion: String) { } else { doFirst { error("Use JDK 15+ to run tests or set up JDK_15/JDK_FOR_GRADLE_TESTS env. var") } } -} -tasks.named("check") { - dependsOn(testMinGradleVersion) } task("printAllAndroidxReplacements") { diff --git a/gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/DesktopApplicationTest.kt b/gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/gradle/DesktopApplicationTest.kt similarity index 99% rename from gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/DesktopApplicationTest.kt rename to gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/gradle/DesktopApplicationTest.kt index 1a9720fcb1..5aa1ee97c9 100644 --- a/gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/DesktopApplicationTest.kt +++ b/gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/gradle/DesktopApplicationTest.kt @@ -1,4 +1,4 @@ -package org.jetbrains.compose +package org.jetbrains.compose.gradle import org.gradle.internal.impldep.org.testng.Assert import org.gradle.testkit.runner.TaskOutcome diff --git a/gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/GradlePluginTest.kt b/gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/gradle/GradlePluginTest.kt similarity index 95% rename from gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/GradlePluginTest.kt rename to gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/gradle/GradlePluginTest.kt index ff4c46fcfa..bbf6cc39a3 100644 --- a/gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/GradlePluginTest.kt +++ b/gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/gradle/GradlePluginTest.kt @@ -1,4 +1,4 @@ -package org.jetbrains.compose +package org.jetbrains.compose.gradle import org.gradle.testkit.runner.TaskOutcome import org.jetbrains.compose.test.GradlePluginTestBase