Skip to content

Commit ef581f3

Browse files
committed
[DIRTY-MSVC] to simplify tests
+ tests for [DIRTY-MSVC]
1 parent 2a81f76 commit ef581f3

File tree

7 files changed

+205
-247
lines changed

7 files changed

+205
-247
lines changed

crates/cargo-test-support/src/compare.rs

Lines changed: 135 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,9 @@ fn normalize_actual(actual: &str, cwd: Option<&Path>) -> String {
108108

109109
/// Normalizes the expected string so that it can be compared against the actual output.
110110
fn normalize_expected(expected: &str, cwd: Option<&Path>) -> String {
111-
let expected = substitute_macros(expected);
111+
let expected = replace_dirty_msvc(expected);
112+
let expected = substitute_macros(&expected);
113+
112114
if cfg!(windows) {
113115
normalize_windows(&expected, cwd)
114116
} else {
@@ -121,6 +123,28 @@ fn normalize_expected(expected: &str, cwd: Option<&Path>) -> String {
121123
}
122124
}
123125

126+
fn replace_dirty_msvc_impl(s: &str, is_msvc: bool) -> String {
127+
if is_msvc {
128+
s.replace("[DIRTY-MSVC]", "[DIRTY]")
129+
} else {
130+
use itertools::Itertools;
131+
132+
let mut new = s
133+
.lines()
134+
.filter(|it| !it.starts_with("[DIRTY-MSVC]"))
135+
.join("\n");
136+
137+
if s.ends_with("\n") {
138+
new.push_str("\n");
139+
}
140+
141+
new
142+
}
143+
}
144+
145+
fn replace_dirty_msvc(s: &str) -> String {
146+
replace_dirty_msvc_impl(s, cfg!(target_env = "msvc"))
147+
}
124148
/// Normalizes text for both actual and expected strings on Windows.
125149
fn normalize_windows(text: &str, cwd: Option<&Path>) -> String {
126150
// Let's not deal with / vs \ (windows...)
@@ -640,3 +664,113 @@ fn wild_str_cmp() {
640664
assert_ne!(WildStr::new(a), WildStr::new(b));
641665
}
642666
}
667+
668+
#[test]
669+
fn dirty_msvc() {
670+
let case = |expected: &str, wild: &str, msvc: bool| {
671+
assert_eq!(expected, &replace_dirty_msvc_impl(wild, msvc));
672+
};
673+
674+
// no replacements
675+
case("aa", "aa", false);
676+
case("aa", "aa", true);
677+
678+
// with replacements
679+
case(
680+
"\
681+
[DIRTY] a",
682+
"\
683+
[DIRTY-MSVC] a",
684+
true,
685+
);
686+
case(
687+
"",
688+
"\
689+
[DIRTY-MSVC] a",
690+
false,
691+
);
692+
case(
693+
"\
694+
[DIRTY] a
695+
[COMPILING] a",
696+
"\
697+
[DIRTY-MSVC] a
698+
[COMPILING] a",
699+
true,
700+
);
701+
case(
702+
"\
703+
[COMPILING] a",
704+
"\
705+
[DIRTY-MSVC] a
706+
[COMPILING] a",
707+
false,
708+
);
709+
710+
// test trailing newline behavior
711+
case(
712+
"\
713+
A
714+
B
715+
", "\
716+
A
717+
B
718+
", true,
719+
);
720+
721+
case(
722+
"\
723+
A
724+
B
725+
", "\
726+
A
727+
B
728+
", false,
729+
);
730+
731+
case(
732+
"\
733+
A
734+
B", "\
735+
A
736+
B", true,
737+
);
738+
739+
case(
740+
"\
741+
A
742+
B", "\
743+
A
744+
B", false,
745+
);
746+
747+
case(
748+
"\
749+
[DIRTY] a
750+
",
751+
"\
752+
[DIRTY-MSVC] a
753+
",
754+
true,
755+
);
756+
case(
757+
"",
758+
"\
759+
[DIRTY-MSVC] a",
760+
false,
761+
);
762+
763+
case(
764+
"\
765+
[DIRTY] a",
766+
"\
767+
[DIRTY-MSVC] a",
768+
true,
769+
);
770+
case(
771+
"",
772+
"\
773+
[DIRTY-MSVC] a",
774+
false,
775+
);
776+
}

tests/testsuite/features.rs

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -480,28 +480,16 @@ fn no_feature_doesnt_build() {
480480
.run();
481481
p.process(&p.bin("foo")).with_stdout("").run();
482482

483-
let mut e = p.cargo("build --features bar");
484-
485-
// MSVC does not include hash in binary filename, so it gets recompiled.
486-
if cfg!(target_env = "msvc") {
487-
e.with_stderr(
488-
"\
489-
[COMPILING] bar v0.0.1 ([CWD]/bar)
490-
[DIRTY] foo v0.0.1 ([CWD]): the list of features changed
491-
[COMPILING] foo v0.0.1 ([CWD])
492-
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
493-
",
494-
);
495-
} else {
496-
e.with_stderr(
483+
p.cargo("build --features bar")
484+
.with_stderr(
497485
"\
498486
[COMPILING] bar v0.0.1 ([CWD]/bar)
487+
[DIRTY-MSVC] foo v0.0.1 ([CWD]): the list of features changed
499488
[COMPILING] foo v0.0.1 ([CWD])
500489
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
501490
",
502-
);
503-
}
504-
e.run();
491+
)
492+
.run();
505493

506494
p.process(&p.bin("foo")).with_stdout("bar\n").run();
507495
}
@@ -551,27 +539,15 @@ fn default_feature_pulled_in() {
551539
.run();
552540
p.process(&p.bin("foo")).with_stdout("bar\n").run();
553541

554-
let mut e = p.cargo("build --no-default-features");
555-
556-
// MSVC does not include hash in binary filename, so it gets recompiled.
557-
if cfg!(target_env = "msvc") {
558-
e.with_stderr(
559-
"\
560-
[DIRTY] foo v0.0.1 ([CWD]): the list of features changed
561-
[COMPILING] foo v0.0.1 ([CWD])
562-
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
563-
",
564-
);
565-
} else {
566-
e.with_stderr(
542+
p.cargo("build --no-default-features")
543+
.with_stderr(
567544
"\
545+
[DIRTY-MSVC] foo v0.0.1 ([CWD]): the list of features changed
568546
[COMPILING] foo v0.0.1 ([CWD])
569547
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
570548
",
571-
);
572-
}
573-
574-
e.run();
549+
)
550+
.run();
575551

576552
p.process(&p.bin("foo")).with_stdout("").run();
577553
}

tests/testsuite/features_namespaced.rs

Lines changed: 12 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -322,34 +322,20 @@ fn namespaced_same_name() {
322322
.with_stdout("")
323323
.run();
324324

325-
let mut e = p.cargo("run --features baz");
326-
327-
// MSVC does not include hash in binary filename, so it gets recompiled.
328-
if cfg!(target_env = "msvc") {
329-
e.with_stderr(
330-
"\
331-
[DOWNLOADING] crates ...
332-
[DOWNLOADED] baz v0.1.0 [..]
333-
[COMPILING] baz v0.1.0
334-
[DIRTY] foo v0.0.1 ([..]): the list of features changed
335-
[COMPILING] foo v0.0.1 [..]
336-
[FINISHED] [..]
337-
[RUNNING] [..]
338-
",
339-
);
340-
} else {
341-
e.with_stderr(
325+
p.cargo("run --features baz")
326+
.with_stderr(
342327
"\
343328
[DOWNLOADING] crates ...
344329
[DOWNLOADED] baz v0.1.0 [..]
345330
[COMPILING] baz v0.1.0
331+
[DIRTY-MSVC] foo v0.0.1 ([..]): the list of features changed
346332
[COMPILING] foo v0.0.1 [..]
347333
[FINISHED] [..]
348334
[RUNNING] [..]
349335
",
350-
);
351-
}
352-
e.with_stdout("baz").run();
336+
)
337+
.with_stdout("baz")
338+
.run();
353339
}
354340

355341
#[cargo_test]
@@ -397,38 +383,22 @@ fn no_implicit_feature() {
397383
.with_stdout("")
398384
.run();
399385

400-
let mut e = p.cargo("run --features regex");
401-
402-
// MSVC does not include hash in binary filename, so it gets recompiled.
403-
if cfg!(target_env = "msvc") {
404-
e.with_stderr_unordered(
386+
p.cargo("run --features regex")
387+
.with_stderr_unordered(
405388
"\
406389
[DOWNLOADING] crates ...
407390
[DOWNLOADED] regex v1.0.0 [..]
408391
[DOWNLOADED] lazy_static v1.0.0 [..]
409392
[COMPILING] regex v1.0.0
410393
[COMPILING] lazy_static v1.0.0
411-
[DIRTY] foo v0.1.0 ([..]): the list of features changed
394+
[DIRTY-MSVC] foo v0.1.0 ([..]): the list of features changed
412395
[COMPILING] foo v0.1.0 [..]
413396
[FINISHED] [..]
414397
[RUNNING] `target/debug/foo[EXE]`
415398
",
416-
);
417-
} else {
418-
e.with_stderr_unordered(
419-
"\
420-
[DOWNLOADING] crates ...
421-
[DOWNLOADED] regex v1.0.0 [..]
422-
[DOWNLOADED] lazy_static v1.0.0 [..]
423-
[COMPILING] regex v1.0.0
424-
[COMPILING] lazy_static v1.0.0
425-
[COMPILING] foo v0.1.0 [..]
426-
[FINISHED] [..]
427-
[RUNNING] `target/debug/foo[EXE]`
428-
",
429-
);
430-
}
431-
e.with_stdout("regex").run();
399+
)
400+
.with_stdout("regex")
401+
.run();
432402

433403
p.cargo("run --features lazy_static")
434404
.with_stderr(

tests/testsuite/freshness.rs

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -485,32 +485,22 @@ fn changing_bin_features_caches_targets() {
485485
.run();
486486
p.rename_run("foo", "off1").with_stdout("feature off").run();
487487

488-
// MSVC does not include hash in binary filename, so it gets recompiled.
489-
if cfg!(target_env = "msvc") {
490-
p.cargo("build --features foo")
491-
.with_stderr(
492-
"\
493-
[DIRTY] foo v0.0.1 ([..]): the list of features changed
494-
[COMPILING] foo v0.0.1 ([..])
495-
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
496-
",
497-
)
498-
.run();
499-
} else {
500-
p.cargo("build --features foo")
501-
.with_stderr(
502-
"\
488+
p.cargo("build --features foo")
489+
.with_stderr(
490+
"\
491+
[DIRTY-MSVC] foo v0.0.1 ([..]): the list of features changed
503492
[COMPILING] foo v0.0.1 ([..])
504493
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
505494
",
506-
)
507-
.run();
508-
}
495+
)
496+
.run();
509497
p.rename_run("foo", "on1").with_stdout("feature on").run();
510498

511499
/* Targets should be cached from the first build */
512500

513501
let mut e = p.cargo("build");
502+
503+
// MSVC does not include hash in binary filename, so it gets recompiled.
514504
if cfg!(target_env = "msvc") {
515505
e.with_stderr(
516506
"\

0 commit comments

Comments
 (0)