From 3cdd51c9a287ea55839116830fc9397b1d429226 Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Tue, 26 Jul 2022 15:02:07 +0100 Subject: [PATCH] Allow deprecated in unit tests Signed-off-by: Weihang Lo --- .../rust/codegen/generators/EnumGeneratorTest.kt | 3 +++ .../codegen/generators/StructureGeneratorTest.kt | 14 ++++---------- .../rust/codegen/generators/UnionGeneratorTest.kt | 12 +++--------- .../smithy/generators/BuilderGeneratorTest.kt | 3 +++ 4 files changed, 13 insertions(+), 19 deletions(-) diff --git a/codegen/src/test/kotlin/software/amazon/smithy/rust/codegen/generators/EnumGeneratorTest.kt b/codegen/src/test/kotlin/software/amazon/smithy/rust/codegen/generators/EnumGeneratorTest.kt index c044a33cb4f..5a5d759d6b3 100644 --- a/codegen/src/test/kotlin/software/amazon/smithy/rust/codegen/generators/EnumGeneratorTest.kt +++ b/codegen/src/test/kotlin/software/amazon/smithy/rust/codegen/generators/EnumGeneratorTest.kt @@ -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 @@ -177,6 +178,7 @@ class EnumGeneratorTest { val shape = model.lookup("test#FooEnum") val trait = shape.expectTrait() val writer = RustWriter.forModule("model") + writer.rust("##![allow(deprecated)]") val generator = EnumGenerator(model, testSymbolProvider(model), writer, shape, trait) generator.render() writer.compileAndTest( @@ -216,6 +218,7 @@ class EnumGeneratorTest { val trait = shape.expectTrait() 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( diff --git a/codegen/src/test/kotlin/software/amazon/smithy/rust/codegen/generators/StructureGeneratorTest.kt b/codegen/src/test/kotlin/software/amazon/smithy/rust/codegen/generators/StructureGeneratorTest.kt index 835a8d03899..7f57ee13936 100644 --- a/codegen/src/test/kotlin/software/amazon/smithy/rust/codegen/generators/StructureGeneratorTest.kt +++ b/codegen/src/test/kotlin/software/amazon/smithy/rust/codegen/generators/StructureGeneratorTest.kt @@ -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 @@ -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() @@ -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() @@ -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 diff --git a/codegen/src/test/kotlin/software/amazon/smithy/rust/codegen/generators/UnionGeneratorTest.kt b/codegen/src/test/kotlin/software/amazon/smithy/rust/codegen/generators/UnionGeneratorTest.kt index fc6ba0e736c..5be114e07c0 100644 --- a/codegen/src/test/kotlin/software/amazon/smithy/rust/codegen/generators/UnionGeneratorTest.kt +++ b/codegen/src/test/kotlin/software/amazon/smithy/rust/codegen/generators/UnionGeneratorTest.kt @@ -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 @@ -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 { diff --git a/codegen/src/test/kotlin/software/amazon/smithy/rust/codegen/smithy/generators/BuilderGeneratorTest.kt b/codegen/src/test/kotlin/software/amazon/smithy/rust/codegen/smithy/generators/BuilderGeneratorTest.kt index 5b0580afdcc..8e09065ba2f 100644 --- a/codegen/src/test/kotlin/software/amazon/smithy/rust/codegen/smithy/generators/BuilderGeneratorTest.kt +++ b/codegen/src/test/kotlin/software/amazon/smithy/rust/codegen/smithy/generators/BuilderGeneratorTest.kt @@ -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 @@ -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) @@ -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