diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 243ac99fbf92d61703011c1a95dc88f1d5e23def..a144b2593754ace864e401ae6584d7c95ae68e89 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -7,105 +7,105 @@ jobs: name: Kotlin style checks runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Set up JDK - uses: actions/setup-java@v1 - with: - java-version: 8 - - uses: actions/cache@v2 - with: - path: | - ~/.gradle/caches - ~/.gradle/wrapper - key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }} - restore-keys: | - ${{ runner.os }}-gradle- - - name: ktlint - run: ./gradlew ktlint + - uses: actions/checkout@v2 + - name: Set up JDK + uses: actions/setup-java@v1 + with: + java-version: 8 + - uses: actions/cache@v2 + with: + path: | + ~/.gradle/caches + ~/.gradle/wrapper + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }} + restore-keys: | + ${{ runner.os }}-gradle- + - name: ktlint + run: ./gradlew ktlint unit-tests: name: Codegen unit tests runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions/cache@v2 - with: - path: | - ~/.gradle/caches - ~/.gradle/wrapper - key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }} - restore-keys: | - ${{ runner.os }}-gradle- - - uses: actions/cache@v2 - with: - path: | - ~/.cargo/registry - ~/.cargo/git - target - key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} - - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - - name: Set up JDK - uses: actions/setup-java@v1 - with: - java-version: 8 - - name: test - run: ./gradlew :codegen:test + - uses: actions/checkout@v2 + - uses: actions/cache@v2 + with: + path: | + ~/.gradle/caches + ~/.gradle/wrapper + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }} + restore-keys: | + ${{ runner.os }}-gradle- + - uses: actions/cache@v2 + with: + path: | + ~/.cargo/registry + ~/.cargo/git + target + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + - uses: actions-rs/toolchain@v1 + with: + toolchain: stable + - name: Set up JDK + uses: actions/setup-java@v1 + with: + java-version: 8 + - name: test + run: ./gradlew :codegen:test integration-tests: name: Codegen integration tests runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions/cache@v2 - name: Gradle Cache - with: - path: | - ~/.gradle/caches - ~/.gradle/wrapper - key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }} - restore-keys: | - ${{ runner.os }}-gradle- - - uses: actions/cache@v2 - name: Cargo Cache - with: - path: | - ~/.cargo/registry - ~/.cargo/git - target - key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} - - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - - name: Set up JDK - uses: actions/setup-java@v1 - with: - java-version: 8 - - name: integration-tests - run: ./gradlew :codegen-test:test - - uses: actions/upload-artifact@v2 - name: Upload Codegen Output for inspection + - uses: actions/checkout@v2 + - uses: actions/cache@v2 + name: Gradle Cache + with: + path: | + ~/.gradle/caches + ~/.gradle/wrapper + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }} + restore-keys: | + ${{ runner.os }}-gradle- + - uses: actions/cache@v2 + name: Cargo Cache + with: + path: | + ~/.cargo/registry + ~/.cargo/git + target + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + - uses: actions-rs/toolchain@v1 + with: + toolchain: stable + - name: Set up JDK + uses: actions/setup-java@v1 + with: + java-version: 8 + - name: integration-tests + run: ./gradlew :codegen-test:test + - uses: actions/upload-artifact@v2 + name: Upload Codegen Output for inspection # Always upload the output even if the tests failed - if: ${{ always() }} - with: - name: codegen-output - path: | - codegen-test/build/smithyprojections/codegen-test/*/rust-codegen/ - codegen-test/build/smithyprojections/codegen-test/Cargo.toml - !**/target + if: ${{ always() }} + with: + name: codegen-output + path: | + codegen-test/build/smithyprojections/codegen-test/*/rust-codegen/ + codegen-test/build/smithyprojections/codegen-test/Cargo.toml + !**/target runtime-tests: name: Rust runtime tests runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions/cache@v2 - with: - path: | - ~/.cargo/registry - ~/.cargo/git - target - key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} - - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - - name: execute runtime tests - run: ./rust-runtime/test.sh + - uses: actions/checkout@v2 + - uses: actions/cache@v2 + with: + path: | + ~/.cargo/registry + ~/.cargo/git + target + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + - uses: actions-rs/toolchain@v1 + with: + toolchain: stable + - name: execute runtime tests + run: ./rust-runtime/test.sh diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000000000000000000000000000000000000..64d434f5f9cc1d5fc6db67fa380a4d4de47ca2d0 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,14 @@ +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v2.3.0 + hooks: + - id: check-yaml + - id: end-of-file-fixer + - id: trailing-whitespace +- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks + rev: v1.6.1 + hooks: + - id: pretty-format-kotlin + args: [--autofix, --ktlint-version, 0.39.0] + - id: pretty-format-yaml + args: [--autofix, --indent, '2'] diff --git a/README.md b/README.md index 09841162d6b17a2299b17c38514b17dead2be04e..96bd70574d2bbe91b657f2c475d3095d044f6a35 100644 --- a/README.md +++ b/README.md @@ -3,10 +3,17 @@ Smithy code generators for Rust ## Setup 1. `./gradlew` will setup gradle for you -2. Running tests requires a working Rust installation. See [Rust docs](https://www.rust-lang.org/learn/get-started) for +2. Running tests requires a working Rust installation. See [Rust docs](https://www.rust-lang.org/learn/get-started) for installation instructions on your platform. -## Run tests +## Run tests ```./tesh.sh``` -This will run all the unit tests, codegen an example model end-to-end and validates that the generated code compiles. \ No newline at end of file +This will run all the unit tests, codegen an example model end-to-end and validates that the generated code compiles. + +## Development +For development, pre-commit hooks may be useful. Setup: +``` +brew install pre-commit # (or appropriate for your platform: https://pre-commit.com/) +pre-commit install +``` diff --git a/codegen-test/build.gradle.kts b/codegen-test/build.gradle.kts index 7efd698c795f1b5ab613972b2bd400e92fac3ad0..15f72a0d0637f3e5afc857819e0700a7d424fbae 100644 --- a/codegen-test/build.gradle.kts +++ b/codegen-test/build.gradle.kts @@ -33,8 +33,8 @@ fun generateSmithyBuild(tests: List): String { val projections = tests.joinToString(",\n") { """ "${it.module}": { - "plugins": { - "rust-codegen": { + "plugins": { + "rust-codegen": { "runtimeConfig": { "relativePath": "${rootProject.projectDir.absolutePath}/rust-runtime" }, @@ -44,7 +44,7 @@ fun generateSmithyBuild(tests: List): String { "build": { "rootProject": true } - } + } } } """.trimIndent() diff --git a/codegen-test/model/dynamodb.json b/codegen-test/model/dynamodb.json index 2adaae28a70d486d0ca66978acdd88146d869677..09cb632f567c1f4573117083629817544dedbbce 100644 --- a/codegen-test/model/dynamodb.json +++ b/codegen-test/model/dynamodb.json @@ -7799,4 +7799,4 @@ } } } -} \ No newline at end of file +} diff --git a/codegen-test/model/ebs.json b/codegen-test/model/ebs.json index 19154367be67e5a8ce9495bbd308a10161068ac1..78ff288a5847079a69d757a7ab0067df52b7cc49 100644 --- a/codegen-test/model/ebs.json +++ b/codegen-test/model/ebs.json @@ -1347,4 +1347,4 @@ } } } -} \ No newline at end of file +} diff --git a/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/lang/RustTypes.kt b/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/lang/RustTypes.kt index 7af33c2897402f21ef0d5af680d3c97bd38e9499..dba602aed095e502a9af2b8f453ffbbf576713ad 100644 --- a/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/lang/RustTypes.kt +++ b/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/lang/RustTypes.kt @@ -61,15 +61,15 @@ sealed class RustType { } fun RustType.render(): String = when (this) { - is RustType.Bool -> this.name - is RustType.Float -> this.name - is RustType.Integer -> this.name - is RustType.String -> this.name - is RustType.Vec -> "${this.name}<${this.member.render()}>" - is RustType.HashMap -> "${this.name}<${this.key.render()}, ${this.value.render()}>" - is RustType.HashSet -> "${this.name}<${this.member.render()}>" - is RustType.Reference -> "&${this.lifetime?.let { "'$it" } ?: ""} ${this.value.render()}" - is RustType.Option -> "${this.name}<${this.value.render()}>" - is RustType.Box -> "${this.name}<${this.value.render()}>" - is RustType.Opaque -> this.name + is RustType.Bool -> this.name + is RustType.Float -> this.name + is RustType.Integer -> this.name + is RustType.String -> this.name + is RustType.Vec -> "${this.name}<${this.member.render()}>" + is RustType.HashMap -> "${this.name}<${this.key.render()}, ${this.value.render()}>" + is RustType.HashSet -> "${this.name}<${this.member.render()}>" + is RustType.Reference -> "&${this.lifetime?.let { "'$it" } ?: ""} ${this.value.render()}" + is RustType.Option -> "${this.name}<${this.value.render()}>" + is RustType.Box -> "${this.name}<${this.value.render()}>" + is RustType.Opaque -> this.name } 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 cb18ce105f2db39397450eaaa5ee7515df205dba..2ff70bb1c11370e34377d9ff6cc254cff411a02a 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 @@ -5,7 +5,6 @@ package software.amazon.smithy.rust.codegen.lang -import java.util.function.BiFunction import software.amazon.smithy.codegen.core.CodegenException import software.amazon.smithy.codegen.core.Symbol import software.amazon.smithy.codegen.core.writer.CodegenWriter @@ -17,6 +16,7 @@ import software.amazon.smithy.rust.codegen.smithy.RuntimeType import software.amazon.smithy.rust.codegen.smithy.isOptional import software.amazon.smithy.rust.codegen.smithy.rustType import software.amazon.smithy.utils.CodeWriter +import java.util.function.BiFunction fun T.withBlock( textBeforeNewLine: String, diff --git a/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/lang/UseDeclarations.kt b/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/lang/UseDeclarations.kt index 6372b0347bb4a694b1b77d9a63d10a6e199b3413..e7a59006f45b27e301c8a45e58dd183530926541 100644 --- a/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/lang/UseDeclarations.kt +++ b/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/lang/UseDeclarations.kt @@ -27,10 +27,10 @@ class UseDeclarations(private val filename: String, private val namespace: Strin private data class UseStatement(val moduleName: String, val symbolName: String, val alias: String) { val rendered: String - get() { - val alias = alias.let { if (it == symbolName) "" else " as $it" } - return "use $moduleName::$symbolName$alias;" - } + get() { + val alias = alias.let { if (it == symbolName) "" else " as $it" } + return "use $moduleName::$symbolName$alias;" + } override fun toString(): String = rendered } diff --git a/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/CodegenVisitor.kt b/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/CodegenVisitor.kt index 86ae3566dbf445413c302be710c307e6dc3bfdb4..cc3984a0cd92d9968ede5af1667fcd9d72ad7304 100644 --- a/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/CodegenVisitor.kt +++ b/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/CodegenVisitor.kt @@ -5,7 +5,6 @@ package software.amazon.smithy.rust.codegen.smithy -import java.util.logging.Logger import software.amazon.smithy.build.PluginContext import software.amazon.smithy.codegen.core.SymbolProvider import software.amazon.smithy.codegen.core.writer.CodegenWriterDelegator @@ -29,6 +28,7 @@ import software.amazon.smithy.rust.codegen.smithy.generators.UnionGenerator import software.amazon.smithy.rust.codegen.smithy.transformers.OperationNormalizer import software.amazon.smithy.rust.codegen.util.CommandFailed import software.amazon.smithy.rust.codegen.util.runCommand +import java.util.logging.Logger private val PublicModules = listOf("error", "operation", "model") diff --git a/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/RuntimeTypes.kt b/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/RuntimeTypes.kt index c3df3fd497ca3c2940e15868804ffee68eef48c3..fe082b0f3a5af806892d832fa06be9c7e1e2f4c8 100644 --- a/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/RuntimeTypes.kt +++ b/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/RuntimeTypes.kt @@ -5,13 +5,13 @@ package software.amazon.smithy.rust.codegen.smithy -import java.io.File -import java.util.Optional import software.amazon.smithy.codegen.core.Symbol import software.amazon.smithy.model.node.ObjectNode import software.amazon.smithy.model.traits.TimestampFormatTrait import software.amazon.smithy.rust.codegen.lang.RustDependency import software.amazon.smithy.rust.codegen.lang.RustType +import java.io.File +import java.util.Optional data class RuntimeConfig(val cratePrefix: String = "smithy", val relativePath: String = "../") { companion object { diff --git a/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/RustSettings.kt b/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/RustSettings.kt index 26db80edaf0640e1f3a071dc5a5278420c052b3f..ff834be710fb6e5e5e1347aeef53d65359a2a1ad 100644 --- a/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/RustSettings.kt +++ b/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/RustSettings.kt @@ -5,9 +5,6 @@ package software.amazon.smithy.rust.codegen.smithy -import java.util.Optional -import java.util.logging.Logger -import kotlin.streams.toList import software.amazon.smithy.codegen.core.CodegenException import software.amazon.smithy.model.Model import software.amazon.smithy.model.knowledge.ServiceIndex @@ -16,6 +13,9 @@ import software.amazon.smithy.model.node.StringNode import software.amazon.smithy.model.shapes.ServiceShape import software.amazon.smithy.model.shapes.Shape import software.amazon.smithy.model.shapes.ShapeId +import java.util.Optional +import java.util.logging.Logger +import kotlin.streams.toList private const val SERVICE = "service" private const val MODULE_NAME = "module" @@ -86,13 +86,13 @@ class RustSettings( services.isEmpty() -> { throw CodegenException( "Cannot infer a service to generate because the model does not " + - "contain any service shapes" + "contain any service shapes" ) } services.size > 1 -> { throw CodegenException( "Cannot infer service to generate because the model contains " + - "multiple service shapes: " + services + "multiple service shapes: " + services ) } else -> { @@ -123,7 +123,8 @@ class RustSettings( val protocol = resolvedProtocols.firstOrNull(supportedProtocolTraits::contains) return protocol ?: throw UnresolvableProtocolException( "The ${service.id} service supports the following unsupported protocols $resolvedProtocols. " + - "The following protocol generators were found on the class path: $supportedProtocolTraits") + "The following protocol generators were found on the class path: $supportedProtocolTraits" + ) } } diff --git a/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/generators/EnumGenerator.kt b/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/generators/EnumGenerator.kt index 0467ea29df9ba475df19186bb0ef7b5fed2fe5ad..b00fe0b02c1db4a9a831617451b2a232e6289b54 100644 --- a/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/generators/EnumGenerator.kt +++ b/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/generators/EnumGenerator.kt @@ -5,7 +5,6 @@ package software.amazon.smithy.rust.codegen.smithy.generators -import java.lang.IllegalStateException import software.amazon.smithy.codegen.core.SymbolProvider import software.amazon.smithy.model.shapes.StringShape import software.amazon.smithy.model.traits.EnumDefinition @@ -15,6 +14,7 @@ import software.amazon.smithy.rust.codegen.lang.rustBlock import software.amazon.smithy.rust.codegen.lang.withBlock import software.amazon.smithy.rust.codegen.smithy.RuntimeType import software.amazon.smithy.rust.codegen.util.doubleQuote +import java.lang.IllegalStateException class EnumGenerator( symbolProvider: SymbolProvider, diff --git a/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/generators/HttpTraitBindingGenerator.kt b/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/generators/HttpTraitBindingGenerator.kt index ae4d8873335b96c3d788a355b818f3c7689b5dec..125c597ff877a8010e6cfb8333821ba01f74fcca 100644 --- a/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/generators/HttpTraitBindingGenerator.kt +++ b/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/generators/HttpTraitBindingGenerator.kt @@ -76,9 +76,11 @@ class HttpTraitBindingGenerator( uriBase(implBlockWriter) val hasHeaders = addHeaders(implBlockWriter) val hasQuery = uriQuery(implBlockWriter) - implBlockWriter.rustBlock("fn update_http_builder(&self, builder: \$T) -> \$T", + implBlockWriter.rustBlock( + "fn update_http_builder(&self, builder: \$T) -> \$T", RuntimeType.HttpRequestBuilder, - RuntimeType.HttpRequestBuilder) { + RuntimeType.HttpRequestBuilder + ) { write("let mut uri = String::new();") write("self.uri_base(&mut uri);") if (hasQuery) { @@ -205,11 +207,11 @@ class HttpTraitBindingGenerator( val target = model.expectShape(targetId) write( "params.push((${param.locationName.dq()}, ${ - paramFmtFun( - target, - memberShape, - innerField - ) + paramFmtFun( + target, + memberShape, + innerField + ) }))" ) } diff --git a/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/generators/UnionGenerator.kt b/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/generators/UnionGenerator.kt index bd230ec90dbb742c4f1620e3114e1f27bc163b9c..b1eed4e9292c3ca6eb2461db2fc53b561e881121 100644 --- a/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/generators/UnionGenerator.kt +++ b/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/generators/UnionGenerator.kt @@ -28,7 +28,8 @@ class UnionGenerator( writer.write("#[derive(Debug, PartialEq, Clone)]") val blockWriter = writer.openBlock("pub enum ${symbol.name} {") sortedMembers.forEach { member -> - blockWriter.write("${member.memberName.toPascalCase()}(\$T),", symbolProvider.toSymbol(member)) } + blockWriter.write("${member.memberName.toPascalCase()}(\$T),", symbolProvider.toSymbol(member)) + } blockWriter.closeBlock("}") } } diff --git a/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/traits/SyntheticInput.kt b/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/traits/SyntheticInput.kt index 55b556b6ef184f40c252d7d902227ccbdad24db6..e58616ba40045a0f54047726652979fabe8ef2ba 100644 --- a/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/traits/SyntheticInput.kt +++ b/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/traits/SyntheticInput.kt @@ -21,7 +21,8 @@ class SyntheticInput @JvmOverloads constructor(node: ObjectNode? = Node.objectNo SyntheticInput( node ) - }) + } + ) companion object { val ID = ShapeId.from("smithy.api.internal#synthetic") diff --git a/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/transformers/OperationNormalizer.kt b/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/transformers/OperationNormalizer.kt index 4b47730ee1080266c7255c096d0b460fa3c3b736..236f24130a286ceaa8f2c6e45db3a6209d60abbe 100644 --- a/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/transformers/OperationNormalizer.kt +++ b/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/transformers/OperationNormalizer.kt @@ -5,8 +5,6 @@ package software.amazon.smithy.rust.codegen.smithy.transformers -import java.util.Optional -import kotlin.streams.toList import software.amazon.smithy.codegen.core.SymbolProvider import software.amazon.smithy.model.Model import software.amazon.smithy.model.shapes.OperationShape @@ -15,6 +13,8 @@ import software.amazon.smithy.model.shapes.ShapeId import software.amazon.smithy.model.shapes.StructureShape import software.amazon.smithy.model.transform.ModelTransformer import software.amazon.smithy.rust.codegen.smithy.traits.SyntheticInput +import java.util.Optional +import kotlin.streams.toList /** * Generate synthetic Input and Output structures for operations. diff --git a/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/util/Exec.kt b/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/util/Exec.kt index 3eebe6bada95a99ef622b76bb44cef613b99d1d5..5695bc4a55f26a122004f878d0e784cb0cbb49bd 100644 --- a/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/util/Exec.kt +++ b/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/util/Exec.kt @@ -5,9 +5,9 @@ package software.amazon.smithy.rust.codegen.util +import software.amazon.smithy.rust.codegen.smithy.letIf import java.nio.file.Path import java.util.concurrent.TimeUnit -import software.amazon.smithy.rust.codegen.smithy.letIf class CommandFailed(output: String) : Exception("Command Failed\n$output") diff --git a/codegen/src/test/kotlin/software/amazon/smithy/rust/codegen/SymbolBuilderTest.kt b/codegen/src/test/kotlin/software/amazon/smithy/rust/codegen/SymbolBuilderTest.kt index 0301a74e7da3bbbebd51d82b7155d3a2431f3825..514c34f9c195a2da48ecb7b6317b50ce3182019b 100644 --- a/codegen/src/test/kotlin/software/amazon/smithy/rust/codegen/SymbolBuilderTest.kt +++ b/codegen/src/test/kotlin/software/amazon/smithy/rust/codegen/SymbolBuilderTest.kt @@ -79,7 +79,7 @@ class SymbolBuilderTest { fun `creates enums`() { val model = """ namespace test - + @enum([ { value: "Count", 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 8d95a6453f7ba3c7c1e073158630c0007b0d8370..5aadec4a0816841f51dc8173fbfcc7e5ca85d658 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 @@ -28,10 +28,10 @@ class EnumGeneratorTest { .addEnum(EnumDefinition.builder().value("t2.nano").name("T2_NANO").build()) .addEnum( EnumDefinition.builder().value("t2.micro").name("T2_MICRO").documentation( - "T2 instances are Burstable Performance\n" + - "Instances that provide a baseline level of CPU\n" + - "performance with the ability to burst above the\n" + - "baseline." + "T2 instances are Burstable Performance\n" + + "Instances that provide a baseline level of CPU\n" + + "performance with the ability to burst above the\n" + + "baseline." ).build() ) .build() @@ -53,14 +53,16 @@ class EnumGeneratorTest { val result = writer.toString() result.shouldParseAsRust() result.shouldCompile() - result.quickTest(""" + result.quickTest( + """ let instance = InstanceType::T2Micro; assert_eq!(instance.as_str(), "t2.micro"); assert_eq!(InstanceType::from("t2.nano"), InstanceType::T2Nano); assert_eq!(InstanceType::from("other"), InstanceType::Unknown("other".to_owned())); // round trip unknown variants: assert_eq!(InstanceType::from("other").as_str(), "other"); - """.trimIndent()) + """.trimIndent() + ) } @Test @@ -92,9 +94,11 @@ class EnumGeneratorTest { val writer = RustWriter.forModule("model") val generator = EnumGenerator(provider, writer, shape, trait) generator.render() - writer.shouldCompile(""" + writer.shouldCompile( + """ // Values should be sorted assert_eq!(FooEnum::${EnumGenerator.Values}(), ["0", "1", "Bar", "Baz", "Foo"]); - """) + """ + ) } } diff --git a/codegen/src/test/kotlin/software/amazon/smithy/rust/codegen/generators/HttpTraitBindingGeneratorTest.kt b/codegen/src/test/kotlin/software/amazon/smithy/rust/codegen/generators/HttpTraitBindingGeneratorTest.kt index 986119377276ad7df2edc7ba911bc7d2579bf5e0..052267ac7d4377e4fa50a26b9d1db09621e44cce 100644 --- a/codegen/src/test/kotlin/software/amazon/smithy/rust/codegen/generators/HttpTraitBindingGeneratorTest.kt +++ b/codegen/src/test/kotlin/software/amazon/smithy/rust/codegen/generators/HttpTraitBindingGeneratorTest.kt @@ -41,15 +41,15 @@ class HttpTraitBindingGeneratorTest { operation PutObject { input: PutObjectRequest } - + list Extras { member: Integer } - + list Dates { member: Timestamp } - + @mediaType("video/quicktime") string Video @@ -67,17 +67,17 @@ class HttpTraitBindingGeneratorTest { // Sent in the X-Dates header @httpHeader("X-Dates") dateHeaderList: Dates, - + @httpHeader("X-Ints") intList: Extras, - + @httpHeader("X-MediaType") mediaType: Video, // Sent in the query string as paramName @httpQuery("paramName") someValue: String, - + @httpQuery("hello") extras: Extras, @@ -97,9 +97,11 @@ class HttpTraitBindingGeneratorTest { private val symbolProvider = testSymbolProvider(model) private fun renderOperation(writer: RustWriter) { StructureGenerator(model, symbolProvider, writer, inputShape).render() - HttpTraitBindingGenerator(model, + HttpTraitBindingGenerator( + model, symbolProvider, - TestRuntimeConfig, writer, operationShape, inputShape, httpTrait) + TestRuntimeConfig, writer, operationShape, inputShape, httpTrait + ) .Default().render() } @@ -128,7 +130,7 @@ class HttpTraitBindingGeneratorTest { o.clear(); inp.uri_query(&mut o); assert_eq!(o.as_str(), "?paramName=svq!!%25%26&hello=0&hello=1&hello=2&hello=44") - """.trimIndent() + """.trimIndent() ) } @@ -154,10 +156,10 @@ class HttpTraitBindingGeneratorTest { let mut date_header = http_request.headers().get_all("X-Dates").iter(); assert_eq!(date_header.next().unwrap(), "Tue, 28 Apr 1970 03:58:45 GMT"); assert_eq!(date_header.next(), None); - + let int_header = http_request.headers().get_all("X-Ints").iter().map(|hv|hv.to_str().unwrap()).collect::>(); assert_eq!(int_header, vec!["0", "1", "44"]); - + let base64_header = http_request.headers().get_all("X-MediaType").iter().map(|hv|hv.to_str().unwrap()).collect::>(); assert_eq!(base64_header, vec!["YmFzZTY0ZW5jb2RldGhpcw=="]); """ 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 e9b6bf9b707966b442c8f91331b7d3ebaac7299b..f971d00149fa4daaa6dc9be496b4996e5d59b677 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 @@ -33,11 +33,11 @@ class StructureGeneratorTest { inner: Inner, byteValue: Byte } - + // Intentionally empty structure Inner { } - + @error("server") structure MyError { message: String @@ -55,10 +55,11 @@ class StructureGeneratorTest { val generator = StructureGenerator(model, provider, writer, struct) generator.render() innerGenerator.render() - writer.shouldCompile(""" + writer.shouldCompile( + """ let s: Option = None; s.map(|i|println!("{:?}, {:?}", i.ts, i.byte_value)); - """.trimIndent() + """.trimIndent() ) } 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 0509d520e7c8501b68e96f3a1d66b2c3763b756b..3009673a009fd5fd4fbfee48b593b8eec0c6bd13 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 @@ -25,8 +25,8 @@ class UnionGeneratorTest { .target("smithy.api#String").build() val member2 = MemberShape.builder().id("com.test#MyUnion\$intConfig") .target("smithy.api#PrimitiveInteger").addTrait( - DocumentationTrait("This *is* documentation about the member.") - ).build() + DocumentationTrait("This *is* documentation about the member.") + ).build() val union = UnionShape.builder() .id("com.test#MyUnion") diff --git a/codegen/src/test/kotlin/software/amazon/smithy/rust/codegen/smithy/generators/InstantiatorTest.kt b/codegen/src/test/kotlin/software/amazon/smithy/rust/codegen/smithy/generators/InstantiatorTest.kt index 0b7422b98f98692eaf285df9a430a8484efe3fae..e2d075b2d954658ce4b0ee4212b632d7f354974d 100644 --- a/codegen/src/test/kotlin/software/amazon/smithy/rust/codegen/smithy/generators/InstantiatorTest.kt +++ b/codegen/src/test/kotlin/software/amazon/smithy/rust/codegen/smithy/generators/InstantiatorTest.kt @@ -25,26 +25,26 @@ class InstantiatorTest { ts: Timestamp, byteValue: Byte } - + list MyList { member: String } - + @sparse list MySparseList { member: String } - + union MyUnion { stringVariant: String, numVariant: Integer } - + structure Inner { map: NestedMap } - - + + map NestedMap { key: String, value: Inner @@ -60,9 +60,11 @@ class InstantiatorTest { fun `generate unions`() { val union = model.lookup("com.test#MyUnion") val sut = Instantiator(symbolProvider, model, runtimeConfig) - val data = Node.parse("""{ + val data = Node.parse( + """{ "stringVariant": "ok!" - }""") + }""" + ) val writer = RustWriter.forModule("model") UnionGenerator(model, symbolProvider, writer, union).render() writer.write("#[test]") @@ -78,11 +80,13 @@ class InstantiatorTest { fun `generate struct builders`() { val structure = model.lookup("com.test#MyStruct") val sut = Instantiator(symbolProvider, model, runtimeConfig) - val data = Node.parse(""" { + val data = Node.parse( + """ { "bar": 10, "foo": "hello" } - """.trimIndent()) + """.trimIndent() + ) val writer = RustWriter.forModule("model") val structureGenerator = StructureGenerator(model, symbolProvider, writer, structure) structureGenerator.render() @@ -99,11 +103,13 @@ class InstantiatorTest { @Test fun `generate lists`() { - val data = Node.parse(""" [ + val data = Node.parse( + """ [ "bar", "foo" ] - """) + """ + ) val writer = RustWriter.forModule("lib") val sut = Instantiator(symbolProvider, model, runtimeConfig) writer.write("#[test]") @@ -118,12 +124,14 @@ class InstantiatorTest { @Test fun `generate sparse lists`() { - val data = Node.parse(""" [ + val data = Node.parse( + """ [ "bar", "foo", null ] - """) + """ + ) val writer = RustWriter.forModule("lib") val sut = Instantiator(symbolProvider, model, runtimeConfig) writer.write("#[test]") @@ -138,12 +146,14 @@ class InstantiatorTest { @Test fun `generate maps of maps`() { - val data = Node.parse("""{ + val data = Node.parse( + """{ "k1": { "map": {} }, "k2": { "map": { "k3": {} } }, "k3": { } } - """) + """ + ) val writer = RustWriter.forModule("model") val sut = Instantiator(symbolProvider, model, runtimeConfig) val structureGenerator = StructureGenerator(model, symbolProvider, writer, model.lookup("com.test#Inner")) @@ -153,12 +163,14 @@ class InstantiatorTest { writer.withBlock("let result = ", ";") { sut.render(data, model.lookup("com.test#NestedMap"), writer) } - writer.write(""" + writer.write( + """ assert_eq!(result.len(), 3); assert_eq!(result.get("k1").unwrap().map.as_ref().unwrap().len(), 0); assert_eq!(result.get("k2").unwrap().map.as_ref().unwrap().len(), 1); assert_eq!(result.get("k3").unwrap().map, None); - """) + """ + ) } writer.shouldCompile(strict = true) } diff --git a/codegen/src/test/kotlin/software/amazon/smithy/rust/testutil/TestHelpers.kt b/codegen/src/test/kotlin/software/amazon/smithy/rust/testutil/TestHelpers.kt index 695804753576399cbbb41edf0a0730e9fb50fa78..4af06e6f77b8521a477351b6a1a0e891f745644f 100644 --- a/codegen/src/test/kotlin/software/amazon/smithy/rust/testutil/TestHelpers.kt +++ b/codegen/src/test/kotlin/software/amazon/smithy/rust/testutil/TestHelpers.kt @@ -5,7 +5,6 @@ package software.amazon.smithy.rust.testutil -import java.io.File import software.amazon.smithy.codegen.core.SymbolProvider import software.amazon.smithy.model.Model import software.amazon.smithy.rust.codegen.smithy.RuntimeConfig @@ -13,6 +12,7 @@ import software.amazon.smithy.rust.codegen.smithy.SymbolVisitor import software.amazon.smithy.rust.codegen.smithy.SymbolVisitorConfig import software.amazon.smithy.rust.codegen.smithy.letIf import software.amazon.smithy.rust.codegen.util.dq +import java.io.File val TestRuntimeConfig = RuntimeConfig(relativePath = File("../rust-runtime/").absolutePath) val TestSymbolVisitorConfig = SymbolVisitorConfig(runtimeConfig = TestRuntimeConfig, handleOptionality = true, handleRustBoxing = true) diff --git a/gradle.properties b/gradle.properties index c34692fdff4a4d30db4f87b70f60e3f7eb820061..cb352daea36014c6a08dc51bc91711ed4bb8ca75 100644 --- a/gradle.properties +++ b/gradle.properties @@ -20,6 +20,5 @@ ktorVersion=1.3.2 # testing/utility # FIXME - junit5 not working junitVersion=4.12 -ktlintVersion=0.36.0 +ktlintVersion=0.39.0 kotestVersion=4.2.6 - diff --git a/gradle/maincodecoverage.gradle b/gradle/maincodecoverage.gradle index 4cd06e16123f91457656f89e56175e6795f878e4..c140ce1d33108490f37bd92298ce50e186ab566a 100644 --- a/gradle/maincodecoverage.gradle +++ b/gradle/maincodecoverage.gradle @@ -68,4 +68,4 @@ task testCoverageMain(type: JacocoReport) { html.enabled true html.destination file("${buildDir}/jacoco-reports/html") } -} \ No newline at end of file +} diff --git a/rust-runtime/protocol-test-helpers/Cargo.toml b/rust-runtime/protocol-test-helpers/Cargo.toml index fcffcaf545ce930f4495f4e0a692223391865030..82d83a4c00186fe81f6778c33315fe119d62289d 100644 --- a/rust-runtime/protocol-test-helpers/Cargo.toml +++ b/rust-runtime/protocol-test-helpers/Cargo.toml @@ -6,4 +6,4 @@ edition = "2018" description = "A collection of library functions to validate HTTP requests against Smithy protocol tests" [dependencies] -http = "0.2.1" \ No newline at end of file +http = "0.2.1" diff --git a/rust-runtime/smithy-http/Cargo.toml b/rust-runtime/smithy-http/Cargo.toml index ae8fb2dffe49d10aa862b8f3afe25f9d9959fa63..7dd147d0997822eb2cce43c998549c227f9529ea 100644 --- a/rust-runtime/smithy-http/Cargo.toml +++ b/rust-runtime/smithy-http/Cargo.toml @@ -9,4 +9,4 @@ smithy-types = { path = "../smithy-types" } [dev-dependencies] proptest = "0.10.1" -base64 = "0.13.0" \ No newline at end of file +base64 = "0.13.0" diff --git a/rust-runtime/smithy-types/Cargo.toml b/rust-runtime/smithy-types/Cargo.toml index 109b3273d856cfac69af4d21b8fc3e9c7e79756a..ae28120fe0d1f212c888811546742684abcd971f 100644 --- a/rust-runtime/smithy-types/Cargo.toml +++ b/rust-runtime/smithy-types/Cargo.toml @@ -6,4 +6,4 @@ edition = "2018" [dependencies] chrono = "0.4" -httpdate = "0.3.2" \ No newline at end of file +httpdate = "0.3.2" diff --git a/rust-runtime/test.sh b/rust-runtime/test.sh index c3312732a05c2b0d68f4a9bf04cb8476e9301386..ff0dbdddb2d56b27eba8e0f2233caa38a0327e5e 100755 --- a/rust-runtime/test.sh +++ b/rust-runtime/test.sh @@ -7,4 +7,4 @@ do (cd "$crate" && cargo fmt -- --check) (cd "$crate" && cargo clippy -- -D warnings) (cd "$crate" && cargo test) -done \ No newline at end of file +done diff --git a/test.sh b/test.sh index 3935e22d9ecb1537d9bbe92fce4fafb33d6ee725..97bf71a961eaa7fc8d36b2400d844be60523c896 100755 --- a/test.sh +++ b/test.sh @@ -7,4 +7,4 @@ set -e ./gradlew test ./gradlew ktlintFormat -./gradlew ktlint \ No newline at end of file +./gradlew ktlint