Merge pull request #19005 from duncanawoods/18955---fix-running-tests-for-packages-with-multiple-targets

fix testing packages with multiple targets
This commit is contained in:
HKalbasi 2025-03-17 19:54:49 +00:00 committed by GitHub
commit 0c1b4838ce
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 186 additions and 143 deletions

View file

@ -226,6 +226,7 @@ pub enum TargetKind {
Example,
Test,
Bench,
/// Cargo calls this kind `custom-build`
BuildScript,
Other,
}
@ -254,6 +255,22 @@ impl TargetKind {
pub fn is_proc_macro(self) -> bool {
matches!(self, TargetKind::Lib { is_proc_macro: true })
}
/// If this is a valid cargo target, returns the name cargo uses in command line arguments
/// and output, otherwise None.
/// https://docs.rs/cargo_metadata/latest/cargo_metadata/enum.TargetKind.html
pub fn as_cargo_target(self) -> Option<&'static str> {
match self {
TargetKind::Bin => Some("bin"),
TargetKind::Lib { is_proc_macro: true } => Some("proc-macro"),
TargetKind::Lib { is_proc_macro: false } => Some("lib"),
TargetKind::Example => Some("example"),
TargetKind::Test => Some("test"),
TargetKind::Bench => Some("bench"),
TargetKind::BuildScript => Some("custom-build"),
TargetKind::Other => None,
}
}
}
#[derive(Default, Clone, Debug, PartialEq, Eq)]