1
Fork 0
mirror of https://github.com/redstrate/Physis.git synced 2025-04-19 17:36:50 +00:00

Add a test to CFG, to see if it panics on clearly invalid garbage data

This commit is contained in:
Joshua Goins 2024-04-16 21:40:30 -04:00
parent 74940c0436
commit 170c61b556
2 changed files with 17 additions and 1 deletions

BIN
resources/tests/random Normal file

Binary file not shown.

View file

@ -33,7 +33,7 @@ impl ConfigFile {
let reader = BufReader::new(cursor);
let mut current_category: Option<String> = None;
for line in reader.lines().flatten() {
if !line.is_empty() && line != "\0" {
if line.contains('<') || line.contains('>') {
@ -131,6 +131,14 @@ mod tests {
read(d).unwrap()
}
fn common_setup_invalid() -> ByteBuffer {
let mut d = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
d.push("resources/tests");
d.push("random");
read(d).unwrap()
}
#[test]
fn basic_parsing() {
let cfg = common_setup();
@ -150,4 +158,12 @@ mod tests {
assert_eq!(modified_cfg, cfg_buffer);
}
#[test]
fn test_invalid() {
let cfg = common_setup_invalid();
// Feeding it invalid data should not panic
ConfigFile::from_existing(&cfg);
}
}