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

Fix option --release-type #439

Merged
merged 5 commits into from
Apr 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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: 3 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,9 @@ impl From<CheckRelease> for cargo_semver_checks::Check {
if let Some(log_level) = value.verbosity.log_level() {
check.with_log_level(log_level);
}
if let Some(release_type) = value.release_type {
check.with_release_type(release_type);
}

check
}
Expand Down
72 changes: 72 additions & 0 deletions tests/rustdoc_edge_cases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,75 @@ fn crate_in_workspace() {
.assert()
.success();
}

/// This test ensures that the `--release-type` flag works correctly,
/// overriding autodetected version changes between the rustdoc JSON files.
/// /~https://github.com/obi1kenobi/cargo-semver-checks/issues/438
#[test]
fn release_type_flag_major() {
// This run checks a crate with a major breaking change that doesn't bump the version.
// It should pass without errors because of `--release-type=major`.
let mut cmd = Command::cargo_bin("cargo-semver-checks").unwrap();
cmd.current_dir("test_crates/enum_missing/new")
.args([
"semver-checks",
"check-release",
"--baseline-root=../old",
"--release-type=major",
])
.assert()
.success();

// Running the same command with `--release-type=minor` or without that flag fails both times.
let mut cmd = Command::cargo_bin("cargo-semver-checks").unwrap();
cmd.current_dir("test_crates/enum_missing/new")
.args([
"semver-checks",
"check-release",
"--baseline-root=../old",
"--release-type=minor",
])
.assert()
.failure();
let mut cmd = Command::cargo_bin("cargo-semver-checks").unwrap();
cmd.current_dir("test_crates/enum_missing/new")
.args(["semver-checks", "check-release", "--baseline-root=../old"])
.assert()
.failure();
}

/// This test ensures that the `--release-type` flag works correctly,
/// overriding autodetected version changes between the rustdoc JSON files.
/// /~https://github.com/obi1kenobi/cargo-semver-checks/issues/438
#[test]
fn release_type_flag_minor() {
// This run checks a crate with deprecations (semver-minor) that doesn't bump the version.
// It should pass without errors because of `--release-type=minor`.
let mut cmd = Command::cargo_bin("cargo-semver-checks").unwrap();
cmd.current_dir("test_crates/type_marked_deprecated/new")
.args([
"semver-checks",
"check-release",
"--baseline-root=../old",
"--release-type=minor",
])
.assert()
.success();

// Running the same command with `--release-type=patch` or without that flag fails both times.
let mut cmd = Command::cargo_bin("cargo-semver-checks").unwrap();
cmd.current_dir("test_crates/type_marked_deprecated/new")
.args([
"semver-checks",
"check-release",
"--baseline-root=../old",
"--release-type=patch",
])
.assert()
.failure();
let mut cmd = Command::cargo_bin("cargo-semver-checks").unwrap();
cmd.current_dir("test_crates/type_marked_deprecated/new")
.args(["semver-checks", "check-release", "--baseline-root=../old"])
.assert()
.failure();
}