Skip to content

Commit fd4f492

Browse files
authored
Update tests to fix nightly errors (#15110)
There were some changes in the latest nightly which is breaking some tests: * rust-lang/rust#133154 updated the wording of a message. I adjusted the test to be less sensitive to the exact wording. * rust-lang/rust#119286 added the `linker-messages` lint which shows the output from the linker. Some of our tests were passing dummy flags to the linker, which it was complaining about. This updates it so that it uses real directories. * This also fixes an incidental issue, where `build_script_needed_for_host_and_target` was not testing for the correct command-line flags. These got lost in #14132.
2 parents e63457a + c35cb56 commit fd4f492

File tree

3 files changed

+35
-18
lines changed

3 files changed

+35
-18
lines changed

tests/testsuite/build_script.rs

+26-13
Original file line numberDiff line numberDiff line change
@@ -878,20 +878,26 @@ fn custom_build_script_rustc_flags() {
878878
"foo/build.rs",
879879
r#"
880880
fn main() {
881-
println!("cargo::rustc-flags=-l nonexistinglib -L /dummy/path1 -L /dummy/path2");
881+
let root = std::env::current_dir().unwrap();
882+
let root = root.parent().unwrap();
883+
println!("cargo::rustc-flags=-l nonexistinglib \
884+
-L {R}/dummy-path1 -L {R}/dummy-path2", R=root.display());
882885
}
883886
"#,
884887
)
885888
.build();
889+
p.root().join("dummy-path1").mkdir_p();
890+
p.root().join("dummy-path2").mkdir_p();
886891

887-
p.cargo("build --verbose").with_stderr_data(str![[r#"
892+
p.cargo("build --verbose")
893+
.with_stderr_data(str![[r#"
888894
[LOCKING] 1 package to latest compatible version
889895
[COMPILING] foo v0.5.0 ([ROOT]/foo/foo)
890896
[RUNNING] `rustc --crate-name build_script_build --edition=2015 foo/build.rs [..]`
891897
[RUNNING] `[ROOT]/foo/target/debug/build/foo-[HASH]/build-script-build`
892-
[RUNNING] `rustc --crate-name foo --edition=2015 foo/src/lib.rs [..]-L dependency=[ROOT]/foo/target/debug/deps -L /dummy/path1 -L /dummy/path2 -l nonexistinglib`
898+
[RUNNING] `rustc --crate-name foo --edition=2015 foo/src/lib.rs [..]-L dependency=[ROOT]/foo/target/debug/deps -L [ROOT]/foo/dummy-path1 -L [ROOT]/foo/dummy-path2 -l nonexistinglib`
893899
[COMPILING] bar v0.5.0 ([ROOT]/foo)
894-
[RUNNING] `rustc --crate-name bar --edition=2015 src/main.rs [..]-L dependency=[ROOT]/foo/target/debug/deps --extern foo=[ROOT]/foo/target/debug/deps/libfoo-[HASH].rlib -L /dummy/path1 -L /dummy/path2`
900+
[RUNNING] `rustc --crate-name bar --edition=2015 src/main.rs [..]-L dependency=[ROOT]/foo/target/debug/deps --extern foo=[ROOT]/foo/target/debug/deps/libfoo-[HASH].rlib -L [ROOT]/foo/dummy-path1 -L [ROOT]/foo/dummy-path2`
895901
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
896902
897903
"#]]).run();
@@ -932,20 +938,25 @@ fn custom_build_script_rustc_flags_no_space() {
932938
"foo/build.rs",
933939
r#"
934940
fn main() {
935-
println!("cargo::rustc-flags=-lnonexistinglib -L/dummy/path1 -L/dummy/path2");
941+
let root = std::env::current_dir().unwrap();
942+
let root = root.parent().unwrap();
943+
println!("cargo::rustc-flags=-lnonexistinglib \
944+
-L {R}/dummy-path1 -L {R}/dummy-path2", R=root.display());
936945
}
937946
"#,
938947
)
939948
.build();
949+
p.root().join("dummy-path1").mkdir_p();
950+
p.root().join("dummy-path2").mkdir_p();
940951

941952
p.cargo("build --verbose").with_stderr_data(str![[r#"
942953
[LOCKING] 1 package to latest compatible version
943954
[COMPILING] foo v0.5.0 ([ROOT]/foo/foo)
944955
[RUNNING] `rustc --crate-name build_script_build --edition=2015 foo/build.rs [..]`
945956
[RUNNING] `[ROOT]/foo/target/debug/build/foo-[HASH]/build-script-build`
946-
[RUNNING] `rustc --crate-name foo --edition=2015 foo/src/lib.rs [..]-L dependency=[ROOT]/foo/target/debug/deps -L /dummy/path1 -L /dummy/path2 -l nonexistinglib`
957+
[RUNNING] `rustc --crate-name foo --edition=2015 foo/src/lib.rs [..]-L dependency=[ROOT]/foo/target/debug/deps -L [ROOT]/foo/dummy-path1 -L [ROOT]/foo/dummy-path2 -l nonexistinglib`
947958
[COMPILING] bar v0.5.0 ([ROOT]/foo)
948-
[RUNNING] `rustc --crate-name bar --edition=2015 src/main.rs [..]-L dependency=[ROOT]/foo/target/debug/deps --extern foo=[ROOT]/foo/target/debug/deps/libfoo-[HASH].rlib -L /dummy/path1 -L /dummy/path2`
959+
[RUNNING] `rustc --crate-name bar --edition=2015 src/main.rs [..]-L dependency=[ROOT]/foo/target/debug/deps --extern foo=[ROOT]/foo/target/debug/deps/libfoo-[HASH].rlib -L [ROOT]/foo/dummy-path1 -L [ROOT]/foo/dummy-path2`
949960
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
950961
951962
"#]]).run();
@@ -2975,24 +2986,26 @@ fn flags_go_into_tests() {
29752986
"a/build.rs",
29762987
r#"
29772988
fn main() {
2978-
println!("cargo::rustc-link-search=test");
2989+
let path = std::env::current_dir().unwrap().parent().unwrap().join("link-dir");
2990+
println!("cargo::rustc-link-search={}", path.display());
29792991
}
29802992
"#,
29812993
)
29822994
.build();
2995+
p.root().join("link-dir").mkdir_p();
29832996

29842997
p.cargo("test -v --test=foo")
29852998
.with_stderr_data(str![[r#"
29862999
[LOCKING] 2 packages to latest compatible versions
29873000
[COMPILING] a v0.5.0 ([ROOT]/foo/a)
29883001
[RUNNING] `rustc [..] a/build.rs [..]`
29893002
[RUNNING] `[ROOT]/foo/target/debug/build/a-[HASH]/build-script-build`
2990-
[RUNNING] `rustc [..] a/src/lib.rs [..] -L test`
3003+
[RUNNING] `rustc [..] a/src/lib.rs [..] -L [ROOT]/foo/link-dir`
29913004
[COMPILING] b v0.5.0 ([ROOT]/foo/b)
2992-
[RUNNING] `rustc [..] b/src/lib.rs [..] -L test`
3005+
[RUNNING] `rustc [..] b/src/lib.rs [..] -L [ROOT]/foo/link-dir`
29933006
[COMPILING] foo v0.5.0 ([ROOT]/foo)
2994-
[RUNNING] `rustc [..] src/lib.rs [..] -L test`
2995-
[RUNNING] `rustc [..] tests/foo.rs [..] -L test`
3007+
[RUNNING] `rustc [..] src/lib.rs [..] -L [ROOT]/foo/link-dir`
3008+
[RUNNING] `rustc [..] tests/foo.rs [..] -L [ROOT]/foo/link-dir`
29963009
[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
29973010
[RUNNING] `[ROOT]/foo/target/debug/deps/foo-[HASH][EXE]`
29983011
@@ -3011,7 +3024,7 @@ test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; fini
30113024
.with_stderr_data(str![[r#"
30123025
[FRESH] a v0.5.0 ([ROOT]/foo/a)
30133026
[COMPILING] b v0.5.0 ([ROOT]/foo/b)
3014-
[RUNNING] `rustc --crate-name b [..] -L test`
3027+
[RUNNING] `rustc --crate-name b [..] -L [ROOT]/foo/link-dir`
30153028
[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
30163029
[RUNNING] `[ROOT]/foo/target/debug/deps/b-[HASH][EXE]`
30173030

tests/testsuite/cross_compile.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,9 @@ fn build_script_needed_for_host_and_target() {
731731
use std::env;
732732
fn main() {
733733
let target = env::var("TARGET").unwrap();
734-
println!("cargo::rustc-flags=-L /path/to/{}", target);
734+
let root = std::env::current_dir().unwrap();
735+
let root = root.parent().unwrap().join(format!("link-{target}"));
736+
println!("cargo::rustc-flags=-L {}", root.display());
735737
}
736738
"#,
737739
)
@@ -757,6 +759,8 @@ fn build_script_needed_for_host_and_target() {
757759
",
758760
)
759761
.build();
762+
p.root().join(format!("link-{target}")).mkdir_p();
763+
p.root().join(format!("link-{}", rustc_host())).mkdir_p();
760764

761765
p.cargo("build -v --target")
762766
.arg(&target)
@@ -769,11 +773,11 @@ fn build_script_needed_for_host_and_target() {
769773
[RUNNING] `rustc [..] d1/src/lib.rs [..] --out-dir [ROOT]/foo/target/debug/deps [..]
770774
[RUNNING] `rustc [..] d1/src/lib.rs [..] --out-dir [ROOT]/foo/target/[ALT_TARGET]/debug/deps [..]
771775
[COMPILING] d2 v0.0.0 ([ROOT]/foo/d2)
772-
[RUNNING] `rustc [..] d2/src/lib.rs [..] --out-dir [ROOT]/foo/target/debug/deps [..]
776+
[RUNNING] `rustc [..] d2/src/lib.rs [..] --out-dir [ROOT]/foo/target/debug/deps [..]-L [ROOT]/foo/link-[HOST_TARGET]`
773777
[COMPILING] foo v0.0.0 ([ROOT]/foo)
774-
[RUNNING] `rustc [..] build.rs [..] --out-dir [ROOT]/foo/target/debug/build/foo-[HASH] [..]
778+
[RUNNING] `rustc [..] build.rs [..] --out-dir [ROOT]/foo/target/debug/build/foo-[HASH] [..]-L [ROOT]/foo/link-[HOST_TARGET]`
775779
[RUNNING] `[ROOT]/foo/target/debug/build/foo-[HASH]/build-script-build`
776-
[RUNNING] `rustc [..] src/main.rs [..] --out-dir [ROOT]/foo/target/[ALT_TARGET]/debug/deps --target [ALT_TARGET] [..]
780+
[RUNNING] `rustc [..] src/main.rs [..] --out-dir [ROOT]/foo/target/[ALT_TARGET]/debug/deps --target [ALT_TARGET] [..]-L [ROOT]/foo/link-[ALT_TARGET]`
777781
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
778782
779783
"#]].unordered())

tests/testsuite/standard_lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ fn no_implicit_alloc() {
699699
.target_host()
700700
.with_stderr_data(str![[r#"
701701
...
702-
error[E0433]: failed to resolve: use of undeclared crate or module `alloc`
702+
error[E0433]: failed to resolve[..]`alloc`
703703
...
704704
"#]])
705705
.with_status(101)

0 commit comments

Comments
 (0)