@@ -2,9 +2,9 @@ use std::fs::{self, File};
2
2
use std:: io:: prelude:: * ;
3
3
4
4
use cargotest:: sleep_ms;
5
- use cargotest:: support:: { execs, project, path2url} ;
6
5
use cargotest:: support:: paths:: CargoPathExt ;
7
6
use cargotest:: support:: registry:: Package ;
7
+ use cargotest:: support:: { execs, path2url, project} ;
8
8
use hamcrest:: { assert_that, existing_file} ;
9
9
10
10
#[ test]
@@ -515,60 +515,71 @@ fn changing_bin_features_caches_targets() {
515
515
)
516
516
. build ( ) ;
517
517
518
+ // Windows has a problem with replacing a binary that was just executed.
519
+ // Unlinking it will succeed, but then attempting to immediately replace
520
+ // it will sometimes fail with "Already Exists".
521
+ // See https://github.com/rust-lang/cargo/issues/5481
522
+ let foo_proc = |name : & str | {
523
+ let src = p. bin ( "foo" ) ;
524
+ let dst = p. bin ( name) ;
525
+ fs:: copy ( & src, & dst) . expect ( "Failed to copy foo" ) ;
526
+ p. process ( dst)
527
+ } ;
528
+
518
529
assert_that (
519
- p. cargo ( "run" ) ,
520
- execs ( )
521
- . with_status ( 0 )
522
- . with_stdout ( "feature off" )
523
- . with_stderr (
524
- "\
525
- [..]Compiling foo v0.0.1 ([..])
530
+ p. cargo ( "build" ) ,
531
+ execs ( ) . with_status ( 0 ) . with_stderr (
532
+ "\
533
+ [COMPILING] foo v0.0.1 ([..])
526
534
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
527
- [RUNNING] `target[/]debug[/]foo[EXE]`
528
535
" ,
529
- ) ,
536
+ ) ,
537
+ ) ;
538
+ assert_that (
539
+ foo_proc ( "off1" ) ,
540
+ execs ( ) . with_status ( 0 ) . with_stdout ( "feature off" ) ,
530
541
) ;
531
542
532
543
assert_that (
533
- p. cargo ( "run" ) . arg ( "--features" ) . arg ( "foo" ) ,
534
- execs ( )
535
- . with_status ( 0 )
536
- . with_stdout ( "feature on" )
537
- . with_stderr (
538
- "\
539
- [..]Compiling foo v0.0.1 ([..])
544
+ p. cargo ( "build" ) . arg ( "--features" ) . arg ( "foo" ) ,
545
+ execs ( ) . with_status ( 0 ) . with_stderr (
546
+ "\
547
+ [COMPILING] foo v0.0.1 ([..])
540
548
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
541
- [RUNNING] `target[/]debug[/]foo[EXE]`
542
549
" ,
543
- ) ,
550
+ ) ,
551
+ ) ;
552
+ assert_that (
553
+ foo_proc ( "on1" ) ,
554
+ execs ( ) . with_status ( 0 ) . with_stdout ( "feature on" ) ,
544
555
) ;
545
556
546
557
/* Targets should be cached from the first build */
547
558
548
559
assert_that (
549
- p. cargo ( "run" ) ,
550
- execs ( )
551
- . with_status ( 0 )
552
- . with_stdout ( "feature off" )
553
- . with_stderr (
554
- "\
560
+ p. cargo ( "build" ) ,
561
+ execs ( ) . with_status ( 0 ) . with_stderr (
562
+ "\
555
563
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
556
- [RUNNING] `target[/]debug[/]foo[EXE]`
557
564
" ,
558
- ) ,
565
+ ) ,
566
+ ) ;
567
+ assert_that (
568
+ foo_proc ( "off2" ) ,
569
+ execs ( ) . with_status ( 0 ) . with_stdout ( "feature off" ) ,
559
570
) ;
560
571
561
572
assert_that (
562
- p. cargo ( "run" ) . arg ( "--features" ) . arg ( "foo" ) ,
563
- execs ( )
564
- . with_status ( 0 )
565
- . with_stdout ( "feature on" )
566
- . with_stderr (
567
- "\
573
+ p. cargo ( "build" ) . arg ( "--features" ) . arg ( "foo" ) ,
574
+ execs ( ) . with_status ( 0 ) . with_stderr (
575
+ "\
568
576
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
569
- [RUNNING] `target[/]debug[/]foo[EXE]`
570
577
" ,
571
- ) ,
578
+ ) ,
579
+ ) ;
580
+ assert_that (
581
+ foo_proc ( "on2" ) ,
582
+ execs ( ) . with_status ( 0 ) . with_stdout ( "feature on" ) ,
572
583
) ;
573
584
}
574
585
0 commit comments