Skip to content

Commit

Permalink
Treat an empty features string as a no-op like Cargo does (#566)
Browse files Browse the repository at this point in the history
* Treat an empty features string as a no-op like Cargo does

* Remove empty features everywhere

* Update tests, don't use Default

* Looks like clap doesn't like keeping things simple :(

* Don't need a patch anymore with this version
  • Loading branch information
HadrienG2 authored Oct 23, 2023
1 parent a2fc13a commit e746555
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 10 deletions.
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
30 changes: 28 additions & 2 deletions 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, Clone)]
struct CheckRelease {
#[command(flatten, next_help_heading = "Current")]
pub manifest: clap_cargo::Manifest,
Expand Down Expand Up @@ -340,8 +340,15 @@ impl From<CheckRelease> for cargo_semver_checks::Check {
let mut baseline_features = value.baseline_features;
current_features.append(&mut mutual_features.clone());
baseline_features.append(&mut mutual_features);
check.with_extra_features(current_features, baseline_features);

// Treat --features="" as a no-op like cargo does
let trim_features = |features: &mut Vec<String>| {
features.retain(|feature| !feature.is_empty());
};
trim_features(&mut current_features);
trim_features(&mut baseline_features);

check.with_extra_features(current_features, baseline_features);
check
}
}
Expand All @@ -351,3 +358,22 @@ fn verify_cli() {
use clap::CommandFactory;
Cargo::command().debug_assert()
}

#[test]
fn features_empty_string_is_no_op() {
use cargo_semver_checks::Check;

let Cargo::SemverChecks(SemverChecks {
check_release: no_features,
..
}) = Cargo::parse_from(["cargo", "semver-checks"]);

let empty_features = CheckRelease {
features: vec![String::new()],
current_features: vec![String::new(), String::new()],
baseline_features: vec![String::new()],
..no_features.clone()
};

assert_eq!(Check::from(no_features), Check::from(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

0 comments on commit e746555

Please sign in to comment.