From 787d317850195ac12b51a6d1c9644bd48e3262ab Mon Sep 17 00:00:00 2001 From: Russell Cohen Date: Mon, 2 Nov 2020 15:37:29 -0500 Subject: [PATCH] Fix RustWrite.withModule bug (#13) * withModule needs to set the parent dependencies * Fix ktlin style --- .../amazon/smithy/rust/codegen/lang/RustWriter.kt | 1 + .../amazon/smithy/rust/lang/RustWriterTest.kt | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/lang/RustWriter.kt b/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/lang/RustWriter.kt index e95c6f718..cb18ce105 100644 --- a/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/lang/RustWriter.kt +++ b/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/lang/RustWriter.kt @@ -93,6 +93,7 @@ class RustWriter private constructor(private val filename: String, val namespace rustBlock("$visibility mod $moduleName") { write(innerWriter.toString()) } + innerWriter.dependencies.forEach { addDependency(it) } } // TODO: refactor both of these methods & add a parent method to for_each across any field type diff --git a/codegen/src/test/kotlin/software/amazon/smithy/rust/lang/RustWriterTest.kt b/codegen/src/test/kotlin/software/amazon/smithy/rust/lang/RustWriterTest.kt index a9321bb9e..27e279991 100644 --- a/codegen/src/test/kotlin/software/amazon/smithy/rust/lang/RustWriterTest.kt +++ b/codegen/src/test/kotlin/software/amazon/smithy/rust/lang/RustWriterTest.kt @@ -5,14 +5,17 @@ package software.amazon.smithy.rust.lang +import io.kotest.matchers.collections.shouldContain import io.kotest.matchers.string.shouldContain import org.junit.jupiter.api.Test import software.amazon.smithy.codegen.core.SymbolProvider import software.amazon.smithy.model.Model import software.amazon.smithy.model.shapes.SetShape import software.amazon.smithy.model.shapes.StringShape +import software.amazon.smithy.rust.codegen.lang.RustDependency import software.amazon.smithy.rust.codegen.lang.RustWriter import software.amazon.smithy.rust.codegen.lang.rustBlock +import software.amazon.smithy.rust.codegen.smithy.RuntimeType import software.amazon.smithy.rust.codegen.smithy.SymbolVisitor import software.amazon.smithy.rust.testutil.quickTest import software.amazon.smithy.rust.testutil.shouldCompile @@ -28,6 +31,18 @@ class RustWriterTest { sut.toString().shouldMatchResource(javaClass, "empty.rs") } + @Test + fun `inner modules correctly handle dependencies`() { + val sut = RustWriter.forModule("lib") + val requestBuilder = RuntimeType.HttpRequestBuilder + sut.withModule("inner") { + rustBlock("fn build(builer: \$T)", requestBuilder) { + } + } + val httpDep = RustDependency.Http.dependencies[0] + sut.dependencies shouldContain httpDep + } + @Test fun `manually created struct`() { val sut = RustWriter.forModule("lib") -- GitLab