From 37e4609e951030ebf2487ccdee57e426828a8cc3 Mon Sep 17 00:00:00 2001 From: Jesse Wilson Date: Fri, 24 Nov 2023 10:15:32 -0500 Subject: [PATCH] Suppress deprecation warnings in generated code (#1701) Our generated code calls deprecated APIs, either because the Redwood generated interfaces they're calling are deprecated, or because other external symbols like property types are deprecated. In either case the developer is already getting these deprecation warnings in the code that declares the schema, so Redwood's additional deprecations are just noise. This PR applies deprecation warnings everywhere. I originally looked into doing it precisely for the Redwood symbols that declare deprecations, but this doesn't cover deprecations on property types. --- redwood-tooling-codegen/build.gradle | 1 + .../cash/redwood/tooling/codegen/codegen.kt | 59 ++++--- .../tooling/codegen/composeGeneration.kt | 3 + .../tooling/codegen/modifierGeneration.kt | 1 + .../tooling/codegen/protocolCodegen.kt | 41 +++-- .../codegen/protocolGuestGeneration.kt | 5 + .../redwood/tooling/codegen/sharedHelpers.kt | 5 + .../tooling/codegen/testingGeneration.kt | 4 + .../tooling/codegen/widgetGeneration.kt | 3 + .../codegen/widgetProtocolGeneration.kt | 3 + .../codegen/DeprecatedGenerationTest.kt | 164 ++++++++++++++++++ .../tooling/codegen/ModifierGenerationTest.kt | 45 ----- .../tooling/codegen/WidgetGenerationTest.kt | 72 -------- 13 files changed, 248 insertions(+), 158 deletions(-) create mode 100644 redwood-tooling-codegen/src/test/kotlin/app/cash/redwood/tooling/codegen/DeprecatedGenerationTest.kt diff --git a/redwood-tooling-codegen/build.gradle b/redwood-tooling-codegen/build.gradle index f1ec039a38..93ece5729d 100644 --- a/redwood-tooling-codegen/build.gradle +++ b/redwood-tooling-codegen/build.gradle @@ -14,4 +14,5 @@ dependencies { testImplementation projects.testApp.schema.compose testImplementation libs.junit testImplementation libs.assertk + testImplementation libs.testParameterInjector } diff --git a/redwood-tooling-codegen/src/main/kotlin/app/cash/redwood/tooling/codegen/codegen.kt b/redwood-tooling-codegen/src/main/kotlin/app/cash/redwood/tooling/codegen/codegen.kt index 3d47d96bcd..186a0b9f75 100644 --- a/redwood-tooling-codegen/src/main/kotlin/app/cash/redwood/tooling/codegen/codegen.kt +++ b/redwood-tooling-codegen/src/main/kotlin/app/cash/redwood/tooling/codegen/codegen.kt @@ -20,6 +20,7 @@ import app.cash.redwood.tooling.codegen.CodegenType.Modifiers import app.cash.redwood.tooling.codegen.CodegenType.Testing import app.cash.redwood.tooling.codegen.CodegenType.Widget import app.cash.redwood.tooling.schema.SchemaSet +import com.squareup.kotlinpoet.FileSpec import java.nio.file.Path public enum class CodegenType { @@ -30,34 +31,42 @@ public enum class CodegenType { } public fun SchemaSet.generate(type: CodegenType, destination: Path) { - when (type) { - Compose -> { - generateModifierImpls(schema)?.writeTo(destination) - for (scope in schema.scopes) { - generateScope(schema, scope).writeTo(destination) + for (fileSpec in generateFileSpecs(type)) { + fileSpec.writeTo(destination) + } +} + +internal fun SchemaSet.generateFileSpecs(type: CodegenType): List { + return buildList { + when (type) { + Compose -> { + generateModifierImpls(schema)?.let { add(it) } + for (scope in schema.scopes) { + add(generateScope(schema, scope)) + } + for (widget in schema.widgets) { + add(generateComposable(schema, widget)) + } } - for (widget in schema.widgets) { - generateComposable(schema, widget).writeTo(destination) + Modifiers -> { + for (modifier in schema.modifiers) { + add(generateModifierInterface(schema, modifier)) + } } - } - Modifiers -> { - for (modifier in schema.modifiers) { - generateModifierInterface(schema, modifier).writeTo(destination) + Testing -> { + add(generateTester(this@generateFileSpecs)) + add(generateMutableWidgetFactory(schema)) + for (widget in schema.widgets) { + add(generateMutableWidget(schema, widget)) + add(generateWidgetValue(schema, widget)) + } } - } - Testing -> { - generateTester(this).writeTo(destination) - generateMutableWidgetFactory(schema).writeTo(destination) - for (widget in schema.widgets) { - generateMutableWidget(schema, widget).writeTo(destination) - generateWidgetValue(schema, widget).writeTo(destination) - } - } - Widget -> { - generateWidgetFactories(this).writeTo(destination) - generateWidgetFactory(schema).writeTo(destination) - for (widget in schema.widgets) { - generateWidget(schema, widget).writeTo(destination) + Widget -> { + add(generateWidgetFactories(this@generateFileSpecs)) + add(generateWidgetFactory(schema)) + for (widget in schema.widgets) { + add(generateWidget(schema, widget)) + } } } } diff --git a/redwood-tooling-codegen/src/main/kotlin/app/cash/redwood/tooling/codegen/composeGeneration.kt b/redwood-tooling-codegen/src/main/kotlin/app/cash/redwood/tooling/codegen/composeGeneration.kt index 93f23624dd..8f407d5089 100644 --- a/redwood-tooling-codegen/src/main/kotlin/app/cash/redwood/tooling/codegen/composeGeneration.kt +++ b/redwood-tooling-codegen/src/main/kotlin/app/cash/redwood/tooling/codegen/composeGeneration.kt @@ -68,6 +68,7 @@ internal fun generateComposable( val widgetType = schema.widgetType(widget).parameterizedBy(STAR) val flatName = widget.type.flatName return FileSpec.builder(schema.composePackage(), flatName) + .addAnnotation(suppressDeprecations) .addFunction( FunSpec.builder(flatName) .addAnnotation(ComposeRuntime.Composable) @@ -209,6 +210,7 @@ internal fun generateScope(schema: Schema, scope: FqType): FileSpec { val scopeName = scope.flatName val scopeType = ClassName(schema.composePackage(), scopeName) return FileSpec.builder(scopeType) + .addAnnotation(suppressDeprecations) .apply { val scopeBuilder = TypeSpec.interfaceBuilder(scopeType) .addAnnotation(Redwood.LayoutScopeMarker) @@ -243,6 +245,7 @@ internal fun generateModifierImpls(schema: Schema): FileSpec? { if (schema.modifiers.isEmpty()) return null return FileSpec.builder(schema.composePackage(), "modifier") + .addAnnotation(suppressDeprecations) .apply { for (modifier in schema.modifiers) { addType(generateModifierImpl(schema, modifier)) diff --git a/redwood-tooling-codegen/src/main/kotlin/app/cash/redwood/tooling/codegen/modifierGeneration.kt b/redwood-tooling-codegen/src/main/kotlin/app/cash/redwood/tooling/codegen/modifierGeneration.kt index 3113d0e6d8..f96829d61f 100644 --- a/redwood-tooling-codegen/src/main/kotlin/app/cash/redwood/tooling/codegen/modifierGeneration.kt +++ b/redwood-tooling-codegen/src/main/kotlin/app/cash/redwood/tooling/codegen/modifierGeneration.kt @@ -24,6 +24,7 @@ import com.squareup.kotlinpoet.TypeSpec internal fun generateModifierInterface(schema: Schema, modifier: Modifier): FileSpec { val type = schema.modifierType(modifier) return FileSpec.builder(type.packageName, type.simpleName) + .addAnnotation(suppressDeprecations) .addType( TypeSpec.interfaceBuilder(type) .addSuperinterface(Redwood.ModifierElement) diff --git a/redwood-tooling-codegen/src/main/kotlin/app/cash/redwood/tooling/codegen/protocolCodegen.kt b/redwood-tooling-codegen/src/main/kotlin/app/cash/redwood/tooling/codegen/protocolCodegen.kt index c05f05f84d..8eef763cd6 100644 --- a/redwood-tooling-codegen/src/main/kotlin/app/cash/redwood/tooling/codegen/protocolCodegen.kt +++ b/redwood-tooling-codegen/src/main/kotlin/app/cash/redwood/tooling/codegen/protocolCodegen.kt @@ -18,6 +18,7 @@ package app.cash.redwood.tooling.codegen import app.cash.redwood.tooling.codegen.ProtocolCodegenType.Compose import app.cash.redwood.tooling.codegen.ProtocolCodegenType.Widget import app.cash.redwood.tooling.schema.ProtocolSchemaSet +import com.squareup.kotlinpoet.FileSpec import java.nio.file.Path public enum class ProtocolCodegenType { @@ -26,24 +27,32 @@ public enum class ProtocolCodegenType { } public fun ProtocolSchemaSet.generate(type: ProtocolCodegenType, destination: Path) { - when (type) { - Compose -> { - generateProtocolBridge(this).writeTo(destination) - generateComposeProtocolModifierSerialization(this).writeTo(destination) - for (dependency in all) { - generateProtocolWidgetFactory(dependency, host = schema).writeTo(destination) - generateProtocolModifierSerializers(dependency, host = schema)?.writeTo(destination) - for (widget in dependency.widgets) { - generateProtocolWidget(dependency, widget, host = schema).writeTo(destination) + for (fileSpec in generateFileSpecs(type)) { + fileSpec.writeTo(destination) + } +} + +internal fun ProtocolSchemaSet.generateFileSpecs(type: ProtocolCodegenType): List { + return buildList { + when (type) { + Compose -> { + add(generateProtocolBridge(this@generateFileSpecs)) + add(generateComposeProtocolModifierSerialization(this@generateFileSpecs)) + for (dependency in all) { + add(generateProtocolWidgetFactory(dependency, host = schema)) + generateProtocolModifierSerializers(dependency, host = schema)?.let { add(it) } + for (widget in dependency.widgets) { + add(generateProtocolWidget(dependency, widget, host = schema)) + } } } - } - Widget -> { - generateProtocolFactory(this).writeTo(destination) - for (dependency in all) { - generateProtocolModifierImpls(dependency, host = schema)?.writeTo(destination) - for (widget in dependency.widgets) { - generateProtocolNode(dependency, widget, host = schema).writeTo(destination) + Widget -> { + add(generateProtocolFactory(this@generateFileSpecs)) + for (dependency in all) { + generateProtocolModifierImpls(dependency, host = schema)?.let { add(it) } + for (widget in dependency.widgets) { + add(generateProtocolNode(dependency, widget, host = schema)) + } } } } diff --git a/redwood-tooling-codegen/src/main/kotlin/app/cash/redwood/tooling/codegen/protocolGuestGeneration.kt b/redwood-tooling-codegen/src/main/kotlin/app/cash/redwood/tooling/codegen/protocolGuestGeneration.kt index 9cf52fa98f..bf70a9c92d 100644 --- a/redwood-tooling-codegen/src/main/kotlin/app/cash/redwood/tooling/codegen/protocolGuestGeneration.kt +++ b/redwood-tooling-codegen/src/main/kotlin/app/cash/redwood/tooling/codegen/protocolGuestGeneration.kt @@ -86,6 +86,7 @@ internal fun generateProtocolBridge( val type = schema.protocolBridgeType() val providerType = schema.getWidgetFactoryProviderType().parameterizedBy(NOTHING) return FileSpec.builder(type) + .addAnnotation(suppressDeprecations) .addType( TypeSpec.classBuilder(type) .addSuperinterface(ProtocolGuest.ProtocolBridge) @@ -195,6 +196,7 @@ internal fun generateProtocolWidgetFactory( ): FileSpec { val type = schema.protocolWidgetFactoryType(host) return FileSpec.builder(type) + .addAnnotation(suppressDeprecations) .addType( TypeSpec.classBuilder(type) .addModifiers(INTERNAL) @@ -293,6 +295,7 @@ internal fun generateProtocolWidget( val type = schema.protocolWidgetType(widget, host) val widgetName = schema.widgetType(widget) return FileSpec.builder(type) + .addAnnotation(suppressDeprecations) .addType( TypeSpec.classBuilder(type) .addModifiers(INTERNAL) @@ -512,6 +515,7 @@ internal fun generateProtocolModifierSerializers( return null } return FileSpec.builder(schema.composePackage(host), "modifierSerializers") + .addAnnotation(suppressDeprecations) .apply { for (modifier in serializableModifiers) { val serializerType = schema.modifierSerializer(modifier, host) @@ -691,6 +695,7 @@ internal fun generateComposeProtocolModifierSerialization( val schema = schemaSet.schema val name = schema.modifierToProtocol.simpleName return FileSpec.builder(schema.composePackage(), "modifierSerialization") + .addAnnotation(suppressDeprecations) .addFunction( FunSpec.builder(name) .addModifiers(INTERNAL) diff --git a/redwood-tooling-codegen/src/main/kotlin/app/cash/redwood/tooling/codegen/sharedHelpers.kt b/redwood-tooling-codegen/src/main/kotlin/app/cash/redwood/tooling/codegen/sharedHelpers.kt index 7ae65d6487..a12fdbc73f 100644 --- a/redwood-tooling-codegen/src/main/kotlin/app/cash/redwood/tooling/codegen/sharedHelpers.kt +++ b/redwood-tooling-codegen/src/main/kotlin/app/cash/redwood/tooling/codegen/sharedHelpers.kt @@ -213,6 +213,11 @@ internal fun Deprecation.toAnnotationSpec(): AnnotationSpec { .build() } +internal val suppressDeprecations = AnnotationSpec.builder(Suppress::class) + .useSiteTarget(AnnotationSpec.UseSiteTarget.FILE) + .addMember("%S", "DEPRECATION") + .build() + private fun Deprecation.Level.toMemberName(): MemberName { return MemberName( DeprecationLevel::class.asClassName(), diff --git a/redwood-tooling-codegen/src/main/kotlin/app/cash/redwood/tooling/codegen/testingGeneration.kt b/redwood-tooling-codegen/src/main/kotlin/app/cash/redwood/tooling/codegen/testingGeneration.kt index de8d72ec13..5bae482529 100644 --- a/redwood-tooling-codegen/src/main/kotlin/app/cash/redwood/tooling/codegen/testingGeneration.kt +++ b/redwood-tooling-codegen/src/main/kotlin/app/cash/redwood/tooling/codegen/testingGeneration.kt @@ -72,6 +72,7 @@ internal fun generateTester(schemaSet: SchemaSet): FileSpec { returnType = typeVarR, ).copy(suspending = true) return FileSpec.builder(testerFunction.packageName, testerFunction.simpleName) + .addAnnotation(suppressDeprecations) .addFunction( FunSpec.builder(testerFunction) .optIn(Redwood.RedwoodCodegenApi) @@ -127,6 +128,7 @@ public class EmojiSearchTestingWidgetFactory : EmojiSearchWidgetFactory : Widget.Factory { internal fun generateWidgetFactory(schema: Schema): FileSpec { val widgetFactoryType = schema.getWidgetFactoryType() return FileSpec.builder(widgetFactoryType) + .addAnnotation(suppressDeprecations) .addType( TypeSpec.interfaceBuilder(widgetFactoryType) .addTypeVariable(typeVariableW) @@ -157,6 +159,7 @@ interface Button : Widget { internal fun generateWidget(schema: Schema, widget: Widget): FileSpec { val flatName = widget.type.flatName return FileSpec.builder(schema.widgetPackage(), flatName) + .addAnnotation(suppressDeprecations) .addType( TypeSpec.interfaceBuilder(flatName) .addTypeVariable(typeVariableW) diff --git a/redwood-tooling-codegen/src/main/kotlin/app/cash/redwood/tooling/codegen/widgetProtocolGeneration.kt b/redwood-tooling-codegen/src/main/kotlin/app/cash/redwood/tooling/codegen/widgetProtocolGeneration.kt index d79af94868..8a56d91169 100644 --- a/redwood-tooling-codegen/src/main/kotlin/app/cash/redwood/tooling/codegen/widgetProtocolGeneration.kt +++ b/redwood-tooling-codegen/src/main/kotlin/app/cash/redwood/tooling/codegen/widgetProtocolGeneration.kt @@ -73,6 +73,7 @@ internal fun generateProtocolFactory( val provider = schema.getWidgetFactoryProviderType().parameterizedBy(typeVariableW) val type = schema.protocolFactoryType() return FileSpec.builder(type) + .addAnnotation(suppressDeprecations) .addType( TypeSpec.classBuilder(type) .addTypeVariable(typeVariableW) @@ -225,6 +226,7 @@ internal fun generateProtocolNode( val protocolType = WidgetProtocol.ProtocolNode.parameterizedBy(typeVariableW) val (childrens, properties) = widget.traits.partition { it is ProtocolChildren } return FileSpec.builder(type) + .addAnnotation(suppressDeprecations) .addType( TypeSpec.classBuilder(type) .addModifiers(INTERNAL) @@ -413,6 +415,7 @@ internal fun generateProtocolModifierImpls( return null } return FileSpec.builder(schema.widgetPackage(host), "modifierImpls") + .addAnnotation(suppressDeprecations) .apply { for (modifier in schema.modifiers) { val typeName = ClassName(schema.widgetPackage(host), modifier.type.flatName + "Impl") diff --git a/redwood-tooling-codegen/src/test/kotlin/app/cash/redwood/tooling/codegen/DeprecatedGenerationTest.kt b/redwood-tooling-codegen/src/test/kotlin/app/cash/redwood/tooling/codegen/DeprecatedGenerationTest.kt new file mode 100644 index 0000000000..b0ad985c54 --- /dev/null +++ b/redwood-tooling-codegen/src/test/kotlin/app/cash/redwood/tooling/codegen/DeprecatedGenerationTest.kt @@ -0,0 +1,164 @@ +/* + * Copyright (C) 2023 Square, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package app.cash.redwood.tooling.codegen + +import app.cash.redwood.schema.Children +import app.cash.redwood.schema.Modifier +import app.cash.redwood.schema.Property +import app.cash.redwood.schema.Schema +import app.cash.redwood.schema.Widget +import app.cash.redwood.tooling.schema.ProtocolSchemaSet +import assertk.all +import assertk.assertAll +import assertk.assertThat +import assertk.assertions.contains +import com.google.testing.junit.testparameterinjector.TestParameter +import com.google.testing.junit.testparameterinjector.TestParameterInjector +import kotlin.DeprecationLevel.ERROR +import org.junit.Test +import org.junit.runner.RunWith + +@RunWith(TestParameterInjector::class) +class DeprecatedGenerationTest { + @Suppress("DEPRECATION") + @Schema( + [ + DeprecatedModifier::class, + DeprecatedWidget::class, + ], + ) + interface DeprecatedSchema + + @Widget(1) + @Deprecated("Hey") + data class DeprecatedWidget( + @Property(1) + @Deprecated("Property", level = ERROR) + val prop: String, + @Property(2) + @Deprecated("Event", level = ERROR) + val event: () -> Unit, + @Children(1) + @Deprecated("Children", level = ERROR) + val children: () -> Unit, + ) + + @Modifier(1, ModifierGenerationTest.ModifierScope::class) + @Deprecated("Hey") + data class DeprecatedModifier( + @Deprecated("Hello", level = ERROR) + val a: String, + ) + + @Test fun modifierInterface() { + val schema = ProtocolSchemaSet.parse(DeprecatedSchema::class).schema + + val modifier = schema.modifiers.single() + val fileSpec = generateModifierInterface(schema, modifier) + assertThat(fileSpec.toString()).all { + contains( + """ + |@Deprecated( + | "Hey", + | level = WARNING, + |) + |public interface DeprecatedGenerationTestDeprecatedModifier + """.trimMargin(), + ) + + contains( + """ + | @Deprecated( + | "Hello", + | level = ERROR, + | ) + | public val a: + """.trimMargin(), + ) + } + } + + @Test fun widget() { + val schema = ProtocolSchemaSet.parse(DeprecatedSchema::class).schema + + val widget = schema.widgets.single() + val fileSpec = generateWidget(schema, widget) + assertThat(fileSpec.toString()).all { + contains( + """ + |@Deprecated( + | "Hey", + | level = WARNING, + |) + |public interface DeprecatedGenerationTestDeprecatedWidget + """.trimMargin(), + ) + + contains( + """ + | @Deprecated( + | "Property", + | level = ERROR, + | ) + | public fun prop( + """.trimMargin(), + ) + + contains( + """ + | @Deprecated( + | "Event", + | level = ERROR, + | ) + | public fun event( + """.trimMargin(), + ) + + contains( + """ + | @Deprecated( + | "Children", + | level = ERROR, + | ) + | public val children: + """.trimMargin(), + ) + } + } + + @Test + fun protocolCodegen( + @TestParameter type: ProtocolCodegenType, + ) { + val schema = ProtocolSchemaSet.parse(DeprecatedSchema::class) + assertAll { + for (fileSpec in schema.generateFileSpecs(type)) { + assertThat(fileSpec.toString()).contains("""@file:Suppress("DEPRECATION")""") + } + } + } + + @Test fun codegen( + @TestParameter type: CodegenType, + ) { + val schema = ProtocolSchemaSet.parse(DeprecatedSchema::class) + assertAll { + for (fileSpec in schema.generateFileSpecs(type)) { + assertThat(fileSpec.toString()).contains("""@file:Suppress("DEPRECATION")""") + } + } + } +} diff --git a/redwood-tooling-codegen/src/test/kotlin/app/cash/redwood/tooling/codegen/ModifierGenerationTest.kt b/redwood-tooling-codegen/src/test/kotlin/app/cash/redwood/tooling/codegen/ModifierGenerationTest.kt index a56ed1b441..09daa97b84 100644 --- a/redwood-tooling-codegen/src/test/kotlin/app/cash/redwood/tooling/codegen/ModifierGenerationTest.kt +++ b/redwood-tooling-codegen/src/test/kotlin/app/cash/redwood/tooling/codegen/ModifierGenerationTest.kt @@ -18,12 +18,10 @@ package app.cash.redwood.tooling.codegen import app.cash.redwood.schema.Modifier import app.cash.redwood.schema.Schema import app.cash.redwood.tooling.schema.ProtocolSchemaSet -import assertk.all import assertk.assertThat import assertk.assertions.contains import assertk.assertions.isEqualTo import com.example.redwood.testing.compose.TestScope -import kotlin.DeprecationLevel.ERROR import kotlin.time.Duration.Companion.minutes import kotlin.time.Duration.Companion.seconds import org.junit.Test @@ -95,47 +93,4 @@ class ModifierGenerationTest { type = app.cash.redwood.Modifier.customTypeWithDefault(40.minutes, "hello") assertThat(type.toString()).isEqualTo("CustomTypeWithDefault(customType=40m, string=hello)") } - - @Suppress("DEPRECATION") - @Schema( - [ - DeprecatedModifier::class, - ], - ) - interface DeprecatedSchema - - @Modifier(1, ModifierScope::class) - @Deprecated("Hey") - data class DeprecatedModifier( - @Deprecated("Hello", level = ERROR) - val a: String, - ) - - @Test fun deprecation() { - val schema = ProtocolSchemaSet.parse(DeprecatedSchema::class).schema - - val modifier = schema.modifiers.single() - val fileSpec = generateModifierInterface(schema, modifier) - assertThat(fileSpec.toString()).all { - contains( - """ - |@Deprecated( - | "Hey", - | level = WARNING, - |) - |public interface ModifierGenerationTestDeprecatedModifier - """.trimMargin(), - ) - - contains( - """ - | @Deprecated( - | "Hello", - | level = ERROR, - | ) - | public val a: - """.trimMargin(), - ) - } - } } diff --git a/redwood-tooling-codegen/src/test/kotlin/app/cash/redwood/tooling/codegen/WidgetGenerationTest.kt b/redwood-tooling-codegen/src/test/kotlin/app/cash/redwood/tooling/codegen/WidgetGenerationTest.kt index 5ad592c69f..7e7c1141dd 100644 --- a/redwood-tooling-codegen/src/test/kotlin/app/cash/redwood/tooling/codegen/WidgetGenerationTest.kt +++ b/redwood-tooling-codegen/src/test/kotlin/app/cash/redwood/tooling/codegen/WidgetGenerationTest.kt @@ -15,7 +15,6 @@ */ package app.cash.redwood.tooling.codegen -import app.cash.redwood.schema.Children import app.cash.redwood.schema.Property import app.cash.redwood.schema.Schema import app.cash.redwood.schema.Widget @@ -23,7 +22,6 @@ import app.cash.redwood.tooling.schema.ProtocolSchemaSet import assertk.all import assertk.assertThat import assertk.assertions.contains -import kotlin.DeprecationLevel.ERROR import org.junit.Test class WidgetGenerationTest { @@ -92,74 +90,4 @@ class WidgetGenerationTest { ) } } - - @Suppress("DEPRECATION") - @Schema( - [ - DeprecatedWidget::class, - ], - ) - interface DeprecatedSchema - - @Widget(1) - @Deprecated("Hey") - data class DeprecatedWidget( - @Property(1) - @Deprecated("Property", level = ERROR) - val prop: String, - @Property(2) - @Deprecated("Event", level = ERROR) - val event: () -> Unit, - @Children(1) - @Deprecated("Children", level = ERROR) - val children: () -> Unit, - ) - - @Test fun deprecation() { - val schema = ProtocolSchemaSet.parse(DeprecatedSchema::class).schema - - val widget = schema.widgets.single() - val fileSpec = generateWidget(schema, widget) - assertThat(fileSpec.toString()).all { - contains( - """ - |@Deprecated( - | "Hey", - | level = WARNING, - |) - |public interface WidgetGenerationTestDeprecatedWidget - """.trimMargin(), - ) - - contains( - """ - | @Deprecated( - | "Property", - | level = ERROR, - | ) - | public fun prop( - """.trimMargin(), - ) - - contains( - """ - | @Deprecated( - | "Event", - | level = ERROR, - | ) - | public fun event( - """.trimMargin(), - ) - - contains( - """ - | @Deprecated( - | "Children", - | level = ERROR, - | ) - | public val children: - """.trimMargin(), - ) - } - } }