-
Notifications
You must be signed in to change notification settings - Fork 214
Refactoring and adding aws_sdk_unstable
to RUSTFLAG on one of the kotlin test
#2804
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 9 commits
8565bf2
f578b86
268b876
d614f5f
31c16bd
0df1dfb
e6512fb
3624b37
e0311c3
6e87b13
2f25042
7e06e0c
1acf514
84c943d
c358294
99113b5
1e4ec95
5a36064
2b24f9d
970d4c2
cc33514
8d78bd4
7d80faf
5756a41
01a69fc
0dca49e
1496901
73b40a4
2647de9
16b51e3
e7d4597
5b7d9d1
71d54cb
d53c7c4
c46ae34
ac6928d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,43 @@ import java.nio.file.Files.createTempDirectory | |
import java.nio.file.Path | ||
import kotlin.io.path.absolutePathString | ||
|
||
// cargo commands and env values | ||
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 | ||
} | ||
} | ||
thomas-k-cameron marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
fun cargoEnvDWarnings(enableUnstable: Boolean): Map<String, String> { | ||
thomas-k-cameron marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return mapOf( | ||
"RUSTFLAGS" to func("-A dead_code", cfgUnstable, enableUnstable), | ||
) | ||
} | ||
|
||
fun cargoEnvDDeadCode(enableUnstable: Boolean): Map<String, String> { | ||
thomas-k-cameron marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return mapOf( | ||
"RUSTFLAGS" to func("-A dead_code", cfgUnstable, enableUnstable), | ||
) | ||
} | ||
|
||
private const val allFeature = "--all-features" | ||
|
||
fun cargoTest(enableUnstable: Boolean): String { | ||
return func("cargo test", allFeature, enableUnstable) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this isn't quite doing what is expected by the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since only features that can be enabled are protected behind feature gate, I thought it was accurate. I changed the name to I also added a function that accepts array of string as an argument; In this case, you can specified individual features. // 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>): String {
return func("cargo check", allFeature, enableAllFeatures)
} |
||
} | ||
|
||
fun cargoCheck(enableUnstable: Boolean): String { | ||
return func("cargo check", allFeature, enableUnstable) | ||
} | ||
|
||
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...") | ||
|
@@ -316,6 +353,7 @@ fun FileManifest.printGeneratedFiles() { | |
fun TestWriterDelegator.compileAndTest( | ||
runClippy: Boolean = false, | ||
expectFailure: Boolean = false, | ||
enableUnstableFlag: Boolean = false, | ||
): String { | ||
val stubModel = """ | ||
namespace fake | ||
|
@@ -332,14 +370,15 @@ 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(enableUnstableFlag) | ||
val testOutput = Commands.cargoTest(enableUnstableFlag).runCommand(baseDir, env) | ||
if (runClippy) { | ||
"cargo clippy".runCommand(baseDir, env) | ||
Commands.CargoClippy.runCommand(baseDir, env) | ||
} | ||
return testOutput | ||
} | ||
|
@@ -366,6 +405,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<CargoDependency>() | ||
val module = if (this.namespace.contains("::")) { | ||
|
@@ -379,9 +419,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(enableUnstable).runCommand(tempDir.toPath()) | ||
} else { | ||
"cargo check".runCommand(tempDir.toPath()) | ||
Commands.cargoCheck(enableUnstable).runCommand(tempDir.toPath()) | ||
} | ||
if (expectFailure) { | ||
println("Test sources for debugging: file://${testModule.absolutePath}") | ||
|
@@ -488,4 +528,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, enableUnstableFlag: Boolean = true) = this.runCommand(crate, Commands.cargoEnvDWarnings(enableUnstableFlag)) |
Uh oh!
There was an error while loading. Please reload this page.