Skip to content

Commit

Permalink
Merge branch 'master' into issue-14039
Browse files Browse the repository at this point in the history
  • Loading branch information
henry40408 committed Jun 19, 2024
2 parents ba19274 + 3ed207e commit 0226ca4
Show file tree
Hide file tree
Showing 6 changed files with 801 additions and 812 deletions.
16 changes: 8 additions & 8 deletions crates/cargo-test-support/src/compare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,45 +149,45 @@ fn add_common_redactions(subs: &mut snapbox::Redactions) {
// For e2e tests
subs.insert(
"[ELAPSED]",
regex!("[FINISHED].*in (?<redacted>[0-9]+(\\.[0-9]+))s"),
regex!(r"\[FINISHED\].*in (?<redacted>[0-9]+(\.[0-9]+))s"),
)
.unwrap();
// for UI tests
subs.insert(
"[ELAPSED]",
regex!("Finished.*in (?<redacted>[0-9]+(\\.[0-9]+))s"),
regex!(r"Finished.*in (?<redacted>[0-9]+(\.[0-9]+))s"),
)
.unwrap();
// output from libtest
subs.insert(
"[ELAPSED]",
regex!("; finished in (?<redacted>[0-9]+(\\.[0-9]+))s"),
regex!(r"; finished in (?<redacted>[0-9]+(\.[0-9]+))s"),
)
.unwrap();
subs.insert(
"[FILE_SIZE]",
regex!("(?<redacted>[0-9]+(\\.[0-9]+)([a-zA-Z]i)?)B"),
regex!(r"(?<redacted>[0-9]+(\.[0-9]+)([a-zA-Z]i)?)B"),
)
.unwrap();
subs.insert(
"[HASH]",
regex!("home/\\.cargo/registry/src/-(?<redacted>[a-z0-9]+)"),
regex!(r"home/\.cargo/registry/src/-(?<redacted>[a-z0-9]+)"),
)
.unwrap();
subs.insert("[HASH]", regex!("/[a-z0-9\\-_]+-(?<redacted>[0-9a-f]{16})"))
subs.insert("[HASH]", regex!(r"/[a-z0-9\-_]+-(?<redacted>[0-9a-f]{16})"))
.unwrap();
subs.insert("[HOST_TARGET]", rustc_host()).unwrap();
if let Some(alt_target) = try_alternate() {
subs.insert("[ALT_TARGET]", alt_target).unwrap();
}
subs.insert(
"[AVG_ELAPSED]",
regex!("(?<redacted>[0-9]+(\\.[0-9]+)?) ns/iter"),
regex!(r"(?<redacted>[0-9]+(\.[0-9]+)?) ns/iter"),
)
.unwrap();
subs.insert(
"[JITTER]",
regex!("ns/iter \\(\\+/- (?<redacted>[0-9]+(\\.[0-9]+)?)\\)"),
regex!(r"ns/iter \(\+/- (?<redacted>[0-9]+(\.[0-9]+)?)\)"),
)
.unwrap();
}
Expand Down
123 changes: 73 additions & 50 deletions tests/testsuite/build_script_extra_link_arg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
// because MSVC link.exe just gives a warning on unknown flags (how helpful!),
// and other linkers will return an error.

#![allow(deprecated)]

use cargo_test_support::registry::Package;
use cargo_test_support::str;
use cargo_test_support::{basic_bin_manifest, basic_lib_manifest, basic_manifest, project};

