Skip to content

Commit 7b7d406

Browse files
committed
Refactor protocol tests
1 parent afc7d1b commit 7b7d406

File tree

1 file changed

+20
-45
lines changed

1 file changed

+20
-45
lines changed

codegen/protocol-tests/build.gradle.kts

Lines changed: 20 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -73,63 +73,38 @@ dependencies {
7373
codegen(libs.smithy.aws.protocol.tests)
7474
}
7575

76-
abstract class ProtocolTestTask @Inject constructor(private val project: Project) : DefaultTask() {
77-
/**
78-
* The projection
79-
*/
80-
@get:Input
81-
abstract val projectionName: Property<String>
82-
83-
/**
84-
* The projection root directory
85-
*/
86-
@get:Input
87-
abstract val projectionRootDirectory: Property<String>
88-
89-
@TaskAction
90-
fun runTests() {
91-
val projectionRootDir = project.file(projectionRootDirectory.get())
92-
println("[$projectionName] buildDir: $projectionRootDir")
93-
if (!projectionRootDir.exists()) {
94-
throw GradleException("$projectionRootDir does not exist")
95-
}
96-
val wrapper = if (System.getProperty("os.name").lowercase().contains("windows")) "gradlew.bat" else "gradlew"
97-
val gradlew = project.rootProject.file(wrapper).absolutePath
98-
99-
// NOTE - this still requires us to publish to maven local.
100-
providers.exec {
101-
workingDir = projectionRootDir
102-
executable = gradlew
103-
args = listOf("test")
104-
}
105-
}
106-
}
107-
10876
smithyBuild.projections.forEach {
10977
val protocolName = it.name
11078

111-
tasks.register<ProtocolTestTask>("testProtocol-$protocolName") {
112-
dependsOn(tasks.generateSmithyProjections)
113-
group = "Verification"
114-
projectionName.set(it.name)
115-
projectionRootDirectory.set(smithyBuild.smithyKotlinProjectionPath(it.name).map { it.toString() })
116-
}
79+
val dirProvider = smithyBuild
80+
.smithyKotlinProjectionPath(protocolName)
81+
.map { file(it.toString()) }
11782

118-
// FIXME This is a hack to work around how protocol tests aren't in the actual service model and thus codegen
119-
// separately from service customizations.
12083
val copyStaticFiles = tasks.register<Copy>("copyStaticFiles-$protocolName") {
12184
group = "codegen"
12285
from(rootProject.projectDir.resolve("services/$protocolName/common/src"))
123-
into(smithyBuild.smithyKotlinProjectionSrcDir(it.name))
86+
into(smithyBuild.smithyKotlinProjectionSrcDir(protocolName))
12487
}
12588

126-
tasks.generateSmithyProjections.configure {
127-
finalizedBy(copyStaticFiles)
89+
tasks.register<Exec>("testProtocol-$protocolName") {
90+
group = "Verification"
91+
dependsOn(tasks.generateSmithyProjections, copyStaticFiles)
92+
93+
doFirst {
94+
val dir = dirProvider.get()
95+
require(dir.exists()) { "$dir does not exist" }
96+
97+
val wrapper = if (System.getProperty("os.name").lowercase().contains("windows")) "gradlew.bat" else "gradlew"
98+
val gradlew = rootProject.layout.projectDirectory.file(wrapper).asFile.absolutePath
99+
100+
workingDir = dir
101+
executable = gradlew
102+
args = listOf("test")
103+
}
128104
}
129105
}
130106

131107
tasks.register("testAllProtocols") {
132108
group = "Verification"
133-
val allTests = tasks.withType<ProtocolTestTask>()
134-
dependsOn(allTests)
109+
dependsOn(tasks.matching { it.name.startsWith("testProtocol-") })
135110
}

0 commit comments

Comments
 (0)