Skip to content

Commit 9e53ac6

Browse files
committed
Auto merge of #5493 - ehuss:fix-changing_bin_features_caches_targets, r=matklad
Fix random Windows CI error for changing_bin_features_caches_targets Fixes #5481.
2 parents b429a36 + 3521144 commit 9e53ac6

File tree

1 file changed

+46
-35
lines changed

1 file changed

+46
-35
lines changed

tests/testsuite/freshness.rs

+46-35
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ use std::fs::{self, File};
22
use std::io::prelude::*;
33

44
use cargotest::sleep_ms;
5-
use cargotest::support::{execs, project, path2url};
65
use cargotest::support::paths::CargoPathExt;
76
use cargotest::support::registry::Package;
7+
use cargotest::support::{execs, path2url, project};
88
use hamcrest::{assert_that, existing_file};
99

1010
#[test]
@@ -515,60 +515,71 @@ fn changing_bin_features_caches_targets() {
515515
)
516516
.build();
517517

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+
518529
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 ([..])
526534
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
527-
[RUNNING] `target[/]debug[/]foo[EXE]`
528535
",
529-
),
536+
),
537+
);
538+
assert_that(
539+
foo_proc("off1"),
540+
execs().with_status(0).with_stdout("feature off"),
530541
);
531542

532543
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 ([..])
540548
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
541-
[RUNNING] `target[/]debug[/]foo[EXE]`
542549
",
543-
),
550+
),
551+
);
552+
assert_that(
553+
foo_proc("on1"),
554+
execs().with_status(0).with_stdout("feature on"),
544555
);
545556

546557
/* Targets should be cached from the first build */
547558

548559
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+
"\
555563
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
556-
[RUNNING] `target[/]debug[/]foo[EXE]`
557564
",
558-
),
565+
),
566+
);
567+
assert_that(
568+
foo_proc("off2"),
569+
execs().with_status(0).with_stdout("feature off"),
559570
);
560571

561572
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+
"\
568576
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
569-
[RUNNING] `target[/]debug[/]foo[EXE]`
570577
",
571-
),
578+
),
579+
);
580+
assert_that(
581+
foo_proc("on2"),
582+
execs().with_status(0).with_stdout("feature on"),
572583
);
573584
}
574585

0 commit comments

Comments
 (0)