Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Treat an empty features string as a no-op like Cargo does #566

Merged
merged 5 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ termcolor_output = "1.0.1"
cargo_metadata = "0.17.0"
clap-cargo = { version = "0.10.0", features = ["cargo_metadata"] }
ignore = "0.4.18"
clap-verbosity-flag = "2.0.0"
clap-verbosity-flag = { git = "https://github.com/HadrienG2/clap-verbosity-flag.git", branch = "implement-default" }
log = "0.4.17"
# Note that `tame-index` and `gix` must be upgraded in lock-step to retain the same `gix`
# minor version. Otherwise, one will compile `gix` two times in different minor versions.
Expand Down
12 changes: 6 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub use query::{ActualSemverUpdate, RequiredSemverUpdate, SemverQuery};

/// Test a release for semver violations.
#[non_exhaustive]
#[derive(Debug)]
#[derive(Debug, PartialEq, Eq)]
pub struct Check {
/// Which packages to analyze.
scope: Scope,
Expand All @@ -52,7 +52,7 @@ pub enum ReleaseType {
}

#[non_exhaustive]
#[derive(Debug)]
#[derive(Debug, PartialEq, Eq)]
pub struct Rustdoc {
source: RustdocSource,
}
Expand Down Expand Up @@ -102,7 +102,7 @@ impl Rustdoc {
}
}

#[derive(Debug)]
#[derive(Debug, PartialEq, Eq)]
enum RustdocSource {
/// Path to the Rustdoc json file.
/// Use this option when you have already generated the rustdoc file.
Expand All @@ -120,12 +120,12 @@ enum RustdocSource {
}

/// Which packages to analyze.
#[derive(Default, Debug)]
#[derive(Default, Debug, PartialEq, Eq)]
struct Scope {
mode: ScopeMode,
}

#[derive(Debug)]
#[derive(Debug, PartialEq, Eq)]
enum ScopeMode {
/// All packages except the excluded ones.
DenyList(PackageSelection),
Expand All @@ -140,7 +140,7 @@ impl Default for ScopeMode {
}

#[non_exhaustive]
#[derive(Default, Clone, Debug)]
#[derive(Default, Clone, Debug, PartialEq, Eq)]
pub struct PackageSelection {
selection: ScopeSelection,
excluded_packages: Vec<String>,
Expand Down
20 changes: 19 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ enum SemverChecksCommands {
CheckRelease(CheckRelease),
}

#[derive(Debug, Args)]
#[derive(Debug, Args, Default)]
obi1kenobi marked this conversation as resolved.
Show resolved Hide resolved
struct CheckRelease {
#[command(flatten, next_help_heading = "Current")]
pub manifest: clap_cargo::Manifest,
Expand Down Expand Up @@ -336,6 +336,10 @@ impl From<CheckRelease> for cargo_semver_checks::Check {
check.with_heuristically_included_features();
}
let mut mutual_features = value.features;
// Treat --features="" as a no-op like cargo does
if mutual_features == [""] {
mutual_features.clear();
}
HadrienG2 marked this conversation as resolved.
Show resolved Hide resolved
let mut current_features = value.current_features;
let mut baseline_features = value.baseline_features;
current_features.append(&mut mutual_features.clone());
Expand All @@ -351,3 +355,17 @@ fn verify_cli() {
use clap::CommandFactory;
Cargo::command().debug_assert()
}

#[test]
fn features_empty_string_is_no_op() {
use cargo_semver_checks::Check;
let without_features = CheckRelease::default();
let with_empty_features = CheckRelease {
features: vec!["".to_owned()],
..CheckRelease::default()
};
assert_eq!(
Check::from(without_features),
Check::from(with_empty_features)
);
}
4 changes: 2 additions & 2 deletions src/rustdoc_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ pub(crate) enum CrateType<'a> {

/// Configuration used to choose features to enable.
/// Separate configs are used for baseline and current versions.
#[derive(Debug, Clone, Serialize)]
#[derive(Debug, Clone, Serialize, PartialEq, Eq)]
pub(crate) struct FeatureConfig {
/// Feature set chosen as the foundation.
pub(crate) features_group: FeaturesGroup,
Expand All @@ -238,7 +238,7 @@ pub(crate) struct FeatureConfig {
pub(crate) is_baseline: bool,
}

#[derive(Debug, Clone, Serialize)]
#[derive(Debug, Clone, Serialize, PartialEq, Eq)]
pub(crate) enum FeaturesGroup {
All,
Default,
Expand Down
Loading