#[cargo_test]
Expand All @@ -26,8 +25,11 @@ fn build_script_extra_link_arg_bin() {

p.cargo("build -v")
.without_status()
.with_stderr_contains(
"[RUNNING] `rustc --crate-name foo [..]-C link-arg=--this-is-a-bogus-flag[..]",
.with_stderr_data(
"\
...
[RUNNING] `rustc --crate-name foo [..]-C link-arg=--this-is-a-bogus-flag[..]
...",
)
.run();
}
Expand Down Expand Up @@ -66,11 +68,17 @@ fn build_script_extra_link_arg_bin_single() {

p.cargo("build -v")
.without_status()
.with_stderr_contains(
"[RUNNING] `rustc --crate-name foo [..]-C link-arg=--bogus-flag-all -C link-arg=--bogus-flag-foo[..]",
.with_stderr_data(
"\
...
[RUNNING] `rustc --crate-name foo [..]-C link-arg=--bogus-flag-all -C link-arg=--bogus-flag-foo[..]
...",
)
.with_stderr_contains(
"[RUNNING] `rustc --crate-name bar [..]-C link-arg=--bogus-flag-all -C link-arg=--bogus-flag-bar[..]",
.with_stderr_data(
"\
...
[RUNNING] `rustc --crate-name bar [..]-C link-arg=--bogus-flag-all -C link-arg=--bogus-flag-bar[..]
...",
)
.run();
}
Expand All @@ -92,8 +100,11 @@ fn build_script_extra_link_arg() {

p.cargo("build -v")
.without_status()
.with_stderr_contains(
"[RUNNING] `rustc --crate-name foo [..]-C link-arg=--this-is-a-bogus-flag[..]",
.with_stderr_data(
"\
...
[RUNNING] `rustc --crate-name foo [..]-C link-arg=--this-is-a-bogus-flag[..]
...",
)
.run();
}
Expand Down Expand Up @@ -127,11 +138,12 @@ fn link_arg_missing_target() {

p.cargo("check")
.with_status(101)
.with_stderr("\
[COMPILING] foo [..]
error: invalid instruction `cargo::rustc-link-arg-bins` from build script of `foo v0.0.1 ([ROOT]/foo)`
.with_stderr_data(str![[r#"
[COMPILING] foo v0.0.1 ([ROOT]/foo)
[ERROR] invalid instruction `cargo::rustc-link-arg-bins` from build script of `foo v0.0.1 ([ROOT]/foo)`
The package foo v0.0.1 ([ROOT]/foo) does not have a bin target.
")
"#]])
.run();

p.change_file(
Expand All @@ -141,13 +153,12 @@ The package foo v0.0.1 ([ROOT]/foo) does not have a bin target.

p.cargo("check")
.with_status(101)
.with_stderr(
"\
[COMPILING] foo [..]
error: invalid instruction `cargo::rustc-link-arg-bin` from build script of `foo v0.0.1 ([ROOT]/foo)`
.with_stderr_data(str![[r#"
[COMPILING] foo v0.0.1 ([ROOT]/foo)
[ERROR] invalid instruction `cargo::rustc-link-arg-bin` from build script of `foo v0.0.1 ([ROOT]/foo)`
The package foo v0.0.1 ([ROOT]/foo) does not have a bin target with the name `abc`.
",
)
"#]])
.run();

p.change_file(
Expand All @@ -157,13 +168,12 @@ The package foo v0.0.1 ([ROOT]/foo) does not have a bin target with the name `ab

p.cargo("check")
.with_status(101)
.with_stderr(
"\
[COMPILING] foo [..]
error: invalid instruction `cargo::rustc-link-arg-bin=abc` from build script of `foo v0.0.1 ([ROOT]/foo)`
.with_stderr_data(str![[r#"
[COMPILING] foo v0.0.1 ([ROOT]/foo)
[ERROR] invalid instruction `cargo::rustc-link-arg-bin=abc` from build script of `foo v0.0.1 ([ROOT]/foo)`
The instruction should have the form cargo::rustc-link-arg-bin=BIN=ARG
",
)
"#]])
.run();
}

Expand Down Expand Up @@ -203,24 +213,26 @@ fn cdylib_link_arg_transitive() {
.build();
p.cargo("build -v")
.without_status()
.with_stderr_contains(
.with_stderr_data(
"\
[COMPILING] bar v1.0.0 [..]
...
[COMPILING] bar v1.0.0 ([ROOT]/foo/bar)
[RUNNING] `rustc --crate-name build_script_build --edition=2015 bar/build.rs [..]
[RUNNING] `[..]build-script-build[..]
warning: [email protected]: cargo::rustc-link-arg-cdylib was specified in the build script of bar v1.0.0 \
[RUNNING] `[ROOT]/foo/target/debug/build/bar-[HASH]/build-script-build`
[WARNING] [email protected]: cargo::rustc-link-arg-cdylib was specified in the build script of bar v1.0.0 \
([ROOT]/foo/bar), but that package does not contain a cdylib target
Allowing this was an unintended change in the 1.50 release, and may become an error in \
the future. For more information, see <https://github.com/rust-lang/cargo/issues/9562>.
[RUNNING] `rustc --crate-name bar --edition=2015 bar/src/lib.rs [..]
[COMPILING] foo v0.1.0 [..]
[COMPILING] foo v0.1.0 ([ROOT]/foo)
[RUNNING] `rustc --crate-name foo --edition=2015 src/lib.rs [..]-C link-arg=--bogus[..]`
",
...",
)
.run();
}

#[allow(deprecated)]
#[cargo_test]
fn link_arg_transitive_not_allowed() {
// Verify that transitive dependencies don't pass link args.
Expand Down Expand Up @@ -260,21 +272,20 @@ fn link_arg_transitive_not_allowed() {
.build();

p.cargo("build -v")
.with_stderr(
"\
[UPDATING] [..]
.with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index
[LOCKING] 2 packages to latest compatible versions
[DOWNLOADING] [..]
[DOWNLOADED] [..]
[DOWNLOADING] crates ...
[DOWNLOADED] bar v1.0.0 (registry `dummy-registry`)
[COMPILING] bar v1.0.0
[RUNNING] `rustc --crate-name build_script_build [..]
[RUNNING] `[..]/build-script-build[..]
[RUNNING] `[ROOT]/foo/target/debug/build/bar-[HASH]/build-script-build`
[RUNNING] `rustc --crate-name bar [..]
[COMPILING] foo v0.1.0 [..]
[COMPILING] foo v0.1.0 ([ROOT]/foo)
[RUNNING] `rustc --crate-name foo --edition=2015 src/lib.rs [..]
[FINISHED] `dev` profile [..]
",
)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
"#]])
.with_stderr_does_not_contain("--bogus")
.run();
}
Expand Down Expand Up @@ -303,8 +314,11 @@ fn link_arg_with_doctest() {

p.cargo("test --doc -v")
.without_status()
.with_stderr_contains(
"[RUNNING] `rustdoc [..]--crate-name foo [..]-C link-arg=--this-is-a-bogus-flag[..]",
.with_stderr_data(
"\
...
[RUNNING] `rustdoc [..]--crate-name foo [..]-C link-arg=--this-is-a-bogus-flag[..]
...",
)
.run();
}
Expand All @@ -327,8 +341,11 @@ fn build_script_extra_link_arg_tests() {

p.cargo("test -v")
.without_status()
.with_stderr_contains(
"[RUNNING] `rustc --crate-name test_foo [..]-C link-arg=--this-is-a-bogus-flag[..]",
.with_stderr_data(
"\
...
[RUNNING] `rustc --crate-name test_foo [..]-C link-arg=--this-is-a-bogus-flag[..]
...",
)
.run();
}
Expand All @@ -351,8 +368,11 @@ fn build_script_extra_link_arg_benches() {

p.cargo("bench -v")
.without_status()
.with_stderr_contains(
"[RUNNING] `rustc --crate-name bench_foo [..]-C link-arg=--this-is-a-bogus-flag[..]",
.with_stderr_data(
"\
...
[RUNNING] `rustc --crate-name bench_foo [..]-C link-arg=--this-is-a-bogus-flag[..]
...",
)
.run();
}
Expand All @@ -375,8 +395,11 @@ fn build_script_extra_link_arg_examples() {

p.cargo("build -v --examples")
.without_status()
.with_stderr_contains(
"[RUNNING] `rustc --crate-name example_foo [..]-C link-arg=--this-is-a-bogus-flag[..]",
.with_stderr_data(
"\
...
[RUNNING] `rustc --crate-name example_foo [..]-C link-arg=--this-is-a-bogus-flag[..]
...",
)
.run();
}
2 changes: 0 additions & 2 deletions tests/testsuite/cache_lock.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//! Tests for `CacheLock`.
#![allow(deprecated)]

use crate::config::GlobalContextBuilder;
use cargo::util::cache_lock::{CacheLockMode, CacheLocker};
use cargo_test_support::paths::{self, CargoPathExt};
Expand Down
Loading

0 comments on commit 0226ca4

Please sign in to comment.