Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC30: Add tests to ensure that serde attributes are not added to error types #2803

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package software.amazon.smithy.rust.codegen.core.smithy.generators

import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import software.amazon.smithy.codegen.core.Symbol
import software.amazon.smithy.model.Model
Expand All @@ -26,13 +27,16 @@ 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 software.amazon.smithy.rust.codegen.core.util.lookup
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 @@ -157,6 +161,31 @@ internal class BuilderGeneratorTest {
project.compileAndTest()
}

@Test
fun `don't add serde to error types`() {
thomas-k-cameron marked this conversation as resolved.
Show resolved Hide resolved
val provider = testSymbolProvider(model)
val project = TestWorkspace.testProject(provider)
project.moduleFor(errorStruct) {
rust("##![allow(deprecated)]")
StructureGenerator(model, provider, this, errorStruct, emptyList(), StructSettings(false)).render()
implBlock(provider.toSymbol(errorStruct)) {
BuilderGenerator.renderConvenienceMethod(this, provider, errorStruct)
}
}
project.withModule(provider.moduleForBuilder(errorStruct)) {
BuilderGenerator(model, provider, errorStruct, emptyList()).render(this)
}
project.compileAndTest()
thomas-k-cameron marked this conversation as resolved.
Show resolved Hide resolved

// 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()
Assertions.assertFalse(file.contains("serde::"))
}
}
}

@Test
fun `it supports nonzero defaults`() {
val model =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class StructureGeneratorTest {
val credentials = model.lookup<StructureShape>("com.test#Credentials")
val secretStructure = model.lookup<StructureShape>("com.test#SecretStructure")
val structWithInnerSecretStructure = model.lookup<StructureShape>("com.test#StructWithInnerSecretStructure")
val error = model.lookup<StructureShape>("com.test#MyError")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this to get the shape of an error.


val rustReservedWordConfig: RustReservedWordConfig =
RustReservedWordConfig(
Expand Down
Loading