diff --git a/src/functionalTest/groovy/com/autonomousapps/jvm/AbstractJvmSpec.groovy b/src/functionalTest/groovy/com/autonomousapps/jvm/AbstractJvmSpec.groovy index d971949cb..49c380bf7 100644 --- a/src/functionalTest/groovy/com/autonomousapps/jvm/AbstractJvmSpec.groovy +++ b/src/functionalTest/groovy/com/autonomousapps/jvm/AbstractJvmSpec.groovy @@ -12,7 +12,7 @@ abstract class AbstractJvmSpec extends AbstractFunctionalSpec { @SuppressWarnings('unused') def cleanup() { if (gradleProject != null && shouldClean) { - clean(gradleProject.rootDir) +// clean(gradleProject.rootDir) } } } diff --git a/src/functionalTest/groovy/com/autonomousapps/jvm/KotlinSuspendSpec.groovy b/src/functionalTest/groovy/com/autonomousapps/jvm/KotlinSuspendSpec.groovy new file mode 100644 index 000000000..83b90747d --- /dev/null +++ b/src/functionalTest/groovy/com/autonomousapps/jvm/KotlinSuspendSpec.groovy @@ -0,0 +1,29 @@ +package com.autonomousapps.jvm + +import com.autonomousapps.android.AbstractAndroidSpec +import com.autonomousapps.jvm.projects.KotlinSuspendProject + +import static com.autonomousapps.advice.truth.BuildHealthSubject.buildHealth +import static com.autonomousapps.utils.Runner.build +import static com.google.common.truth.Truth.assertAbout + +@SuppressWarnings('GroovyAssignabilityCheck') +final class KotlinSuspendSpec extends AbstractJvmSpec { + + def "can detect functions that take suspend parameters (#gradleVersion)"() { + given: + def project = new KotlinSuspendProject() + gradleProject = project.gradleProject + + when: + build(gradleVersion, gradleProject.rootDir, 'buildHealth') + + then: + assertAbout(buildHealth()) + .that(project.actualBuildHealth()) + .isEquivalentIgnoringModuleAdvice(project.expectedBuildHealth) + + where: + gradleVersion << gradleVersions() + } +} diff --git a/src/functionalTest/groovy/com/autonomousapps/jvm/projects/KotlinSuspendProject.groovy b/src/functionalTest/groovy/com/autonomousapps/jvm/projects/KotlinSuspendProject.groovy new file mode 100644 index 000000000..b5c62a042 --- /dev/null +++ b/src/functionalTest/groovy/com/autonomousapps/jvm/projects/KotlinSuspendProject.groovy @@ -0,0 +1,88 @@ +package com.autonomousapps.jvm.projects + +import com.autonomousapps.AbstractProject +import com.autonomousapps.kit.* +import com.autonomousapps.model.ProjectAdvice + +import static com.autonomousapps.AdviceHelper.actualProjectAdvice +import static com.autonomousapps.AdviceHelper.emptyProjectAdviceFor +import static com.autonomousapps.kit.Dependency.project + +final class KotlinSuspendProject extends AbstractProject { + + final GradleProject gradleProject + + KotlinSuspendProject() { + this.gradleProject = build() + } + + private GradleProject build() { + def builder = newGradleProjectBuilder() + builder.withRootProject { root -> + root.gradleProperties = GradleProperties.minimalJvmProperties() + } + builder.withSubproject('consumer') { consumer -> + consumer.withBuildScript { bs -> + bs.plugins = [Plugin.kotlinPluginNoVersion] + bs.dependencies = [ + project('implementation', ':producer') + ] + } + consumer.sources = consumerSources + } + builder.withSubproject('producer') { producer -> + producer.withBuildScript { bs -> + bs.plugins = [Plugin.kotlinPluginNoVersion] + } + producer.sources = producerSources + } + + def project = builder.build() + project.writer().write() + return project + } + + private static final List consumerSources = [ + new Source( + SourceType.KOTLIN, 'Consumer.kt', 'com/example/consumer', + '''\ + package com.example.consumer + + import com.example.producer.* + + internal class Consumer { + + fun doTheThing() { + complicatedThing(Datum()) { + getApiResult() + } + } + + suspend fun getApiResult(): ApiResult = TODO() + }'''.stripIndent() + ) + ] + + private static final List producerSources = [ + new Source( + SourceType.KOTLIN, 'Producer.kt', 'com/example/producer', + '''\ + package com.example.producer + + fun complicatedThing( + datum: Datum, + body: suspend () -> ApiResult<*, E> + ): Unit = TODO() + + class Datum + + class ApiResult'''.stripIndent() + ) + ] + + Set actualBuildHealth() { + return actualProjectAdvice(gradleProject) + } + + final Set expectedBuildHealth = emptyProjectAdviceFor(':consumer', ':producer',) +}