From 8565bf244f5f5bae4edfa0a7f418284eeba22c4d Mon Sep 17 00:00:00 2001 From: Thomas Cameron Date: Thu, 22 Jun 2023 08:43:56 +0000 Subject: [PATCH 01/24] test --- .../smithy/rust/codegen/core/testutil/Rust.kt | 27 ++++++++++++++----- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt index fa98e87fcb..fe284706d7 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt @@ -42,6 +42,19 @@ import java.nio.file.Files.createTempDirectory import java.nio.file.Path import kotlin.io.path.absolutePathString +object Commands { + val CargoEnvDWarnings = mapOf( + "RUSTFLAGS" to "-D warnings --cfg aws_sdk_unstable", + ) + val CargoEnvDDeadCode = mapOf( + "RUSTFLAGS" to "-A dead_code --cfg aws_sdk_unstable", + ) + const val CargoTest = "cargo test --all-features" + const val CargoCheck = "cargo check --all-features" + const val CargoFmt = "cargo fmt " + const val CargoClippy = "cargo clippy" +} + val TestModuleDocProvider = object : ModuleDocProvider { override fun docsWriter(module: RustModule.LeafModule): Writable = writable { docs("Some test documentation\n\nSome more details...") @@ -332,14 +345,14 @@ fun TestWriterDelegator.compileAndTest( println("Generated files:") printGeneratedFiles() try { - "cargo fmt".runCommand(baseDir) + Commands.CargoFmt.runCommand(baseDir) } catch (e: Exception) { // cargo fmt errors are useless, ignore } - val env = mapOf("RUSTFLAGS" to "-A dead_code") - val testOutput = "cargo test".runCommand(baseDir, env) + val env = Commands.CargoEnvDDeadCode + val testOutput = Commands.CargoTest.runCommand(baseDir, env) if (runClippy) { - "cargo clippy".runCommand(baseDir, env) + Commands.CargoClippy.runCommand(baseDir, env) } return testOutput } @@ -379,9 +392,9 @@ fun RustWriter.compileAndTest( val testModule = tempDir.resolve("src/$module.rs") try { val testOutput = if ((mainRs.readText() + testModule.readText()).contains("#[test]")) { - "cargo test".runCommand(tempDir.toPath()) + Commands.CargoTest.runCommand(tempDir.toPath()) } else { - "cargo check".runCommand(tempDir.toPath()) + Commands.CargoCheck.runCommand(tempDir.toPath()) } if (expectFailure) { println("Test sources for debugging: file://${testModule.absolutePath}") @@ -488,4 +501,4 @@ fun TestWriterDelegator.unitTest(test: Writable): TestWriterDelegator { return this } -fun String.runWithWarnings(crate: Path) = this.runCommand(crate, mapOf("RUSTFLAGS" to "-D warnings")) +fun String.runWithWarnings(crate: Path) = this.runCommand(crate, Commands.CargoEnvDWarnings) From f578b863ff00379d94a739721bde6808cf2b7a29 Mon Sep 17 00:00:00 2001 From: Thomas Cameron Date: Fri, 23 Jun 2023 01:57:11 +0900 Subject: [PATCH 02/24] Update codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt Co-authored-by: Zelda Hessler --- .../software/amazon/smithy/rust/codegen/core/testutil/Rust.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt index fe284706d7..93da546df8 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt @@ -51,7 +51,7 @@ object Commands { ) const val CargoTest = "cargo test --all-features" const val CargoCheck = "cargo check --all-features" - const val CargoFmt = "cargo fmt " + const val CargoFmt = "cargo fmt" const val CargoClippy = "cargo clippy" } From d614f5f39bbdd7cadb70018076eb54ccdb238d1f Mon Sep 17 00:00:00 2001 From: Thomas Cameron Date: Thu, 29 Jun 2023 10:54:26 +0000 Subject: [PATCH 03/24] Rust.kt --- .../smithy/rust/codegen/core/testutil/Rust.kt | 61 ++++++++++++++----- 1 file changed, 47 insertions(+), 14 deletions(-) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt index fe284706d7..60f6f2309b 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt @@ -42,16 +42,46 @@ import java.nio.file.Files.createTempDirectory import java.nio.file.Path import kotlin.io.path.absolutePathString +// cargo commands and env values object Commands { - val CargoEnvDWarnings = mapOf( - "RUSTFLAGS" to "-D warnings --cfg aws_sdk_unstable", - ) - val CargoEnvDDeadCode = mapOf( - "RUSTFLAGS" to "-A dead_code --cfg aws_sdk_unstable", - ) - const val CargoTest = "cargo test --all-features" - const val CargoCheck = "cargo check --all-features" - const val CargoFmt = "cargo fmt " + private const val cfgUnstable = "--cfg aws_sdk_unstable" + fun cargoEnvDWarnings(enableUnstable: Boolean): Map { + var s = "-A dead_code " + if (enableUnstable) { + s += cfgUnstable + } + return mapOf( + "RUSTFLAGS" to s, + ) + } + + fun cargoEnvDDeadCode(enableUnstable: Boolean): Map { + var s = "-A dead_code " + if (enableUnstable) { + s += cfgUnstable + } + return mapOf( + "RUSTFLAGS" to s, + ) + } + + private const val allFeature = "--all-features" + + fun cargoTest(enableUnstable: Boolean): String { + var s = "cargo test" + if (enableUnstable) { + s += allFeature + } + return s + } + fun cargoCheck(enableUnstable: Boolean): String { + var s = "cargo check" + if (enableUnstable) { + s += allFeature + } + return s + } + const val CargoFmt = "cargo fmt" const val CargoClippy = "cargo clippy" } @@ -329,6 +359,7 @@ fun FileManifest.printGeneratedFiles() { fun TestWriterDelegator.compileAndTest( runClippy: Boolean = false, expectFailure: Boolean = false, + enableUnstableFlag: Boolean = false ): String { val stubModel = """ namespace fake @@ -349,8 +380,9 @@ fun TestWriterDelegator.compileAndTest( } catch (e: Exception) { // cargo fmt errors are useless, ignore } - val env = Commands.CargoEnvDDeadCode - val testOutput = Commands.CargoTest.runCommand(baseDir, env) + + val env = Commands.cargoEnvDDeadCode(enableUnstableFlag) + val testOutput = Commands.cargoTest(enableUnstableFlag).runCommand(baseDir, env) if (runClippy) { Commands.CargoClippy.runCommand(baseDir, env) } @@ -379,6 +411,7 @@ fun RustWriter.compileAndTest( main: String = "", clippy: Boolean = false, expectFailure: Boolean = false, + enableUnstable: Boolean = false ): String { val deps = this.dependencies.map { RustDependency.fromSymbolDependency(it) }.filterIsInstance() val module = if (this.namespace.contains("::")) { @@ -392,9 +425,9 @@ fun RustWriter.compileAndTest( val testModule = tempDir.resolve("src/$module.rs") try { val testOutput = if ((mainRs.readText() + testModule.readText()).contains("#[test]")) { - Commands.CargoTest.runCommand(tempDir.toPath()) + Commands.cargoTest(enableUnstable).runCommand(tempDir.toPath()) } else { - Commands.CargoCheck.runCommand(tempDir.toPath()) + Commands.cargoCheck(enableUnstable).runCommand(tempDir.toPath()) } if (expectFailure) { println("Test sources for debugging: file://${testModule.absolutePath}") @@ -501,4 +534,4 @@ fun TestWriterDelegator.unitTest(test: Writable): TestWriterDelegator { return this } -fun String.runWithWarnings(crate: Path) = this.runCommand(crate, Commands.CargoEnvDWarnings) +fun String.runWithWarnings(crate: Path, enableUnstableFlag: Boolean) = this.runCommand(crate, Commands.cargoEnvDWarnings(enableUnstableFlag)) From e6512fb0af02b2e2ccc711ce56a72d9f0cae7292 Mon Sep 17 00:00:00 2001 From: Thomas Cameron Date: Thu, 29 Jun 2023 11:23:46 +0000 Subject: [PATCH 04/24] asdf --- .../software/amazon/smithy/rust/codegen/core/testutil/Rust.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt index ce5465bbd4..7bb7368f52 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt @@ -52,7 +52,7 @@ object Commands { return s } } - + fun cargoEnvDWarnings(enableUnstable: Boolean): Map { return mapOf( "RUSTFLAGS" to func("-A dead_code", cfgUnstable, enableUnstable), From 3624b378ca1ea01993472274cf745c0630c102d2 Mon Sep 17 00:00:00 2001 From: Thomas Cameron Date: Thu, 29 Jun 2023 11:27:26 +0000 Subject: [PATCH 05/24] pre-commit --- .../software/amazon/smithy/rust/codegen/core/testutil/Rust.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt index 7bb7368f52..4bfc1b0e18 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt @@ -353,7 +353,7 @@ fun FileManifest.printGeneratedFiles() { fun TestWriterDelegator.compileAndTest( runClippy: Boolean = false, expectFailure: Boolean = false, - enableUnstableFlag: Boolean = false + enableUnstableFlag: Boolean = false, ): String { val stubModel = """ namespace fake @@ -405,7 +405,7 @@ fun RustWriter.compileAndTest( main: String = "", clippy: Boolean = false, expectFailure: Boolean = false, - enableUnstable: Boolean = false + enableUnstable: Boolean = false, ): String { val deps = this.dependencies.map { RustDependency.fromSymbolDependency(it) }.filterIsInstance() val module = if (this.namespace.contains("::")) { From e0311c34ba2b89ed7e02933c6bcb01af9445a730 Mon Sep 17 00:00:00 2001 From: Thomas Cameron Date: Thu, 29 Jun 2023 11:39:03 +0000 Subject: [PATCH 06/24] check --- .../software/amazon/smithy/rust/codegen/core/testutil/Rust.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt index 4bfc1b0e18..86f37fbd8f 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt @@ -528,4 +528,4 @@ fun TestWriterDelegator.unitTest(test: Writable): TestWriterDelegator { return this } -fun String.runWithWarnings(crate: Path, enableUnstableFlag: Boolean) = this.runCommand(crate, Commands.cargoEnvDWarnings(enableUnstableFlag)) +fun String.runWithWarnings(crate: Path, enableUnstableFlag: Boolean = true) = this.runCommand(crate, Commands.cargoEnvDWarnings(enableUnstableFlag)) From 6e87b131d773f9af2ddf73479f69ec1b84525ddc Mon Sep 17 00:00:00 2001 From: Thomas Cameron Date: Fri, 30 Jun 2023 02:38:14 +0900 Subject: [PATCH 07/24] Update codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt Co-authored-by: John DiSanti --- .../software/amazon/smithy/rust/codegen/core/testutil/Rust.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt index 86f37fbd8f..fb2a179812 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt @@ -43,7 +43,7 @@ import java.nio.file.Path import kotlin.io.path.absolutePathString // cargo commands and env values -object Commands { +private object Commands { private const val cfgUnstable = "--cfg aws_sdk_unstable" fun func(s: String, add: String, flag: Boolean): String { if (flag) { From 2f250428796e317ff368e269a04290355ac4a1b1 Mon Sep 17 00:00:00 2001 From: Thomas Cameron Date: Fri, 30 Jun 2023 02:38:34 +0900 Subject: [PATCH 08/24] Update codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt Co-authored-by: John DiSanti --- .../amazon/smithy/rust/codegen/core/testutil/Rust.kt | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt index fb2a179812..6579152cef 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt @@ -45,13 +45,7 @@ import kotlin.io.path.absolutePathString // cargo commands and env values private object Commands { private const val cfgUnstable = "--cfg aws_sdk_unstable" - fun func(s: String, add: String, flag: Boolean): String { - if (flag) { - return s + " " + add - } else { - return s - } - } + fun func(s: String, add: String, flag: Boolean): String = if (flag) { "$s $add" } else { s } fun cargoEnvDWarnings(enableUnstable: Boolean): Map { return mapOf( From 7e06e0c7977bd64b412e49100a8684f268a345cd Mon Sep 17 00:00:00 2001 From: Thomas Cameron Date: Thu, 29 Jun 2023 17:51:03 +0000 Subject: [PATCH 09/24] FIX --- .../amazon/smithy/rust/codegen/core/testutil/Rust.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt index 6579152cef..d9e82f25a6 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt @@ -47,13 +47,13 @@ private object Commands { private const val cfgUnstable = "--cfg aws_sdk_unstable" fun func(s: String, add: String, flag: Boolean): String = if (flag) { "$s $add" } else { s } - fun cargoEnvDWarnings(enableUnstable: Boolean): Map { + fun cargoEnvDenyWarnings(enableUnstable: Boolean): Map { return mapOf( - "RUSTFLAGS" to func("-A dead_code", cfgUnstable, enableUnstable), + "RUSTFLAGS" to func("-D warnings", cfgUnstable, enableUnstable), ) } - fun cargoEnvDDeadCode(enableUnstable: Boolean): Map { + fun cargoEnvAllowDeadCode(enableUnstable: Boolean): Map { return mapOf( "RUSTFLAGS" to func("-A dead_code", cfgUnstable, enableUnstable), ) From 84c943d8ed1f464a643bb68d379f80d42524ef21 Mon Sep 17 00:00:00 2001 From: Thomas Cameron Date: Thu, 29 Jun 2023 18:53:37 +0000 Subject: [PATCH 10/24] fix --- .../software/amazon/smithy/rust/codegen/core/testutil/Rust.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt index d9e82f25a6..42f3c53a79 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt @@ -369,7 +369,7 @@ fun TestWriterDelegator.compileAndTest( // cargo fmt errors are useless, ignore } - val env = Commands.cargoEnvDDeadCode(enableUnstableFlag) + val env = Commands.cargoEnvAllowDeadCode(enableUnstableFlag) val testOutput = Commands.cargoTest(enableUnstableFlag).runCommand(baseDir, env) if (runClippy) { Commands.CargoClippy.runCommand(baseDir, env) @@ -522,4 +522,4 @@ fun TestWriterDelegator.unitTest(test: Writable): TestWriterDelegator { return this } -fun String.runWithWarnings(crate: Path, enableUnstableFlag: Boolean = true) = this.runCommand(crate, Commands.cargoEnvDWarnings(enableUnstableFlag)) +fun String.runWithWarnings(crate: Path, enableUnstableFlag: Boolean = true) = this.runCommand(crate, Commands.cargoEnvDenyWarnings(enableUnstableFlag)) From c358294abc495c42be36007ff4588b4c3db11e48 Mon Sep 17 00:00:00 2001 From: Thomas Cameron Date: Thu, 29 Jun 2023 22:59:42 +0000 Subject: [PATCH 11/24] fix --- .../amazon/smithy/rust/codegen/core/testutil/Rust.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt index 42f3c53a79..f5b382c697 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt @@ -61,12 +61,12 @@ private object Commands { private const val allFeature = "--all-features" - fun cargoTest(enableUnstable: Boolean): String { - return func("cargo test", allFeature, enableUnstable) + fun cargoTest(enableAllFeatures: Boolean): String { + return func("cargo test", allFeature, enableAllFeatures) } - fun cargoCheck(enableUnstable: Boolean): String { - return func("cargo check", allFeature, enableUnstable) + fun cargoCheck(enableAllFeatures: Boolean): String { + return func("cargo check", allFeature, enableAllFeatures) } const val CargoFmt = "cargo fmt" From 99113b5200e217f8b1da7052c35608790d09a1f2 Mon Sep 17 00:00:00 2001 From: Thomas Cameron Date: Thu, 29 Jun 2023 23:03:50 +0000 Subject: [PATCH 12/24] enable by default --- .../software/amazon/smithy/rust/codegen/core/testutil/Rust.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt index f5b382c697..e8d11c8463 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt @@ -347,7 +347,7 @@ fun FileManifest.printGeneratedFiles() { fun TestWriterDelegator.compileAndTest( runClippy: Boolean = false, expectFailure: Boolean = false, - enableUnstableFlag: Boolean = false, + enableUnstableFlag: Boolean = true, ): String { val stubModel = """ namespace fake From 5a36064821d021e6b089228c755f2bbb9d581e96 Mon Sep 17 00:00:00 2001 From: Thomas Cameron Date: Thu, 29 Jun 2023 23:23:14 +0000 Subject: [PATCH 13/24] fix --- .../smithy/rust/codegen/core/testutil/Rust.kt | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt index e8d11c8463..7d94f8e05c 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt @@ -65,10 +65,18 @@ private object Commands { return func("cargo test", allFeature, enableAllFeatures) } + fun cargoTest(featuresToEnable: Array): String { + return func("cargo test", featuresToEnable.joinToString(" "), true) + } + fun cargoCheck(enableAllFeatures: Boolean): String { return func("cargo check", allFeature, enableAllFeatures) } + fun cargoCheck(featuresToEnable: Array): String { + return func("cargo test", featuresToEnable.joinToString(" "), true) + } + const val CargoFmt = "cargo fmt" const val CargoClippy = "cargo clippy" } @@ -348,6 +356,8 @@ fun TestWriterDelegator.compileAndTest( runClippy: Boolean = false, expectFailure: Boolean = false, enableUnstableFlag: Boolean = true, + enableAllFeatures: Boolean = false, + featuresToEnable: Array? = null, ): String { val stubModel = """ namespace fake @@ -370,7 +380,13 @@ fun TestWriterDelegator.compileAndTest( } val env = Commands.cargoEnvAllowDeadCode(enableUnstableFlag) - val testOutput = Commands.cargoTest(enableUnstableFlag).runCommand(baseDir, env) + + var testCommand = Commands.cargoTest(enableUnstableFlag) + if (featuresToEnable != null) { + testCommand = Commands.cargoCheck(featuresToEnable) + } + + val testOutput = testCommand.runCommand(baseDir, env) if (runClippy) { Commands.CargoClippy.runCommand(baseDir, env) } From 970d4c2a235490df732bda74d727316f0dc03c21 Mon Sep 17 00:00:00 2001 From: Thomas Cameron Date: Tue, 4 Jul 2023 14:27:44 +0900 Subject: [PATCH 14/24] Update Rust.kt --- .../smithy/rust/codegen/core/testutil/Rust.kt | 23 ++++++++----------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt index 7d94f8e05c..87e0c9222d 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt @@ -44,9 +44,16 @@ import kotlin.io.path.absolutePathString // cargo commands and env values private object Commands { + const val CargoFmt = "cargo fmt" + const val CargoClippy = "cargo clippy" + private const val cfgUnstable = "--cfg aws_sdk_unstable" - fun func(s: String, add: String, flag: Boolean): String = if (flag) { "$s $add" } else { s } + private const val allFeature = "--all-features" + + // helper + private fun func(s: String, add: String, flag: Boolean): String = if (flag) { "$s $add" } else { s } + // unstable flag fun cargoEnvDenyWarnings(enableUnstable: Boolean): Map { return mapOf( "RUSTFLAGS" to func("-D warnings", cfgUnstable, enableUnstable), @@ -59,26 +66,14 @@ private object Commands { ) } - private const val allFeature = "--all-features" - + // --all-features fun cargoTest(enableAllFeatures: Boolean): String { return func("cargo test", allFeature, enableAllFeatures) } - fun cargoTest(featuresToEnable: Array): String { - return func("cargo test", featuresToEnable.joinToString(" "), true) - } - fun cargoCheck(enableAllFeatures: Boolean): String { return func("cargo check", allFeature, enableAllFeatures) } - - fun cargoCheck(featuresToEnable: Array): String { - return func("cargo test", featuresToEnable.joinToString(" "), true) - } - - const val CargoFmt = "cargo fmt" - const val CargoClippy = "cargo clippy" } val TestModuleDocProvider = object : ModuleDocProvider { From cc3351424f00e752a062a35590fb0f0243ce9571 Mon Sep 17 00:00:00 2001 From: Thomas Cameron Date: Tue, 4 Jul 2023 15:35:17 +0900 Subject: [PATCH 15/24] Update Rust.kt --- .../software/amazon/smithy/rust/codegen/core/testutil/Rust.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt index 87e0c9222d..6bc66aaa9c 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt @@ -351,7 +351,7 @@ fun TestWriterDelegator.compileAndTest( runClippy: Boolean = false, expectFailure: Boolean = false, enableUnstableFlag: Boolean = true, - enableAllFeatures: Boolean = false, + enableAllFeatures: Boolean = true, featuresToEnable: Array? = null, ): String { val stubModel = """ From 8d78bd41cced2eaaa26c9c81b58d48dfabcc109d Mon Sep 17 00:00:00 2001 From: Thomas Cameron Date: Thu, 6 Jul 2023 15:53:09 +0000 Subject: [PATCH 16/24] fix --- .../smithy/rust/codegen/core/testutil/Rust.kt | 37 ++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt index 6bc66aaa9c..e53102c685 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt @@ -66,14 +66,49 @@ private object Commands { ) } - // --all-features + // enable all features + // e.g. + // ```kotlin + // cargoTest(true) + // // cargo test --all-features + // cargoTest(false) + // // cargo test + // ``` fun cargoTest(enableAllFeatures: Boolean): String { return func("cargo test", allFeature, enableAllFeatures) } + // enable all features + // e.g. + // ```kotlin + // cargoCheck(true) + // // cargo test --all-features + // cargoCheck(false) + // // cargo test + // ``` fun cargoCheck(enableAllFeatures: Boolean): String { return func("cargo check", allFeature, enableAllFeatures) } + + // enable features specified in the array + // e.g. + // ```kotlin + // cargoTest(["serde-serialize", "serde-deserialize"]) + // // cargo test --features serde-serialize serde-deserialize + // ``` + fun cargoTest(featuresToEnable?: Array): String { + return func("cargo test", allFeature, enableAllFeatures) + } + + // enable features specified in the array + // e.g. + // ```kotlin + // cargoCheck(["serde-serialize", "serde-deserialize"]) + // // cargo check --features serde-serialize serde-deserialize + // ``` + fun cargoCheck(featuresToEnable?: Array): String { + return func("cargo check", allFeature, enableAllFeatures) + } } val TestModuleDocProvider = object : ModuleDocProvider { From 7d80faf2b4769abdd2f7371ff96e438ea055a112 Mon Sep 17 00:00:00 2001 From: Thomas Cameron Date: Thu, 6 Jul 2023 15:59:24 +0000 Subject: [PATCH 17/24] better docs --- .../amazon/smithy/rust/codegen/core/testutil/Rust.kt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt index e53102c685..42558282c7 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt @@ -381,6 +381,15 @@ fun FileManifest.printGeneratedFiles() { * Setting `runClippy` to true can be helpful when debugging clippy failures, but * should generally be set to `false` to avoid invalidating the Cargo cache between * every unit test run. + * If you want to enable each features individually, specify the name of the feature on featuresToEnable. + * e.g. + * ```kotlin + * compileAndTest(featuresToEnable = ["this", "that"]) + * ``` + * All features are enabled by default. If you wish to disable them, set enableAllFeatures to False. + * ```kotlin + * compileAndTest(featuresToEnable = false) + * ``` */ fun TestWriterDelegator.compileAndTest( runClippy: Boolean = false, From 5756a4196161b8917d325357970a4b7b3ff7be55 Mon Sep 17 00:00:00 2001 From: Thomas Cameron Date: Thu, 6 Jul 2023 16:01:24 +0000 Subject: [PATCH 18/24] update --- .../software/amazon/smithy/rust/codegen/core/testutil/Rust.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt index 42558282c7..5223d5aba8 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt @@ -96,7 +96,7 @@ private object Commands { // cargoTest(["serde-serialize", "serde-deserialize"]) // // cargo test --features serde-serialize serde-deserialize // ``` - fun cargoTest(featuresToEnable?: Array): String { + fun cargoTest(featuresToEnable: Array?): String { return func("cargo test", allFeature, enableAllFeatures) } @@ -106,7 +106,7 @@ private object Commands { // cargoCheck(["serde-serialize", "serde-deserialize"]) // // cargo check --features serde-serialize serde-deserialize // ``` - fun cargoCheck(featuresToEnable?: Array): String { + fun cargoCheck(featuresToEnable: Array?): String { return func("cargo check", allFeature, enableAllFeatures) } } From 1496901c25339533bafd7bdf6011babf857ac1c4 Mon Sep 17 00:00:00 2001 From: Thomas Cameron Date: Thu, 6 Jul 2023 16:25:56 +0000 Subject: [PATCH 19/24] fix --- .../software/amazon/smithy/rust/codegen/core/testutil/Rust.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt index 40e4dc2f79..be87f523bf 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt @@ -46,7 +46,7 @@ import kotlin.io.path.absolutePathString private object Commands { const val CargoFmt = "cargo fmt" const val CargoClippy = "cargo clippy" - + private const val cfgUnstable = "--cfg aws_sdk_unstable" private const val allFeature = "--all-features" From 73b40a4748716990cfedc8b9529767f0954ed520 Mon Sep 17 00:00:00 2001 From: Thomas Cameron Date: Thu, 6 Jul 2023 16:39:46 +0000 Subject: [PATCH 20/24] fix --- .../smithy/rust/codegen/core/testutil/Rust.kt | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt index be87f523bf..e9b5b94420 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt @@ -97,7 +97,12 @@ private object Commands { // // cargo test --features serde-serialize serde-deserialize // ``` fun cargoTest(featuresToEnable: Array?): String { - return func("cargo test", allFeature, enableAllFeatures) + if (featuresToEnable != null) { + val s = featuresToEnable.joinToString { " " } + return "cargo test --features $s" + }else { + return "cargo test" + } } // enable features specified in the array @@ -107,7 +112,12 @@ private object Commands { // // cargo check --features serde-serialize serde-deserialize // ``` fun cargoCheck(featuresToEnable: Array?): String { - return func("cargo check", allFeature, enableAllFeatures) + if (featuresToEnable != null) { + val s = featuresToEnable.joinToString { " " } + return "cargo check --features $s" + }else { + return "cargo check" + } } } From 2647de97f9c0da5cae3e0aacfa869d3f5c793ff2 Mon Sep 17 00:00:00 2001 From: Thomas Cameron Date: Thu, 6 Jul 2023 19:39:03 +0000 Subject: [PATCH 21/24] update --- .../software/amazon/smithy/rust/codegen/core/testutil/Rust.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt index e9b5b94420..9438eb756a 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt @@ -100,7 +100,7 @@ private object Commands { if (featuresToEnable != null) { val s = featuresToEnable.joinToString { " " } return "cargo test --features $s" - }else { + } else { return "cargo test" } } @@ -115,7 +115,7 @@ private object Commands { if (featuresToEnable != null) { val s = featuresToEnable.joinToString { " " } return "cargo check --features $s" - }else { + } else { return "cargo check" } } From d53c7c4154529a9dc8c31e8ed5974633efe50150 Mon Sep 17 00:00:00 2001 From: Thomas K Cameron Date: Sat, 9 Dec 2023 13:32:26 +0900 Subject: [PATCH 22/24] update --- .../amazon/smithy/rust/codegen/core/testutil/Rust.kt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt index fb26a1ca27..add73469ab 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt @@ -435,11 +435,13 @@ fun TestWriterDelegator.compileAndTest( // cargo fmt errors are useless, ignore } - val env = Commands.cargoEnvAllowDeadCode(enableUnstableFlag) + // Clean `RUSTFLAGS` because in CI we pass in `--deny warnings` and // we still generate test code with warnings. // TODO(https://github.com/smithy-lang/smithy-rs/issues/3194) - val env = mapOf("RUSTFLAGS" to "") + // val env = mapOf("RUSTFLAGS" to "") + // + val env = Commands.cargoEnvAllowDeadCode(enableUnstableFlag) baseDir.writeDotCargoConfigToml(listOf("--allow", "dead_code")) var testCommand = Commands.cargoTest(enableUnstableFlag) From c46ae34fb685186a54f1f97f516d5c9cbd1b8ddc Mon Sep 17 00:00:00 2001 From: Thomas Cameron Date: Sat, 9 Dec 2023 04:43:20 +0000 Subject: [PATCH 23/24] modified: codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt --- .../amazon/smithy/rust/codegen/core/testutil/Rust.kt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt index add73469ab..ba0634986c 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt @@ -435,7 +435,6 @@ fun TestWriterDelegator.compileAndTest( // cargo fmt errors are useless, ignore } - // Clean `RUSTFLAGS` because in CI we pass in `--deny warnings` and // we still generate test code with warnings. // TODO(https://github.com/smithy-lang/smithy-rs/issues/3194) @@ -443,7 +442,7 @@ fun TestWriterDelegator.compileAndTest( // val env = Commands.cargoEnvAllowDeadCode(enableUnstableFlag) baseDir.writeDotCargoConfigToml(listOf("--allow", "dead_code")) - + var testCommand = Commands.cargoTest(enableUnstableFlag) if (featuresToEnable != null) { testCommand = Commands.cargoCheck(featuresToEnable) @@ -454,7 +453,7 @@ fun TestWriterDelegator.compileAndTest( Commands.CargoClippy.runCommand(baseDir, env) } - return testOutput + return testOutput } fun Path.writeDotCargoConfigToml(rustFlags: List) { From ac6928d931bc754a76ade3cb61417f0defd5c5b9 Mon Sep 17 00:00:00 2001 From: Thomas K Cameron Date: Sat, 9 Dec 2023 14:19:33 +0900 Subject: [PATCH 24/24] update --- .../amazon/smithy/rust/codegen/core/testutil/Rust.kt | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt index ba0634986c..aab6c8cf92 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt @@ -405,13 +405,21 @@ fun FileManifest.printGeneratedFiles() { * ``` * All features are enabled by default. If you wish to disable them, set enableAllFeatures to False. * ```kotlin - * compileAndTest(featuresToEnable = false) + * compileAndTest(enableAllFeatures = false) * ``` + * + * You can run with `--cfg aws_sdk_unstable` by setting enableUnstableFlag to True. + * This feature is not enabled by default. + * e.g. + * ```kotlin + * compileAndTest(enableUnstableFlag = true) + * compileAndTest(enableUnstableFlag = true, featuresToEnable = ["serde-serialize", "serde-deserialize"]) + * ``` */ fun TestWriterDelegator.compileAndTest( runClippy: Boolean = false, expectFailure: Boolean = false, - enableUnstableFlag: Boolean = true, + enableUnstableFlag: Boolean = false, enableAllFeatures: Boolean = true, featuresToEnable: Array? = null, ): String {