@@ -14,27 +14,16 @@ import software.amazon.smithy.model.SourceLocation
14
14
import software.amazon.smithy.model.shapes.ShapeId
15
15
import software.amazon.smithy.model.traits.RequiredTrait
16
16
import software.amazon.smithy.model.traits.Trait
17
- import software.amazon.smithy.rust.codegen.core.rustlang.RustModule
18
17
import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter
19
- import software.amazon.smithy.rust.codegen.core.rustlang.Writable
20
- import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig
21
- import software.amazon.smithy.rust.codegen.core.smithy.RuntimeCrateLocation
22
- import software.amazon.smithy.rust.codegen.core.smithy.RustCrate
23
18
import software.amazon.smithy.rust.codegen.core.smithy.transformers.OperationNormalizer
19
+ import software.amazon.smithy.rust.codegen.core.testutil.IntegrationTestParams
24
20
import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel
25
- import software.amazon.smithy.rust.codegen.core.testutil.generatePluginContext
21
+ import software.amazon.smithy.rust.codegen.core.testutil.testModule
26
22
import software.amazon.smithy.rust.codegen.core.testutil.unitTest
27
- import software.amazon.smithy.rust.codegen.core.util.runCommand
28
23
import software.amazon.smithy.rust.codegen.core.util.toPascalCase
29
24
import software.amazon.smithy.rust.codegen.core.util.toSnakeCase
30
- import software.amazon.smithy.rust.codegen.server.smithy.customizations.CustomValidationExceptionWithReasonDecorator
31
- import software.amazon.smithy.rust.codegen.server.smithy.customizations.ServerRequiredCustomizations
32
- import software.amazon.smithy.rust.codegen.server.smithy.customizations.SmithyValidationExceptionDecorator
33
- import software.amazon.smithy.rust.codegen.server.smithy.customize.CombinedServerCodegenDecorator
34
- import software.amazon.smithy.rust.codegen.server.smithy.testutil.serverTestCodegenContext
25
+ import software.amazon.smithy.rust.codegen.server.smithy.testutil.serverIntegrationTest
35
26
import software.amazon.smithy.rust.codegen.server.smithy.transformers.ConstrainedMemberTransform
36
- import java.io.File
37
- import java.nio.file.Path
38
27
39
28
class ConstraintsMemberShapeTest {
40
29
private val outputModelOnly =
@@ -284,68 +273,19 @@ class ConstraintsMemberShapeTest {
284
273
)
285
274
}
286
275
287
- private fun runServerCodeGen (
288
- model : Model ,
289
- dirToUse : File ? = null,
290
- writable : Writable ,
291
- ): Path {
292
- val runtimeConfig =
293
- RuntimeConfig (runtimeCrateLocation = RuntimeCrateLocation .path(File (" ../rust-runtime" ).absolutePath))
294
-
295
- val (context, dir) =
296
- generatePluginContext(
297
- model,
298
- runtimeConfig = runtimeConfig,
299
- overrideTestDir = dirToUse,
300
- )
301
- val codegenDecorator =
302
- CombinedServerCodegenDecorator .fromClasspath(
303
- context,
304
- ServerRequiredCustomizations (),
305
- SmithyValidationExceptionDecorator (),
306
- CustomValidationExceptionWithReasonDecorator (),
307
- )
308
-
309
- ServerCodegenVisitor (context, codegenDecorator)
310
- .execute()
311
-
312
- val codegenContext = serverTestCodegenContext(model)
313
- val settings = ServerRustSettings .from(context.model, context.settings)
314
- val rustCrate =
315
- RustCrate (
316
- context.fileManifest,
317
- codegenContext.symbolProvider,
318
- settings.codegenConfig,
319
- codegenContext.expectModuleDocProvider(),
320
- )
321
-
322
- // We cannot write to the lib anymore as the RustWriter overwrites it, so writing code directly to check.rs
323
- // and then adding a `mod check;` to the lib.rs
324
- rustCrate.withModule(RustModule .public(" check" )) {
325
- writable(this )
326
- File (" $dir /src/check.rs" ).writeText(toString())
327
- }
328
-
329
- val lib = File (" $dir /src/lib.rs" )
330
- val libContents = lib.readText() + " \n mod check;"
331
- lib.writeText(libContents)
332
-
333
- return dir
334
- }
335
-
336
276
@Test
337
277
fun `generate code and check member constrained shapes are in the right modules` () {
338
- val dir =
339
- runServerCodeGen(outputModelOnly) {
340
- fun RustWriter.testTypeExistsInBuilderModule (typeName : String ) {
341
- unitTest(
342
- " builder_module_has_${typeName.toSnakeCase()} " ,
343
- """
344
- #[allow(unused_imports)] use crate::output::operation_using_get_output::$typeName ;
345
- """ ,
346
- )
347
- }
278
+ serverIntegrationTest(outputModelOnly, IntegrationTestParams (service = " constrainedMemberShape#ConstrainedService" )) { codegenContext, rustCrate ->
279
+ fun RustWriter.testTypeExistsInBuilderModule (typeName : String ) {
280
+ unitTest(
281
+ " builder_module_has_${typeName.toSnakeCase()} " ,
282
+ """
283
+ #[allow(unused_imports)] use crate::output::operation_using_get_output::$typeName ;
284
+ """ ,
285
+ )
286
+ }
348
287
288
+ rustCrate.testModule {
349
289
// All directly constrained members of the output structure should be in the builder module
350
290
setOf (
351
291
" ConstrainedLong" ,
@@ -394,9 +334,7 @@ class ConstraintsMemberShapeTest {
394
334
).generateUseStatements(" crate::model::pattern_string_list_override" ),
395
335
)
396
336
}
397
-
398
- val env = mapOf (" RUSTFLAGS" to " -A dead_code" )
399
- " cargo test" .runCommand(dir, env)
337
+ }
400
338
}
401
339
402
340
/* *
0 commit comments