Skip to content

Commit

Permalink
add test for allow lint level (#809)
Browse files Browse the repository at this point in the history
  • Loading branch information
suaviloquence authored Jul 6, 2024
1 parent 137790a commit a72aa13
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 14 deletions.
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();
}

0 comments on commit a72aa13

Please sign in to comment.