use assert_cmd::cargo_bin;
use assert_cmd::Command;
use predicates::prelude::*;
use std::fs;
use tempfile::TempDir;
const VALID_HEDL: &str = "%VERSION: 1.0\n---\na: 1\n";
#[test]
fn test_batch_validate_exceeds_custom_limit() {
let temp = TempDir::new().unwrap();
fs::write(temp.path().join("test1.hedl"), VALID_HEDL).unwrap();
fs::write(temp.path().join("test2.hedl"), VALID_HEDL).unwrap();
let mut cmd = Command::new(cargo_bin!("hedl"));
cmd.arg("batch-validate")
.arg("--max-files")
.arg("1") .arg(temp.path().join("test1.hedl").to_str().unwrap())
.arg(temp.path().join("test2.hedl").to_str().unwrap());
cmd.assert()
.failure()
.stderr(predicate::str::contains("exceeds maximum limit"));
}
#[test]
fn test_batch_validate_unlimited() {
let temp = TempDir::new().unwrap();
fs::write(temp.path().join("test1.hedl"), VALID_HEDL).unwrap();
fs::write(temp.path().join("test2.hedl"), VALID_HEDL).unwrap();
let mut cmd = Command::new(cargo_bin!("hedl"));
cmd.arg("batch-validate")
.arg("--max-files")
.arg("0") .arg(temp.path().join("test1.hedl").to_str().unwrap())
.arg(temp.path().join("test2.hedl").to_str().unwrap());
cmd.assert().success();
}
#[test]
fn test_batch_validate_within_custom_limit() {
let temp = TempDir::new().unwrap();
fs::write(temp.path().join("test1.hedl"), VALID_HEDL).unwrap();
fs::write(temp.path().join("test2.hedl"), VALID_HEDL).unwrap();
let mut cmd = Command::new(cargo_bin!("hedl"));
cmd.arg("batch-validate")
.arg("--max-files")
.arg("10")
.arg(temp.path().join("test1.hedl").to_str().unwrap())
.arg(temp.path().join("test2.hedl").to_str().unwrap());
cmd.assert().success();
}
#[test]
fn test_batch_format_exceeds_custom_limit() {
let temp = TempDir::new().unwrap();
fs::write(temp.path().join("test1.hedl"), VALID_HEDL).unwrap();
fs::write(temp.path().join("test2.hedl"), VALID_HEDL).unwrap();
let mut cmd = Command::new(cargo_bin!("hedl"));
cmd.arg("batch-format")
.arg("--max-files")
.arg("1")
.arg("--check")
.arg(temp.path().join("test1.hedl").to_str().unwrap())
.arg(temp.path().join("test2.hedl").to_str().unwrap());
cmd.assert()
.failure()
.stderr(predicate::str::contains("exceeds maximum limit"));
}
#[test]
fn test_batch_format_within_limit() {
let temp = TempDir::new().unwrap();
fs::write(temp.path().join("test1.hedl"), VALID_HEDL).unwrap();
fs::write(temp.path().join("test2.hedl"), VALID_HEDL).unwrap();
let mut cmd = Command::new(cargo_bin!("hedl"));
cmd.arg("batch-format")
.arg("--max-files")
.arg("5")
.arg("--check")
.arg(temp.path().join("test1.hedl").to_str().unwrap())
.arg(temp.path().join("test2.hedl").to_str().unwrap());
cmd.assert().success();
}
#[test]
fn test_batch_lint_exceeds_custom_limit() {
let temp = TempDir::new().unwrap();
fs::write(temp.path().join("test1.hedl"), VALID_HEDL).unwrap();
fs::write(temp.path().join("test2.hedl"), VALID_HEDL).unwrap();
let mut cmd = Command::new(cargo_bin!("hedl"));
cmd.arg("batch-lint")
.arg("--max-files")
.arg("1")
.arg(temp.path().join("test1.hedl").to_str().unwrap())
.arg(temp.path().join("test2.hedl").to_str().unwrap());
cmd.assert()
.failure()
.stderr(predicate::str::contains("exceeds maximum limit"));
}
#[test]
fn test_batch_lint_within_limit() {
let temp = TempDir::new().unwrap();
fs::write(temp.path().join("test1.hedl"), VALID_HEDL).unwrap();
fs::write(temp.path().join("test2.hedl"), VALID_HEDL).unwrap();
let mut cmd = Command::new(cargo_bin!("hedl"));
cmd.arg("batch-lint")
.arg("--max-files")
.arg("5")
.arg(temp.path().join("test1.hedl").to_str().unwrap())
.arg(temp.path().join("test2.hedl").to_str().unwrap());
cmd.assert().success();
}
#[test]
fn test_batch_validate_at_limit_boundary() {
let temp = TempDir::new().unwrap();
fs::write(temp.path().join("test1.hedl"), VALID_HEDL).unwrap();
fs::write(temp.path().join("test2.hedl"), VALID_HEDL).unwrap();
fs::write(temp.path().join("test3.hedl"), VALID_HEDL).unwrap();
let mut cmd = Command::new(cargo_bin!("hedl"));
cmd.arg("batch-validate")
.arg("--max-files")
.arg("3")
.arg(temp.path().join("test1.hedl").to_str().unwrap())
.arg(temp.path().join("test2.hedl").to_str().unwrap())
.arg(temp.path().join("test3.hedl").to_str().unwrap());
cmd.assert().success();
}
#[test]
fn test_error_message_contains_helpful_suggestions() {
let temp = TempDir::new().unwrap();
fs::write(temp.path().join("test1.hedl"), VALID_HEDL).unwrap();
fs::write(temp.path().join("test2.hedl"), VALID_HEDL).unwrap();
let mut cmd = Command::new(cargo_bin!("hedl"));
cmd.arg("batch-validate")
.arg("--max-files")
.arg("1")
.arg(temp.path().join("test1.hedl").to_str().unwrap())
.arg(temp.path().join("test2.hedl").to_str().unwrap());
cmd.assert()
.failure()
.stderr(predicate::str::contains("Consider:"))
.stderr(predicate::str::contains("--max-files"))
.stderr(predicate::str::contains("HEDL_MAX_BATCH_FILES"));
}