use assert_cmd::Command; use predicates::str::contains; use std::fs; #[test] fn test_custom_image_tags_errors() { let test_files: Vec<_> = fs::read_dir("testdata/md-bad/") .expect("Unable to read testdata/md-bad directory") .filter_map(|entry| entry.ok()) .filter(|entry| { let path = entry.path(); path.is_file() && path.extension().map_or(false, |ext| ext == "md") }) .map(|entry| entry.path()) .collect(); assert_eq!( test_files.len(), 11, "Unexpected number of md-bad test files" ); for file in test_files { let mut cmd = Command::cargo_bin("spezilinter").unwrap(); let file_str = file.to_str().unwrap(); cmd.arg(file_str) .assert() .stderr(predicates::str::contains("Error")) // Expect errors for bad markdown .failure(); } } #[test] fn test_custom_image_tags_successes() { let test_files: Vec<_> = fs::read_dir("testdata/md-good/") .expect("Unable to read testdata/md-good directory") .filter_map(|entry| entry.ok()) .filter(|entry| { entry .path() .extension() .map(|ext| ext == "md") .unwrap_or(false) }) .map(|entry| entry.path()) .collect(); assert_eq!( test_files.len(), 2, "Unexpected number of md-good test files" ); for file in test_files { let mut cmd = Command::cargo_bin("spezilinter").unwrap(); let file_str = file.to_str().unwrap(); cmd.arg(file_str).assert().success(); } } #[test] fn test_broken_image_exif() { let mut cmd = Command::cargo_bin("spezilinter").unwrap(); cmd.arg("testdata/broken.jpg") .assert() .failure() .stderr(contains(": 37 EXIF tags violated the allowlist")); } #[test] fn test_exif_gps_image() { let mut cmd = Command::cargo_bin("spezilinter").unwrap(); cmd.arg("testdata/exif-gps.jpg") .assert() .failure() .stderr(contains(": 60 EXIF tags violated the allowlist")); } #[test] fn test_exif_nogps_image() { let mut cmd = Command::cargo_bin("spezilinter").unwrap(); cmd.arg("testdata/exif-nogps.jpg").assert().success(); } #[test] fn test_exif_stripped_image() { let mut cmd = Command::cargo_bin("spezilinter").unwrap(); cmd.arg("testdata/exif-stripped.jpg").assert().success(); } #[test] fn test_png_image() { let mut cmd = Command::cargo_bin("spezilinter").unwrap(); cmd.arg("testdata/gradient.png").assert().success(); } #[test] fn test_tiff_image() { let mut cmd = Command::cargo_bin("spezilinter").unwrap(); cmd.arg("testdata/tif.tif") .assert() .failure() .stderr(contains(": 12 EXIF tags violated the allowlist")); }