//! Golden tests: the ESC/POS output must stay byte-identical to what master //! produced before TSPL support was added. Goldens in tests/golden/escpos/*.bin //! were generated from unmodified master (regenerate only deliberately with //! POSPRINT_REGEN_GOLDEN=1). use std::collections::HashMap; use std::fs; use std::path::Path; use posprint::io::PosFile; use posprint::pipeline::encode_pos_file; #[test] fn escpos_output_matches_master_goldens() { let dir = Path::new(env!("CARGO_MANIFEST_DIR")).join("tests/golden/escpos"); let params: HashMap = serde_json::from_str(&fs::read_to_string(dir.join("params.json")).unwrap()).unwrap(); let regen = std::env::var_os("POSPRINT_REGEN_GOLDEN").is_some(); let mut checked = 0; let mut entries: Vec<_> = fs::read_dir(&dir).unwrap().flatten().collect(); entries.sort_by_key(|e| e.path()); for entry in entries { let path = entry.path(); if path.extension().and_then(|e| e.to_str()) != Some("pos") { continue; } let file = PosFile::load_from_path(&path).unwrap(); let bytes = encode_pos_file(&file, Some(&dir), ¶ms).unwrap(); let golden = path.with_extension("bin"); if regen { fs::write(&golden, &bytes).unwrap(); } let expected = fs::read(&golden).unwrap_or_else(|_| panic!("missing {}", golden.display())); assert!(bytes == expected, "ESC/POS output changed for {}", path.display()); checked += 1; } assert!(checked >= 6, "expected golden corpus, checked {checked}"); }