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

add test for allow lint level #809

Merged
merged 1 commit into from
Jul 6, 2024
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
9 changes: 9 additions & 0 deletions test_crates/manifest_tests/allow/new/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "allow"
version = "0.1.0"
edition = "2021"

[dependencies]

[package.metadata.cargo-semver-checks.lints]
module_missing = "allow"
3 changes: 3 additions & 0 deletions test_crates/manifest_tests/allow/new/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// this is removed in the new version, triggering the module_missing
// lint, but this is configured to allow, so `semver-checks` should pass
// pub mod module_missing {}
6 changes: 6 additions & 0 deletions test_crates/manifest_tests/allow/old/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "allow"
version = "0.1.0"
edition = "2021"

[dependencies]
3 changes: 3 additions & 0 deletions test_crates/manifest_tests/allow/old/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// this is removed in the new version, triggering the module_missing
// lint, but this is configured to allow, so `semver-checks` should pass
pub mod module_missing {}
43 changes: 29 additions & 14 deletions tests/lint_config.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
use assert_cmd::Command;
use predicates::boolean::PredicateBooleanExt;

fn command_for_crate(crate_name: &'static str) -> Command {
let mut cmd = Command::cargo_bin("cargo-semver-checks")
.expect("cargo semver-checks command should exist");

cmd.current_dir(format!("test_crates/manifest_tests/{crate_name}"))
.args([
"semver-checks",
"--baseline-root",
"old",
"--manifest-path",
"new/",
"-v", // needed to show pass/fail of individual lints
]);
cmd
}

#[test]
fn test_workspace_config() {
let mut cmd = Command::cargo_bin("cargo-semver-checks")
Expand Down Expand Up @@ -44,20 +60,7 @@ fn test_workspace_config() {

#[test]
fn test_only_warnings() {
let mut cmd = Command::cargo_bin("cargo-semver-checks")
.expect("cargo semver-checks command should exist");

cmd.current_dir("test_crates/manifest_tests/only_warnings")
.args([
"semver-checks",
"--baseline-root",
"old",
"--manifest-path",
"new/",
"-v", // needed to show pass/fail of individual lints
]);

let assert = cmd.assert();
let assert = command_for_crate("only_warnings").assert();

let is_warn = predicates::str::is_match("WARN(.*)major(.*)function_missing")
.expect("regex should be valid");
Expand All @@ -72,3 +75,15 @@ fn test_only_warnings() {
.stderr(suggests_major)
.success();
}

#[test]
fn test_allow_skipped() {
// there is an instance of module_missing in the test crate, but
// we have set `module_missing = "allow"`, so the lint should
// not even run, and `cargo-semver-checks` should not require a
// semver upgrade.
let assert = command_for_crate("allow").assert();
assert
.stderr(predicates::str::contains("module_missing").not())
.success();
}
Loading