File tree 2 files changed +59
-12
lines changed
2 files changed +59
-12
lines changed Original file line number Diff line number Diff line change @@ -258,6 +258,16 @@ fn cairo_compilation_unit_for_target(
258
258
let cairo_plugins = solution. cairo_plugins . as_ref ( ) . unwrap ( ) ;
259
259
260
260
let cfg_set = build_cfg_set ( & member_target) ;
261
+ let no_test_cfg_set = cfg_set
262
+ . iter ( )
263
+ . filter ( |cfg| * * cfg != Cfg :: name ( "test" ) )
264
+ . cloned ( )
265
+ . collect ( ) ;
266
+ let no_test_cfg_set = if no_test_cfg_set != cfg_set {
267
+ Some ( no_test_cfg_set)
268
+ } else {
269
+ None
270
+ } ;
261
271
262
272
let props: TestTargetProps = member_target. props ( ) ?;
263
273
let is_integration_test = props. test_type == TestTargetType :: Integration ;
@@ -304,17 +314,7 @@ fn cairo_compilation_unit_for_target(
304
314
enabled_features,
305
315
) ?
306
316
} else {
307
- let component_cfg_set = cfg_set
308
- . iter ( )
309
- . filter ( |cfg| * * cfg != Cfg :: name ( "test" ) )
310
- . cloned ( )
311
- . collect ( ) ;
312
-
313
- if component_cfg_set != cfg_set {
314
- Some ( component_cfg_set)
315
- } else {
316
- None
317
- }
317
+ no_test_cfg_set. clone ( )
318
318
}
319
319
} ;
320
320
@@ -341,7 +341,7 @@ fn cairo_compilation_unit_for_target(
341
341
components. push ( CompilationUnitComponent :: try_new (
342
342
member. clone ( ) ,
343
343
vec ! [ target] ,
344
- None ,
344
+ no_test_cfg_set ,
345
345
) ?) ;
346
346
347
347
// Set test package as main package for this compilation unit.
Original file line number Diff line number Diff line change @@ -360,6 +360,53 @@ fn compile_test_target() {
360
360
assert_eq ! ( tests. len( ) , 0 ) ;
361
361
}
362
362
363
+ #[ test]
364
+ fn integration_tests_do_not_enable_cfg_in_main_package ( ) {
365
+ let t = TempDir :: new ( ) . unwrap ( ) ;
366
+ ProjectBuilder :: start ( )
367
+ . name ( "hello" )
368
+ . lib_cairo ( indoc ! { r#"
369
+ #[cfg(test)]
370
+ fn f() -> felt252 { 42 }
371
+ "# } )
372
+ . build ( & t) ;
373
+ t. child ( "tests" ) . create_dir_all ( ) . unwrap ( ) ;
374
+ t. child ( "tests/test1.cairo" )
375
+ . write_str ( indoc ! { r#"
376
+ #[cfg(test)]
377
+ mod tests {
378
+ use hello::f;
379
+ #[test]
380
+ fn it_works() {
381
+ assert(f() == 42, 'it works!');
382
+ }
383
+ }
384
+ "# } )
385
+ . unwrap ( ) ;
386
+
387
+ Scarb :: quick_snapbox ( )
388
+ . arg ( "build" )
389
+ . arg ( "--test" )
390
+ . current_dir ( & t)
391
+ . assert ( )
392
+ . failure ( )
393
+ . stdout_matches ( indoc ! { r#"
394
+ [..]Compiling test(hello_unittest) hello v1.0.0 ([..]Scarb.toml)
395
+ [..]Compiling test(hello_integrationtest) hello_integrationtest v1.0.0 ([..]Scarb.toml)
396
+ error: Identifier not found.
397
+ --> [..]test1.cairo:3:16
398
+ use hello::f;
399
+ ^
400
+
401
+ error: Type annotations needed. Failed to infer ?0.
402
+ --> [..]test1.cairo:6:16
403
+ assert(f() == 42, 'it works!');
404
+ ^*******^
405
+
406
+ error: could not compile `hello_integrationtest` due to previous error
407
+ "# } ) ;
408
+ }
409
+
363
410
#[ test]
364
411
fn detect_single_file_test_targets ( ) {
365
412
let t = TempDir :: new ( ) . unwrap ( ) ;
You can’t perform that action at this time.
0 commit comments