Skip to content

Commit

Permalink
tests: avoid serde_json::from_reader in tests as it's faster to just … (
Browse files Browse the repository at this point in the history
  • Loading branch information
lukexor authored May 22, 2024
1 parent dcaec14 commit 3ca03ac
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions tetanes-core/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ pub(crate) mod tests {
fmt::Write,
fs::{self, File},
hash::{Hash, Hasher},
io::BufReader,
io::{BufReader, Read},
path::{Path, PathBuf},
sync::OnceLock,
};
Expand Down Expand Up @@ -307,8 +307,11 @@ pub(crate) mod tests {
let file = PathBuf::from(directory)
.join("tests")
.with_extension("json");
let tests = File::open(&file)
.and_then(|file| Ok(serde_json::from_reader::<_, Vec<RomTest>>(file)?))
let mut content = String::with_capacity(1024);
File::open(&file)
.and_then(|mut file| file.read_to_string(&mut content))
.with_context(|| format!("failed to read rom test data: {file:?}"))?;
let tests = serde_json::from_str(&content)
.with_context(|| format!("valid rom test data: {file:?}"))?;
Ok((file, tests))
}
Expand Down

0 comments on commit 3ca03ac

Please sign in to comment.