Skip to content

Commit

Permalink
Allow deprecated in unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: Weihang Lo <[email protected]>
  • Loading branch information
weihanglo committed Jul 26, 2022
1 parent 09ed414 commit dfc85b7
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import org.junit.jupiter.api.Test
import software.amazon.smithy.model.shapes.StringShape
import software.amazon.smithy.model.traits.EnumTrait
import software.amazon.smithy.rust.codegen.rustlang.RustWriter
import software.amazon.smithy.rust.codegen.rustlang.rust
import software.amazon.smithy.rust.codegen.smithy.generators.EnumGenerator
import software.amazon.smithy.rust.codegen.smithy.generators.EnumMemberModel
import software.amazon.smithy.rust.codegen.testutil.asSmithyModel
Expand Down Expand Up @@ -109,6 +110,7 @@ class EnumGeneratorTest {
""".asSmithyModel()
val provider = testSymbolProvider(model)
val writer = RustWriter.forModule("model")
writer.rust("##![allow(deprecated)]")
val shape = model.lookup<StringShape>("test#InstanceType")
val generator = EnumGenerator(model, provider, writer, shape, shape.expectTrait<EnumTrait>())
generator.render()
Expand Down Expand Up @@ -177,6 +179,7 @@ class EnumGeneratorTest {
val shape = model.lookup<StringShape>("test#FooEnum")
val trait = shape.expectTrait<EnumTrait>()
val writer = RustWriter.forModule("model")
writer.rust("##![allow(deprecated)]")
val generator = EnumGenerator(model, testSymbolProvider(model), writer, shape, trait)
generator.render()
writer.compileAndTest(
Expand Down Expand Up @@ -216,6 +219,7 @@ class EnumGeneratorTest {
val trait = shape.expectTrait<EnumTrait>()
val provider = testSymbolProvider(model)
val writer = RustWriter.forModule("model")
writer.rust("##![allow(deprecated)]")
val generator = EnumGenerator(model, provider, writer, shape, trait)
generator.render()
writer.compileAndTest(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@

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

import io.kotest.matchers.string.shouldContain
import io.kotest.matchers.string.shouldContainInOrder
import io.kotest.matchers.string.shouldNotContain
import org.junit.jupiter.api.Test
import software.amazon.smithy.model.shapes.StructureShape
import software.amazon.smithy.rust.codegen.rustlang.Attribute
Expand Down Expand Up @@ -103,6 +101,7 @@ class StructureGeneratorTest {
fun `generate structures with public fields`() {
val provider = testSymbolProvider(model)
val writer = RustWriter.root()
writer.rust("##![allow(deprecated)]")
writer.withModule("model") {
val innerGenerator = StructureGenerator(model, provider, this, inner)
innerGenerator.render()
Expand Down Expand Up @@ -232,6 +231,7 @@ class StructureGeneratorTest {
""".asSmithyModel()
val provider = testSymbolProvider(model)
val writer = RustWriter.root()
writer.rust("##![allow(deprecated)]")
writer.withModule("model") {
StructureGenerator(model, provider, this, model.lookup("test#Foo")).render()
StructureGenerator(model, provider, this, model.lookup("test#Bar")).render()
Expand Down Expand Up @@ -263,20 +263,14 @@ class StructureGeneratorTest {
""".asSmithyModel()
val provider = testSymbolProvider(model)
val writer = RustWriter.root()
writer.rust("##![allow(deprecated)]")
writer.withModule("model") {
StructureGenerator(model, provider, this, model.lookup("test#Nested")).render()
StructureGenerator(model, provider, this, model.lookup("test#Foo")).render()
StructureGenerator(model, provider, this, model.lookup("test#Bar")).render()
}

val output = writer.compileAndTest()
output shouldNotContain "use of deprecated struct `model::Nested`"
output shouldContain "use of deprecated struct `model::Foo`"
output shouldContain "use of deprecated struct `model::Bar`"

output shouldNotContain "use of deprecated field `model::Nested::foo`"
output shouldContain "use of deprecated field `model::Nested::foo2`"
output shouldContain "use of deprecated field `model::Foo::bar`"
writer.compileAndTest()
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
package software.amazon.smithy.rust.codegen.generators

import io.kotest.matchers.string.shouldContain
import io.kotest.matchers.string.shouldNotContain
import org.junit.jupiter.api.Test
import software.amazon.smithy.codegen.core.SymbolProvider
import software.amazon.smithy.rust.codegen.rustlang.RustWriter
import software.amazon.smithy.rust.codegen.rustlang.rust
import software.amazon.smithy.rust.codegen.smithy.generators.UnionGenerator
import software.amazon.smithy.rust.codegen.testutil.asSmithyModel
import software.amazon.smithy.rust.codegen.testutil.compileAndTest
Expand Down Expand Up @@ -114,20 +114,14 @@ class UnionGeneratorTest {
""".asSmithyModel()
val provider: SymbolProvider = testSymbolProvider(model)
val writer = RustWriter.root()
writer.rust("##![allow(deprecated)]")
writer.withModule("model") {
UnionGenerator(model, provider, this, model.lookup("test#Nested")).render()
UnionGenerator(model, provider, this, model.lookup("test#Foo")).render()
UnionGenerator(model, provider, this, model.lookup("test#Bar")).render()
}

val output = writer.compileAndTest()
output shouldNotContain "use of deprecated enum `model::Nested`"
output shouldContain "use of deprecated enum `model::Foo`"
output shouldContain "use of deprecated enum `model::Bar`"

output shouldNotContain "use of deprecated tuple variant `model::Nested::Foo`"
output shouldContain "use of deprecated tuple variant `model::Nested::Foo2`"
output shouldContain "use of deprecated tuple variant `model::Foo::Bar`"
writer.compileAndTest()
}

private fun generateUnion(modelSmithy: String, unionName: String = "MyUnion", unknownVariant: Boolean = true): RustWriter {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import software.amazon.smithy.model.shapes.Shape
import software.amazon.smithy.model.traits.EnumDefinition
import software.amazon.smithy.rust.codegen.generators.StructureGeneratorTest
import software.amazon.smithy.rust.codegen.rustlang.RustWriter
import software.amazon.smithy.rust.codegen.rustlang.rust
import software.amazon.smithy.rust.codegen.smithy.Default
import software.amazon.smithy.rust.codegen.smithy.MaybeRenamed
import software.amazon.smithy.rust.codegen.smithy.RustSymbolProvider
Expand All @@ -29,6 +30,7 @@ internal class BuilderGeneratorTest {
fun `generate builders`() {
val provider = testSymbolProvider(model)
val writer = RustWriter.forModule("model")
writer.rust("##![allow(deprecated)]")
val innerGenerator = StructureGenerator(model, provider, writer, inner)
val generator = StructureGenerator(model, provider, writer, struct)
val builderGenerator = BuilderGenerator(model, provider, struct)
Expand Down Expand Up @@ -69,6 +71,7 @@ internal class BuilderGeneratorTest {
}
}
val writer = RustWriter.forModule("model")
writer.rust("##![allow(deprecated)]")
val innerGenerator = StructureGenerator(
StructureGeneratorTest.model, provider, writer,
StructureGeneratorTest.inner
Expand Down

0 comments on commit dfc85b7

Please sign in to comment.