use assert_cmd::cargo::cargo_bin_cmd;
use predicates::prelude::*;
use tempfile::TempDir;
#[test]
fn test_hidden_files_are_checked_by_default() {
let temp_dir = TempDir::new().unwrap();
std::fs::write(
temp_dir.path().join(".github-workflow.yml"),
"line 1 \nline 2",
)
.unwrap();
std::fs::write(temp_dir.path().join("normal.txt"), "line 1\nline 2\n").unwrap();
let mut cmd = cargo_bin_cmd!("lineguard");
cmd.current_dir(&temp_dir);
cmd.arg(".");
cmd.assert()
.failure()
.stdout(predicate::str::contains(".github-workflow.yml"));
}
#[test]
fn test_no_hidden_flag_skips_hidden_files() {
let temp_dir = TempDir::new().unwrap();
std::fs::write(
temp_dir.path().join(".github-workflow.yml"),
"line 1 \nline 2",
)
.unwrap();
std::fs::write(temp_dir.path().join("normal.txt"), "line 1 \nline 2").unwrap();
let mut cmd = cargo_bin_cmd!("lineguard");
cmd.current_dir(&temp_dir);
cmd.arg("--no-hidden");
cmd.arg(".");
cmd.assert()
.failure()
.stdout(predicate::str::contains("normal.txt"))
.stdout(predicate::str::contains(".github-workflow.yml").not());
}
#[test]
fn test_hidden_directories_are_checked_by_default() {
let temp_dir = TempDir::new().unwrap();
let github_dir = temp_dir.path().join(".github");
std::fs::create_dir(&github_dir).unwrap();
std::fs::write(github_dir.join("workflow.yml"), "line 1 \nline 2").unwrap();
let mut cmd = cargo_bin_cmd!("lineguard");
cmd.current_dir(&temp_dir);
cmd.arg("--recursive");
cmd.arg(".");
cmd.assert()
.failure()
.stdout(predicate::str::contains("workflow.yml"));
}