Skip to content

Commit

Permalink
Check all TZ files in the database
Browse files Browse the repository at this point in the history
  • Loading branch information
x-hgg-x committed Aug 30, 2022
1 parent ec6a5cf commit 4a686cc
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion src/offset/local/tz_info/timezone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -631,8 +631,14 @@ const SECONDS_PER_28_DAYS: i64 = SECONDS_PER_DAY * 28;

#[cfg(test)]
mod tests {
use std::fs;
use std::path::Path;

use super::super::Error;
use super::{LeapSecond, LocalTimeType, TimeZone, TimeZoneName, Transition, TransitionRule};
use super::{
LeapSecond, LocalTimeType, TimeZone, TimeZoneName, Transition, TransitionRule,
ZONE_INFO_DIRECTORIES,
};
use crate::matches;

#[test]
Expand Down Expand Up @@ -902,4 +908,29 @@ mod tests {

Ok(())
}

#[test]
fn test_read_all_tz_files() -> Result<(), Error> {
fn check_dirs(dir: &Path) -> Result<(), Error> {
if dir.is_dir() {
for entry in fs::read_dir(dir).into_iter().flatten().flatten() {
let path = entry.path();
if path.is_dir() {
check_dirs(&path)?;
continue;
}
if let Ok(bytes @ [b'T', b'Z', b'i', b'f', ..]) = fs::read(&path).as_deref() {
assert!(TimeZone::from_tz_data(bytes).is_ok());
}
}
}
Ok(())
}

for dir in ZONE_INFO_DIRECTORIES {
check_dirs(Path::new(dir))?;
}

Ok(())
}
}

0 comments on commit 4a686cc

Please sign in to comment.