mirror of
https://github.com/rust-lang/cargo.git
synced 2025-10-01 11:30:39 +00:00
Auto merge of #10929 - ehuss:ignore-reason, r=weihanglo
Add reasons to all ignored tests. This adds a reason string to all `#[ignore]` attributes. This will be displayed when running the test (since 1.61), which can help quickly see and identify why tests are being ignored. It looks roughly like: ``` test basic ... ignored, requires nightly, CARGO_RUN_BUILD_STD_TESTS must be set test build::simple_terminal_width ... ignored, --diagnostic-width is stabilized in 1.64 test check_cfg::features_with_cargo_check ... ignored, --check-cfg is unstable test plugins::panic_abort_plugins ... ignored, requires rustc_private ```
This commit is contained in:
commit
333478d0aa
@ -20,7 +20,17 @@ pub fn cargo_test(attr: TokenStream, item: TokenStream) -> TokenStream {
|
|||||||
// but they don't really handle the absence of files well.
|
// but they don't really handle the absence of files well.
|
||||||
let mut ignore = false;
|
let mut ignore = false;
|
||||||
let mut requires_reason = false;
|
let mut requires_reason = false;
|
||||||
let mut found_reason = false;
|
let mut explicit_reason = None;
|
||||||
|
let mut implicit_reasons = Vec::new();
|
||||||
|
macro_rules! set_ignore {
|
||||||
|
($predicate:expr, $($arg:tt)*) => {
|
||||||
|
let p = $predicate;
|
||||||
|
ignore |= p;
|
||||||
|
if p {
|
||||||
|
implicit_reasons.push(std::fmt::format(format_args!($($arg)*)));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
let is_not_nightly = !version().1;
|
let is_not_nightly = !version().1;
|
||||||
for rule in split_rules(attr) {
|
for rule in split_rules(attr) {
|
||||||
match rule.as_str() {
|
match rule.as_str() {
|
||||||
@ -29,57 +39,81 @@ pub fn cargo_test(attr: TokenStream, item: TokenStream) -> TokenStream {
|
|||||||
// explicit opt-in (these generally only work on linux, and
|
// explicit opt-in (these generally only work on linux, and
|
||||||
// have some extra requirements, and are slow, and can pollute
|
// have some extra requirements, and are slow, and can pollute
|
||||||
// the environment since it downloads dependencies).
|
// the environment since it downloads dependencies).
|
||||||
ignore |= is_not_nightly;
|
set_ignore!(is_not_nightly, "requires nightly");
|
||||||
ignore |= option_env!("CARGO_RUN_BUILD_STD_TESTS").is_none();
|
set_ignore!(
|
||||||
|
option_env!("CARGO_RUN_BUILD_STD_TESTS").is_none(),
|
||||||
|
"CARGO_RUN_BUILD_STD_TESTS must be set"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
"build_std_mock" => {
|
"build_std_mock" => {
|
||||||
// Only run the "mock" build-std tests on nightly and disable
|
// Only run the "mock" build-std tests on nightly and disable
|
||||||
// for windows-gnu which is missing object files (see
|
// for windows-gnu which is missing object files (see
|
||||||
// https://github.com/rust-lang/wg-cargo-std-aware/issues/46).
|
// https://github.com/rust-lang/wg-cargo-std-aware/issues/46).
|
||||||
ignore |= is_not_nightly;
|
set_ignore!(is_not_nightly, "requires nightly");
|
||||||
ignore |= cfg!(all(target_os = "windows", target_env = "gnu"));
|
set_ignore!(
|
||||||
|
cfg!(all(target_os = "windows", target_env = "gnu")),
|
||||||
|
"does not work on windows-gnu"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
"nightly" => {
|
"nightly" => {
|
||||||
requires_reason = true;
|
requires_reason = true;
|
||||||
ignore |= is_not_nightly;
|
set_ignore!(is_not_nightly, "requires nightly");
|
||||||
}
|
}
|
||||||
s if s.starts_with("requires_") => {
|
s if s.starts_with("requires_") => {
|
||||||
let command = &s[9..];
|
let command = &s[9..];
|
||||||
ignore |= !has_command(command);
|
set_ignore!(!has_command(command), "{command} not installed");
|
||||||
}
|
}
|
||||||
s if s.starts_with(">=1.") => {
|
s if s.starts_with(">=1.") => {
|
||||||
requires_reason = true;
|
requires_reason = true;
|
||||||
let min_minor = s[4..].parse().unwrap();
|
let min_minor = s[4..].parse().unwrap();
|
||||||
ignore |= version().0 < min_minor;
|
let minor = version().0;
|
||||||
|
set_ignore!(minor < min_minor, "requires rustc 1.{minor} or newer");
|
||||||
}
|
}
|
||||||
s if s.starts_with("reason=") => {
|
s if s.starts_with("reason=") => {
|
||||||
found_reason = true;
|
explicit_reason = Some(s[7..].parse().unwrap());
|
||||||
}
|
}
|
||||||
_ => panic!("unknown rule {:?}", rule),
|
_ => panic!("unknown rule {:?}", rule),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if requires_reason && !found_reason {
|
if requires_reason && explicit_reason.is_none() {
|
||||||
panic!(
|
panic!(
|
||||||
"#[cargo_test] with a rule also requires a reason, \
|
"#[cargo_test] with a rule also requires a reason, \
|
||||||
such as #[cargo_test(nightly, reason = \"needs -Z unstable-thing\")]"
|
such as #[cargo_test(nightly, reason = \"needs -Z unstable-thing\")]"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Construct the appropriate attributes.
|
||||||
let span = Span::call_site();
|
let span = Span::call_site();
|
||||||
let mut ret = TokenStream::new();
|
let mut ret = TokenStream::new();
|
||||||
let add_attr = |ret: &mut TokenStream, attr_name| {
|
let add_attr = |ret: &mut TokenStream, attr_name, attr_input| {
|
||||||
ret.extend(Some(TokenTree::from(Punct::new('#', Spacing::Alone))));
|
ret.extend(Some(TokenTree::from(Punct::new('#', Spacing::Alone))));
|
||||||
let attr = TokenTree::from(Ident::new(attr_name, span));
|
let attr = TokenTree::from(Ident::new(attr_name, span));
|
||||||
|
let mut attr_stream: TokenStream = attr.into();
|
||||||
|
if let Some(input) = attr_input {
|
||||||
|
attr_stream.extend(input);
|
||||||
|
}
|
||||||
ret.extend(Some(TokenTree::from(Group::new(
|
ret.extend(Some(TokenTree::from(Group::new(
|
||||||
Delimiter::Bracket,
|
Delimiter::Bracket,
|
||||||
attr.into(),
|
attr_stream,
|
||||||
))));
|
))));
|
||||||
};
|
};
|
||||||
add_attr(&mut ret, "test");
|
add_attr(&mut ret, "test", None);
|
||||||
if ignore {
|
if ignore {
|
||||||
add_attr(&mut ret, "ignore");
|
let reason = explicit_reason
|
||||||
|
.or_else(|| {
|
||||||
|
(!implicit_reasons.is_empty())
|
||||||
|
.then(|| TokenTree::from(Literal::string(&implicit_reasons.join(", "))).into())
|
||||||
|
})
|
||||||
|
.map(|reason: TokenStream| {
|
||||||
|
let mut stream = TokenStream::new();
|
||||||
|
stream.extend(Some(TokenTree::from(Punct::new('=', Spacing::Alone))));
|
||||||
|
stream.extend(Some(reason));
|
||||||
|
stream
|
||||||
|
});
|
||||||
|
add_attr(&mut ret, "ignore", reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Find where the function body starts, and add the boilerplate at the start.
|
||||||
for token in item {
|
for token in item {
|
||||||
let group = match token {
|
let group = match token {
|
||||||
TokenTree::Group(g) => {
|
TokenTree::Group(g) => {
|
||||||
|
@ -5,7 +5,7 @@ use cargo_test_support::{paths, project, registry::Package};
|
|||||||
#[cargo_test]
|
#[cargo_test]
|
||||||
// I don't know why, but `Command` forces all env keys to be upper case on
|
// I don't know why, but `Command` forces all env keys to be upper case on
|
||||||
// Windows. Seems questionable, since I think Windows is case-preserving.
|
// Windows. Seems questionable, since I think Windows is case-preserving.
|
||||||
#[cfg_attr(windows, ignore)]
|
#[cfg_attr(windows, ignore = "broken due to not preserving case on Windows")]
|
||||||
fn source_config_env() {
|
fn source_config_env() {
|
||||||
// Try to define [source] with environment variables.
|
// Try to define [source] with environment variables.
|
||||||
let p = project()
|
let p = project()
|
||||||
|
@ -1331,7 +1331,8 @@ fn build_script_deps_adopts_target_platform_if_target_equals_target() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cargo_test]
|
#[cargo_test]
|
||||||
#[cfg_attr(target_env = "msvc", ignore)] // TODO(ST): rename bar (dependency) to something else and un-ignore this with RFC-3176
|
// TODO(ST): rename bar (dependency) to something else and un-ignore this with RFC-3176
|
||||||
|
#[cfg_attr(target_env = "msvc", ignore = "msvc not working")]
|
||||||
fn profile_override_basic() {
|
fn profile_override_basic() {
|
||||||
let p = project()
|
let p = project()
|
||||||
.file(
|
.file(
|
||||||
@ -1450,7 +1451,7 @@ foo v0.0.0 ([CWD])
|
|||||||
// For reference, see comments by ehuss https://github.com/rust-lang/cargo/pull/9992#discussion_r801086315 and
|
// For reference, see comments by ehuss https://github.com/rust-lang/cargo/pull/9992#discussion_r801086315 and
|
||||||
// joshtriplett https://github.com/rust-lang/cargo/pull/9992#issuecomment-1033394197 .
|
// joshtriplett https://github.com/rust-lang/cargo/pull/9992#issuecomment-1033394197 .
|
||||||
#[cargo_test]
|
#[cargo_test]
|
||||||
#[ignore]
|
#[ignore = "broken, need artifact info in index"]
|
||||||
fn targets_are_picked_up_from_non_workspace_artifact_deps() {
|
fn targets_are_picked_up_from_non_workspace_artifact_deps() {
|
||||||
if cross_compile::disabled() {
|
if cross_compile::disabled() {
|
||||||
return;
|
return;
|
||||||
|
@ -4236,8 +4236,10 @@ fn rename_with_link_search_path() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cargo_test]
|
#[cargo_test]
|
||||||
// Don't have a cdylib cross target on macos.
|
#[cfg_attr(
|
||||||
#[cfg_attr(target_os = "macos", ignore)]
|
target_os = "macos",
|
||||||
|
ignore = "don't have a cdylib cross target on macos"
|
||||||
|
)]
|
||||||
fn rename_with_link_search_path_cross() {
|
fn rename_with_link_search_path_cross() {
|
||||||
if cross_compile::disabled() {
|
if cross_compile::disabled() {
|
||||||
return;
|
return;
|
||||||
|
@ -91,9 +91,11 @@ This may become a hard error in the future; see <https://github.com/rust-lang/ca
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cargo_test]
|
#[cargo_test]
|
||||||
// --out-dir and examples are currently broken on MSVC and apple.
|
|
||||||
// See https://github.com/rust-lang/cargo/issues/7493
|
// See https://github.com/rust-lang/cargo/issues/7493
|
||||||
#[cfg_attr(any(target_env = "msvc", target_vendor = "apple"), ignore)]
|
#[cfg_attr(
|
||||||
|
any(target_env = "msvc", target_vendor = "apple"),
|
||||||
|
ignore = "--out-dir and examples are currently broken on MSVC and apple"
|
||||||
|
)]
|
||||||
fn collision_export() {
|
fn collision_export() {
|
||||||
// `--out-dir` combines some things which can cause conflicts.
|
// `--out-dir` combines some things which can cause conflicts.
|
||||||
let p = project()
|
let p = project()
|
||||||
|
@ -1206,8 +1206,10 @@ fn platform_specific_variables_reflected_in_build_scripts() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cargo_test]
|
#[cargo_test]
|
||||||
// Don't have a dylib cross target on macos.
|
#[cfg_attr(
|
||||||
#[cfg_attr(target_os = "macos", ignore)]
|
target_os = "macos",
|
||||||
|
ignore = "don't have a dylib cross target on macos"
|
||||||
|
)]
|
||||||
fn cross_test_dylib() {
|
fn cross_test_dylib() {
|
||||||
if cross_compile::disabled() {
|
if cross_compile::disabled() {
|
||||||
return;
|
return;
|
||||||
|
@ -2424,7 +2424,7 @@ fn scrape_examples_avoid_build_script_cycle() {
|
|||||||
// The example is calling a function from a proc-macro, but proc-macros don't
|
// The example is calling a function from a proc-macro, but proc-macros don't
|
||||||
// export functions. It is not clear what this test is trying to exercise.
|
// export functions. It is not clear what this test is trying to exercise.
|
||||||
// #[cargo_test(nightly, reason = "rustdoc scrape examples flags are unstable")]
|
// #[cargo_test(nightly, reason = "rustdoc scrape examples flags are unstable")]
|
||||||
#[ignore]
|
#[ignore = "broken, needs fixing"]
|
||||||
#[cargo_test]
|
#[cargo_test]
|
||||||
fn scrape_examples_complex_reverse_dependencies() {
|
fn scrape_examples_complex_reverse_dependencies() {
|
||||||
let p = project()
|
let p = project()
|
||||||
|
@ -110,7 +110,7 @@ fn default_toolchain_is_stable() -> bool {
|
|||||||
// The optional dependency `new-baz-dep` should not be activated.
|
// The optional dependency `new-baz-dep` should not be activated.
|
||||||
// * `bar` 1.0.2 has a dependency on `baz` that *requires* the new feature
|
// * `bar` 1.0.2 has a dependency on `baz` that *requires* the new feature
|
||||||
// syntax.
|
// syntax.
|
||||||
#[ignore]
|
#[ignore = "must be run manually, requires old cargo installations"]
|
||||||
#[cargo_test]
|
#[cargo_test]
|
||||||
fn new_features() {
|
fn new_features() {
|
||||||
let registry = registry::init();
|
let registry = registry::init();
|
||||||
@ -534,7 +534,7 @@ fn new_features() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cargo_test]
|
#[cargo_test]
|
||||||
#[ignore]
|
#[ignore = "must be run manually, requires old cargo installations"]
|
||||||
fn index_cache_rebuild() {
|
fn index_cache_rebuild() {
|
||||||
// Checks that the index cache gets rebuilt.
|
// Checks that the index cache gets rebuilt.
|
||||||
//
|
//
|
||||||
@ -618,7 +618,7 @@ foo v0.1.0 [..]
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cargo_test]
|
#[cargo_test]
|
||||||
#[ignore]
|
#[ignore = "must be run manually, requires old cargo installations"]
|
||||||
fn avoids_split_debuginfo_collision() {
|
fn avoids_split_debuginfo_collision() {
|
||||||
// Test needs two different toolchains.
|
// Test needs two different toolchains.
|
||||||
// If the default toolchain is stable, then it won't work.
|
// If the default toolchain is stable, then it won't work.
|
||||||
|
@ -94,7 +94,10 @@ Caused by:
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cargo_test]
|
#[cargo_test]
|
||||||
#[ignore] // dir-name is currently disabled
|
// We are currently uncertain if dir-name will ever be exposed to the user.
|
||||||
|
// The code for it still roughly exists, but only for the internal profiles.
|
||||||
|
// This test was kept in case we ever want to enable support for it again.
|
||||||
|
#[ignore = "dir-name is disabled"]
|
||||||
fn invalid_dir_name() {
|
fn invalid_dir_name() {
|
||||||
let p = project()
|
let p = project()
|
||||||
.file(
|
.file(
|
||||||
|
@ -55,8 +55,7 @@ fn simple() {
|
|||||||
assert!(myfun.contains(r#"href="https://docs.rs/bar/1.0.0/bar/struct.Straw.html""#));
|
assert!(myfun.contains(r#"href="https://docs.rs/bar/1.0.0/bar/struct.Straw.html""#));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Broken, temporarily disable until https://github.com/rust-lang/rust/pull/82776 is resolved.
|
#[ignore = "Broken, temporarily disabled until https://github.com/rust-lang/rust/pull/82776 is resolved."]
|
||||||
#[ignore]
|
|
||||||
#[cargo_test]
|
#[cargo_test]
|
||||||
// #[cargo_test(nightly, reason = "--extern-html-root-url is unstable")]
|
// #[cargo_test(nightly, reason = "--extern-html-root-url is unstable")]
|
||||||
fn std_docs() {
|
fn std_docs() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user