Skip to content

Commit

Permalink
Fix crate_wide_allow
Browse files Browse the repository at this point in the history
  • Loading branch information
smoelius committed Sep 12, 2024
1 parent 8632679 commit bb89b22
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions examples/general/crate_wide_allow/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,32 @@ mod test {
use cargo_metadata::MetadataCommand;
use dylint_internal::env;
use predicates::prelude::*;
use std::{env::consts, sync::Mutex};
use std::{
env::consts,
sync::{Mutex, MutexGuard},
};

static MUTEX: Mutex<()> = Mutex::new(());
fn mutex(keep: bool) -> Option<MutexGuard<'static, ()>> {
static MUTEX: Mutex<()> = Mutex::new(());

let lock = MUTEX.lock().unwrap();

// smoelius: Ensure the `clippy` component is installed.
Command::new("rustup")
.args(["component", "add", "clippy"])
.assert()
.success();

if keep {
Some(lock)
} else {
None
}
}

#[test]
fn ui() {
let _lock = MUTEX.lock().unwrap();
let _lock = mutex(true);

dylint_testing::ui_test_example(env!("CARGO_PKG_NAME"), "ui");
}
Expand Down Expand Up @@ -115,7 +134,7 @@ mod test {
fn test(rustflags: &str, assert: impl Fn(Assert) -> Assert) {
const MANIFEST_DIR: &str = "../../..";

let _lock = MUTEX.lock().unwrap();
let _lock = mutex(true);

Command::new("cargo")
.current_dir(MANIFEST_DIR)
Expand Down Expand Up @@ -159,6 +178,8 @@ mod test {

#[test]
fn premise_manifest_sanity() {
mutex(false);

let mut command = Command::new("cargo");
command.args(["clippy"]);
command.current_dir("ui_manifest");
Expand All @@ -171,6 +192,8 @@ mod test {
/// Verify that `allow`ing a lint in the manifest does not silently override `--warn`.
#[test]
fn premise_manifest_warn() {
mutex(false);

let mut command = Command::new("cargo");
command.args(["clippy", "--", "--warn=clippy::assertions-on-constants"]);
command.current_dir("ui_manifest");
Expand All @@ -183,6 +206,8 @@ mod test {
/// Verify that `allow`ing a lint in the manifest does not silently override `--deny`.
#[test]
fn premise_manifest_deny() {
mutex(false);

let mut command = Command::new("cargo");
command.args(["clippy", "--", "--deny=clippy::assertions-on-constants"]);
command.current_dir("ui_manifest");
Expand Down

0 comments on commit bb89b22

Please sign in to comment.