Skip to content

Commit

Permalink
add
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-k-cameron committed Jun 22, 2023
1 parent 7dc67c8 commit 4f65d8d
Showing 1 changed file with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@ import software.amazon.smithy.rust.codegen.core.testutil.TestWorkspace
import software.amazon.smithy.rust.codegen.core.testutil.compileAndTest
import software.amazon.smithy.rust.codegen.core.testutil.testSymbolProvider
import software.amazon.smithy.rust.codegen.core.testutil.unitTest
import kotlin.io.path.extension
import kotlin.io.path.readText

internal class BuilderGeneratorTest {
private val model = StructureGeneratorTest.model
private val inner = StructureGeneratorTest.inner
private val struct = StructureGeneratorTest.struct
private val credentials = StructureGeneratorTest.credentials
private val secretStructure = StructureGeneratorTest.secretStructure
private val errorStruct = StructureGeneratorTest.error

@Test
fun `generate builders`() {
Expand Down Expand Up @@ -137,4 +140,30 @@ internal class BuilderGeneratorTest {
}
project.compileAndTest()
}

@Test
fun `don't add serde to error types`() {
val provider = testSymbolProvider(model)
val project = TestWorkspace.testProject(provider)
project.moduleFor(errorStruct) {
rust("##![allow(deprecated)]")
StructureGenerator(model, provider, this, errorStruct, emptyList()).render()
implBlock(provider.toSymbol(errorStruct)) {
BuilderGenerator.renderConvenienceMethod(this, provider, errorStruct)
}
}
project.withModule(provider.moduleForBuilder(errorStruct)) {
BuilderGenerator(model, provider, errorStruct, emptyList()).render(this)
}
project.compileAndTest()

// checks if there is a serde derive in the code
project.generatedFiles().forEach {
if (it.extension == "rs") {
val file = project.baseDir.resolve(it).toFile().readText()
val check = file.contains("derive(serde::Deserialize)") || file.contains("derive(serde::Serialize)")
assert(!check)
}
}
}
}

0 comments on commit 4f65d8d

Please sign in to comment.