mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-28 11:20:36 +00:00
test: requires
attribute accepts string literals for cmds
The new syntax is key-value pair like `requires = "rustfmt"`, comparing to the previous `requires_<cmd>`.
This commit is contained in:
parent
759ee7ca7a
commit
4240e722d4
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -451,7 +451,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "cargo-test-macro"
|
||||
version = "0.3.4"
|
||||
version = "0.4.0"
|
||||
|
||||
[[package]]
|
||||
name = "cargo-test-support"
|
||||
|
@ -32,7 +32,7 @@ cargo-credential-libsecret = { version = "0.4.7", path = "credential/cargo-crede
|
||||
cargo-credential-macos-keychain = { version = "0.4.7", path = "credential/cargo-credential-macos-keychain" }
|
||||
cargo-credential-wincred = { version = "0.4.7", path = "credential/cargo-credential-wincred" }
|
||||
cargo-platform = { path = "crates/cargo-platform", version = "0.2.0" }
|
||||
cargo-test-macro = { version = "0.3.0", path = "crates/cargo-test-macro" }
|
||||
cargo-test-macro = { version = "0.4.0", path = "crates/cargo-test-macro" }
|
||||
cargo-test-support = { version = "0.6.0", path = "crates/cargo-test-support" }
|
||||
cargo-util = { version = "0.2.14", path = "crates/cargo-util" }
|
||||
cargo-util-schemas = { version = "0.7.0", path = "crates/cargo-util-schemas" }
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "cargo-test-macro"
|
||||
version = "0.3.4"
|
||||
version = "0.4.0"
|
||||
edition.workspace = true
|
||||
rust-version = "1.83" # MSRV:1
|
||||
license.workspace = true
|
||||
|
@ -34,8 +34,8 @@ use std::sync::Once;
|
||||
/// This is useful for tests that use unstable options in `rustc` or `rustdoc`.
|
||||
/// These tests are run in Cargo's CI, but are disabled in rust-lang/rust's CI due to the difficulty of updating both repos simultaneously.
|
||||
/// A `reason` field is required to explain why it is nightly-only.
|
||||
/// * `requires_<cmd>` --- This indicates a command that is required to be installed to be run.
|
||||
/// For example, `requires_rustfmt` means the test will only run if the executable `rustfmt` is installed.
|
||||
/// * `requires = "<cmd>"` --- This indicates a command that is required to be installed to be run.
|
||||
/// For example, `requires = "rustfmt"` means the test will only run if the executable `rustfmt` is installed.
|
||||
/// These tests are *always* run on CI.
|
||||
/// This is mainly used to avoid requiring contributors from having every dependency installed.
|
||||
/// * `build_std_real` --- This is a "real" `-Zbuild-std` test (in the `build_std` integration test).
|
||||
@ -133,8 +133,18 @@ pub fn cargo_test(attr: TokenStream, item: TokenStream) -> TokenStream {
|
||||
"rustup or stable toolchain not installed"
|
||||
);
|
||||
}
|
||||
s if s.starts_with("requires_") => {
|
||||
s if s.starts_with("requires=") => {
|
||||
let command = &s[9..];
|
||||
let Ok(literal) = command.parse::<Literal>() else {
|
||||
panic!("expect a string literal, found: {command}");
|
||||
};
|
||||
let literal = literal.to_string();
|
||||
let Some(command) = literal
|
||||
.strip_prefix('"')
|
||||
.and_then(|lit| lit.strip_suffix('"'))
|
||||
else {
|
||||
panic!("expect a quoted string literal, found: {literal}");
|
||||
};
|
||||
set_ignore!(!has_command(command), "{command} not installed");
|
||||
}
|
||||
s if s.starts_with(">=1.") => {
|
||||
|
@ -5,7 +5,7 @@ use cargo_test_support::prelude::*;
|
||||
use cargo_test_support::str;
|
||||
use cargo_test_support::Project;
|
||||
|
||||
#[cargo_test(requires_hg)]
|
||||
#[cargo_test(requires = "hg")]
|
||||
fn case() {
|
||||
let project = Project::from_template(current_dir!().join("in"));
|
||||
let project_root = &project.root();
|
||||
|
@ -2917,7 +2917,7 @@ fn failed_submodule_checkout() {
|
||||
t.join().unwrap();
|
||||
}
|
||||
|
||||
#[cargo_test(requires_git)]
|
||||
#[cargo_test(requires = "git")]
|
||||
fn use_the_cli() {
|
||||
let project = project();
|
||||
let git_project = git::new("dep1", |project| {
|
||||
@ -3028,7 +3028,7 @@ fn templatedir_doesnt_cause_problems() {
|
||||
p.cargo("check").run();
|
||||
}
|
||||
|
||||
#[cargo_test(requires_git)]
|
||||
#[cargo_test(requires = "git")]
|
||||
fn git_with_cli_force() {
|
||||
// Supports a force-pushed repo.
|
||||
let git_project = git::new("dep1", |project| {
|
||||
@ -3095,7 +3095,7 @@ two
|
||||
.run();
|
||||
}
|
||||
|
||||
#[cargo_test(requires_git)]
|
||||
#[cargo_test(requires = "git")]
|
||||
fn git_fetch_cli_env_clean() {
|
||||
// This tests that git-fetch-with-cli works when GIT_DIR environment
|
||||
// variable is set (for whatever reason).
|
||||
@ -4069,7 +4069,7 @@ src/lib.rs
|
||||
.run();
|
||||
}
|
||||
|
||||
#[cargo_test(public_network_test, requires_git)]
|
||||
#[cargo_test(public_network_test, requires = "git")]
|
||||
fn github_fastpath_error_message() {
|
||||
let p = project()
|
||||
.file(
|
||||
|
@ -90,7 +90,7 @@ fn run_test(path_env: Option<&OsStr>) {
|
||||
);
|
||||
}
|
||||
|
||||
#[cargo_test(requires_git)]
|
||||
#[cargo_test(requires = "git")]
|
||||
fn use_git_gc() {
|
||||
run_test(None);
|
||||
}
|
||||
|
@ -114,7 +114,7 @@ fn simple_git() {
|
||||
cargo_process("build").cwd(&paths::root().join("foo")).run();
|
||||
}
|
||||
|
||||
#[cargo_test(requires_hg)]
|
||||
#[cargo_test(requires = "hg")]
|
||||
fn simple_hg() {
|
||||
cargo_process("new --lib foo --edition 2015 --vcs hg").run();
|
||||
|
||||
|
@ -445,17 +445,17 @@ mod object_works {
|
||||
.stdout
|
||||
}
|
||||
|
||||
#[cargo_test(requires_nm, nightly, reason = "-Zremap-path-scope is unstable")]
|
||||
#[cargo_test(requires = "nm", nightly, reason = "-Zremap-path-scope is unstable")]
|
||||
fn with_split_debuginfo_off() {
|
||||
object_works_helper("off", inspect_debuginfo);
|
||||
}
|
||||
|
||||
#[cargo_test(requires_nm, nightly, reason = "-Zremap-path-scope is unstable")]
|
||||
#[cargo_test(requires = "nm", nightly, reason = "-Zremap-path-scope is unstable")]
|
||||
fn with_split_debuginfo_packed() {
|
||||
object_works_helper("packed", inspect_debuginfo);
|
||||
}
|
||||
|
||||
#[cargo_test(requires_nm, nightly, reason = "-Zremap-path-scope is unstable")]
|
||||
#[cargo_test(requires = "nm", nightly, reason = "-Zremap-path-scope is unstable")]
|
||||
fn with_split_debuginfo_unpacked() {
|
||||
object_works_helper("unpacked", inspect_debuginfo);
|
||||
}
|
||||
@ -475,17 +475,29 @@ mod object_works {
|
||||
.stdout
|
||||
}
|
||||
|
||||
#[cargo_test(requires_readelf, nightly, reason = "-Zremap-path-scope is unstable")]
|
||||
#[cargo_test(
|
||||
requires = "readelf",
|
||||
nightly,
|
||||
reason = "-Zremap-path-scope is unstable"
|
||||
)]
|
||||
fn with_split_debuginfo_off() {
|
||||
object_works_helper("off", inspect_debuginfo);
|
||||
}
|
||||
|
||||
#[cargo_test(requires_readelf, nightly, reason = "-Zremap-path-scope is unstable")]
|
||||
#[cargo_test(
|
||||
requires = "readelf",
|
||||
nightly,
|
||||
reason = "-Zremap-path-scope is unstable"
|
||||
)]
|
||||
fn with_split_debuginfo_packed() {
|
||||
object_works_helper("packed", inspect_debuginfo);
|
||||
}
|
||||
|
||||
#[cargo_test(requires_readelf, nightly, reason = "-Zremap-path-scope is unstable")]
|
||||
#[cargo_test(
|
||||
requires = "readelf",
|
||||
nightly,
|
||||
reason = "-Zremap-path-scope is unstable"
|
||||
)]
|
||||
fn with_split_debuginfo_unpacked() {
|
||||
object_works_helper("unpacked", inspect_debuginfo);
|
||||
}
|
||||
@ -676,7 +688,7 @@ fn custom_build_env_var_trim_paths() {
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
#[cargo_test(requires_lldb, nightly, reason = "-Zremap-path-scope is unstable")]
|
||||
#[cargo_test(requires = "lldb", nightly, reason = "-Zremap-path-scope is unstable")]
|
||||
fn lldb_works_after_trimmed() {
|
||||
use cargo_test_support::compare::assert_e2e;
|
||||
use cargo_util::is_ci;
|
||||
|
Loading…
x
Reference in New Issue
Block a user