File tree 1 file changed +56
-0
lines changed
1 file changed +56
-0
lines changed Original file line number Diff line number Diff line change 441
441
"# ] ] )
442
442
. run ( ) ;
443
443
}
444
+
445
+ #[ cargo_test]
446
+ fn override_env_set_by_cargo ( ) {
447
+ // Cargo disallows overridding envs set by itself.
448
+ let p = project ( )
449
+ . file ( "Cargo.toml" , & basic_bin_manifest ( "foo" ) )
450
+ . file (
451
+ "src/main.rs" ,
452
+ r#"
453
+ use std::env;
454
+ fn main() {
455
+ println!( "{}", env!("CARGO_MANIFEST_DIR") );
456
+ println!( "{}", env!("CARGO_PKG_NAME") );
457
+ }
458
+ "# ,
459
+ )
460
+ . build ( ) ;
461
+
462
+ let args = [
463
+ "--config" ,
464
+ "env.CARGO_MANIFEST_DIR='Sauron'" ,
465
+ "--config" ,
466
+ "env.CARGO_PKG_NAME='Saruman'" ,
467
+ ] ;
468
+
469
+ p. cargo ( "run" )
470
+ . args ( & args)
471
+ . with_stdout_data ( str![ [ r#"
472
+ [ROOT]/foo
473
+ foo
474
+
475
+ "# ] ] )
476
+ . with_stderr_data ( str![ [ r#"
477
+ [COMPILING] foo v0.5.0 ([ROOT]/foo)
478
+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
479
+ [RUNNING] `target/debug/foo[EXE]`
480
+
481
+ "# ] ] )
482
+ . run ( ) ;
483
+
484
+ // The second run shouldn't trigger a rebuild
485
+ p. cargo ( "run" )
486
+ . args ( & args)
487
+ . with_stdout_data ( str![ [ r#"
488
+ [ROOT]/foo
489
+ foo
490
+
491
+ "# ] ] )
492
+ . with_stderr_data ( str![ [ r#"
493
+ [COMPILING] foo v0.5.0 ([ROOT]/foo)
494
+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
495
+ [RUNNING] `target/debug/foo[EXE]`
496
+
497
+ "# ] ] )
498
+ . run ( ) ;
499
+ }
You can’t perform that action at this time.
0 commit comments