tests.rs (3829B)
1 use super::{Data, E, io::Read as _}; 2 use std::fs::{self, File}; 3 #[expect(clippy::panic, reason = "want to crash when there is a bug")] 4 #[expect(clippy::verbose_file_reads, reason = "want to lock file")] 5 #[test] 6 fn outputs() { 7 let mut output = Vec::with_capacity(u16::MAX.into()); 8 assert!( 9 fs::read_dir("./outputs/").is_ok_and(|mut dir| { 10 dir.try_fold((), |(), ent_res| { 11 if ent_res.is_ok_and(|ent| { 12 File::options() 13 .read(true) 14 .open(ent.path()) 15 .is_ok_and(|mut file| { 16 file.lock_shared().is_ok_and(|()| { 17 output.clear(); 18 file.read_to_end(&mut output).is_ok_and(|_| { 19 // Release lock. 20 drop(file); 21 let file_name = ent.file_name(); 22 let file_name_bytes = file_name.as_encoded_bytes(); 23 if let Err(e) = Data::new(&output, false) { 24 match file_name_bytes { 25 b"1.34.0.txt" | b"1.34.1.txt" | b"1.34.2.txt" => { 26 assert_eq!( 27 e, 28 E::LintGroupContainsUnknownLint( 29 b"future-incompatible", 30 b"duplicate-matcher-binding-name" 31 ), 32 "1.34.0.txt, 1.34.1.txt, and 1.34.2.txt can't be parsed for a reason other than the expected reason" 33 ); 34 Data::new(&output, true).is_ok() 35 } 36 b"1.48.0.txt" => { 37 assert_eq!( 38 e, 39 E::LintGroupContainsUnknownLint( 40 b"rustdoc", 41 b"private-intra-doc-links" 42 ), 43 "1.48.0.txt can't be parsed for a reason other than the expected reason" 44 ); 45 Data::new(&output, true).is_ok() 46 } 47 _ => panic!("{} cannot be parsed due to {e:?}.", String::from_utf8_lossy(file_name_bytes)), 48 } 49 } else { 50 assert!(!matches!(file_name_bytes, b"1.34.0.txt" | b"1.34.1.txt" | b"1.34.2.txt" | b"1.48.0.txt"), "{} shouldn't be parsable", String::from_utf8_lossy(file_name_bytes)); 51 true 52 } 53 }) 54 }) 55 }) 56 }) { 57 Ok(()) 58 } else { 59 Err(()) 60 } 61 }) 62 .is_ok() 63 }) 64 ); 65 }