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

Run cargo build and test built binary to ensure it works #246

Merged
merged 3 commits into from
Dec 27, 2022
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
Prev Previous commit
Moved verify_binary_contains_lints to tests/
  • Loading branch information
tonowak committed Dec 24, 2022
commit 3af601590038160fcf219875ef4a453d35de8bb7
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,6 @@ bugreport = "0.5.0"
itertools = "0.10.5"
cargo_toml = "0.13.0"
toml = "0.5.9"

[dev-dependencies]
assert_cmd = "2.0"
tonowak marked this conversation as resolved.
Show resolved Hide resolved
43 changes: 4 additions & 39 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,43 +282,8 @@ struct CheckRelease {
verbosity: clap_verbosity_flag::Verbosity<clap_verbosity_flag::InfoLevel>,
}

#[cfg(test)]
mod tests {
#[test]
fn verify_cli() {
use clap::CommandFactory;
crate::Cargo::command().debug_assert()
}

#[test]
fn verify_binary_contains_lints() {
use assert_cmd::Command;

let assert_on_crate_pair = |crate_pair: &str| {
let mut cmd = Command::cargo_bin("cargo-semver-checks").unwrap();
cmd.current_dir(format!("test_crates/{crate_pair}/new"))
.args([
"semver-checks",
"check-release",
"--baseline-root=../old/Cargo.toml",
])
.assert()
};

// The `template/new` and `template/old` are identical crates, so running cargo-semver-checks on
// them shouldn't report any issues.
assert_on_crate_pair("template").success();

// Those test crate pairs should trigger an error (because of a lint with the same name),
// so they should return a non-zero exit code.
// Only a few (arbitrarily) lints are being checked to speed up the testing process (the full
// list of lints is tested in `src/query.rs`).
for crate_pair in [
"enum_missing",
"function_const_removed",
"function_unsafe_added",
] {
assert_on_crate_pair(crate_pair).failure();
}
}
#[test]
fn verify_cli() {
use clap::CommandFactory;
Cargo::command().debug_assert()
obi1kenobi marked this conversation as resolved.
Show resolved Hide resolved
}
31 changes: 31 additions & 0 deletions tests/verify_binary_contains_lints.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use assert_cmd::Command;

#[test]
fn verify_binary_contains_lints() {
let assert_on_crate_pair = |crate_pair: &str| {
let mut cmd = Command::cargo_bin("cargo-semver-checks").unwrap();
cmd.current_dir(format!("test_crates/{crate_pair}/new"))
.args([
"semver-checks",
"check-release",
"--baseline-root=../old/Cargo.toml",
])
.assert()
};

// The `template/new` and `template/old` are identical crates, so running cargo-semver-checks on
// them shouldn't report any issues.
assert_on_crate_pair("template").success();

// Those test crate pairs should trigger an error (because of a lint with the same name),
// so they should return a non-zero exit code.
// Only a few (arbitrarily) lints are being checked to speed up the testing process (the full
// list of lints is tested in `src/query.rs`).
for crate_pair in [
"enum_missing",
"function_const_removed",
"function_unsafe_added",
] {
assert_on_crate_pair(crate_pair).failure();
}
}