-
-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP. Proving that DAGP can handle suspend functions.
- Loading branch information
1 parent
cbd5cd0
commit 1723ad6
Showing
3 changed files
with
118 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/functionalTest/groovy/com/autonomousapps/jvm/KotlinSuspendSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
} | ||
} |
88 changes: 88 additions & 0 deletions
88
src/functionalTest/groovy/com/autonomousapps/jvm/projects/KotlinSuspendProject.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Source> 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<String, String> = TODO() | ||
}'''.stripIndent() | ||
) | ||
] | ||
|
||
private static final List<Source> producerSources = [ | ||
new Source( | ||
SourceType.KOTLIN, 'Producer.kt', 'com/example/producer', | ||
'''\ | ||
package com.example.producer | ||
fun <E : Any> complicatedThing( | ||
datum: Datum, | ||
body: suspend () -> ApiResult<*, E> | ||
): Unit = TODO() | ||
class Datum | ||
class ApiResult<A, B>'''.stripIndent() | ||
) | ||
] | ||
|
||
Set<ProjectAdvice> actualBuildHealth() { | ||
return actualProjectAdvice(gradleProject) | ||
} | ||
|
||
final Set<ProjectAdvice> expectedBuildHealth = emptyProjectAdviceFor(':consumer', ':producer',) | ||
} |