Skip to content

Commit ddc63f2

Browse files
committed
test: simplify rebuild tests to address nondeterminism
``` ---- freshness::rebuild_tests_if_lib_changes stdout ---- running `/home/runner/work/cargo/cargo/target/debug/cargo build` running `/home/runner/work/cargo/cargo/target/debug/cargo test` running `/home/runner/work/cargo/cargo/target/debug/cargo build -v` running `/home/runner/work/cargo/cargo/target/debug/cargo test -v` error: test failed, to rerun pass `-p cargo --test testsuite` thread 'freshness::rebuild_tests_if_lib_changes' panicked at tests/testsuite/freshness.rs:633:10: ---- expected: tests/testsuite/freshness.rs:623:27 ++++ actual: stderr 1 1 | [DIRTY] foo v0.0.1 ([ROOT]/foo): the dependency foo was rebuilt ([TIME_DIFF_AFTER_LAST_BUILD]) 2 2 | [COMPILING] foo v0.0.1 ([ROOT]/foo) 3 3 | [RUNNING] `rustc --crate-name foo [..] 4 - [RUNNING] `rustc --crate-name foo [..] 5 4 | error[E0425]: cannot find function `foo` in crate `foo` 5 + --> tests/foo.rs:4:34 6 6 | ... 7 7 | [ERROR] could not compile `foo` (test "foo") due to 1 previous error 8 8 | ...∅ ```
1 parent d8a2a61 commit ddc63f2

File tree

2 files changed

+14
-34
lines changed

2 files changed

+14
-34
lines changed

tests/testsuite/freshness.rs

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -601,14 +601,7 @@ feature on
601601
fn rebuild_tests_if_lib_changes() {
602602
let p = project()
603603
.file("src/lib.rs", "pub fn foo() {}")
604-
.file(
605-
"tests/foo.rs",
606-
r#"
607-
extern crate foo;
608-
#[test]
609-
fn test() { foo::foo(); }
610-
"#,
611-
)
604+
.file("tests/foo-test.rs", "extern crate foo;")
612605
.build();
613606

614607
p.cargo("build").run();
@@ -617,18 +610,15 @@ fn rebuild_tests_if_lib_changes() {
617610
sleep_ms(1000);
618611
p.change_file("src/lib.rs", "");
619612

620-
p.cargo("build -v").run();
621-
p.cargo("test -v")
622-
.with_status(101)
613+
p.cargo("build").run();
614+
p.cargo("test -v --test foo-test")
623615
.with_stderr_data(str![[r#"
624616
[DIRTY] foo v0.0.1 ([ROOT]/foo): the dependency foo was rebuilt ([TIME_DIFF_AFTER_LAST_BUILD])
625617
[COMPILING] foo v0.0.1 ([ROOT]/foo)
626-
[RUNNING] `rustc --crate-name foo [..]
627-
[RUNNING] `rustc --crate-name foo [..]
628-
error[E0425]: cannot find function `foo` in crate `foo`
629-
...
630-
[ERROR] could not compile `foo` (test "foo") due to 1 previous error
631-
...
618+
[RUNNING] `rustc --crate-name foo_test [..]`
619+
[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
620+
[RUNNING] `[ROOT]/foo/target/debug/deps/foo_test-[HASH][EXE]`
621+
632622
"#]])
633623
.run();
634624
}

tests/testsuite/freshness_checksum.rs

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -765,14 +765,7 @@ feature on
765765
fn rebuild_tests_if_lib_changes() {
766766
let p = project()
767767
.file("src/lib.rs", "pub fn foo() {}")
768-
.file(
769-
"tests/foo.rs",
770-
r#"
771-
extern crate foo;
772-
#[test]
773-
fn test() { foo::foo(); }
774-
"#,
775-
)
768+
.file("tests/foo-test.rs", "extern crate foo;")
776769
.build();
777770

778771
p.cargo("build -Zchecksum-freshness")
@@ -784,21 +777,18 @@ fn rebuild_tests_if_lib_changes() {
784777

785778
p.change_file("src/lib.rs", "");
786779

787-
p.cargo("build -Zchecksum-freshness -v")
780+
p.cargo("build -Zchecksum-freshness")
788781
.masquerade_as_nightly_cargo(&["checksum-freshness"])
789782
.run();
790-
p.cargo("test -Zchecksum-freshness -v")
783+
p.cargo("test -Zchecksum-freshness -v --test foo-test")
791784
.masquerade_as_nightly_cargo(&["checksum-freshness"])
792-
.with_status(101)
793785
.with_stderr_data(str![[r#"
794786
[DIRTY] foo v0.0.1 ([ROOT]/foo): the dependency foo was rebuilt ([TIME_DIFF_AFTER_LAST_BUILD])
795787
[COMPILING] foo v0.0.1 ([ROOT]/foo)
796-
[RUNNING] `rustc --crate-name foo [..]
797-
[RUNNING] `rustc --crate-name foo [..]
798-
error[E0425]: cannot find function `foo` in crate `foo`
799-
...
800-
[ERROR] could not compile `foo` (test "foo") due to 1 previous error
801-
...
788+
[RUNNING] `rustc --crate-name foo_test [..]`
789+
[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
790+
[RUNNING] `[ROOT]/foo/target/debug/deps/foo_test-[HASH][EXE]`
791+
802792
"#]])
803793
.run();
804794
}

0 commit comments

Comments
 (0)