diff --git a/Cargo.lock b/Cargo.lock index db9bdea..d6bee16 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -422,13 +422,13 @@ dependencies = [ [[package]] name = "fgoxide" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de2a7105842bc5c341acb1013dca3b50bd0a9f8d8850987ee30d6b7e05185f19" +version = "0.4.1-rc.1" +source = "git+https://github.com/fulcrumgenomics/fgoxide.git?branch=jf/validate-header#8e78a5e764e5912b186d9610d055834ef5a96b41" dependencies = [ "csv", "flate2", "serde", + "serde-aux", "thiserror", ] diff --git a/Cargo.toml b/Cargo.toml index 7c6ba55..ab23ad6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,7 +36,9 @@ bstr = "1.0.1" clap = { version = "4.0.25", features = ["derive"] } enum_dispatch = "0.3.8" env_logger = "0.9.3" -fgoxide = "0.3.0" +# TODO: change this when 0.3.1 is released with header validation. +# fgoxide = "0.3.1" +fgoxide = { git = "https://github.com/fulcrumgenomics/fgoxide.git", branch = "jf/validate-header" } flate2 = { version = "1.0.25", features = ["zlib-ng"] } # Force the faster backend that requires a C compiler itertools = "0.10.5" log = "0.4.17" diff --git a/src/lib/samples.rs b/src/lib/samples.rs index 0fc6f8f..5ee00e1 100644 --- a/src/lib/samples.rs +++ b/src/lib/samples.rs @@ -151,11 +151,7 @@ mod tests { use core::panic; use super::*; - use csv::DeserializeErrorKind as CsvDeserializeErrorEnum; - use csv::ErrorKind as CsvErrorEnum; use fgoxide::{self, io::Io}; - use serde::de::value::Error as SerdeError; - use serde::de::Error; use tempfile::TempDir; // ############################################################################################ @@ -181,6 +177,29 @@ mod tests { assert!(samples_metadata.samples[1].barcode == "CATGCTA"); } + #[test] + fn test_tsv_file_delim_error() { + let lines = vec![ + // Sample::deserialize_header_line(), + "sample_id,barcode".to_owned(), + "sample1,GATTACA".to_owned(), + "sample2,CATGCTA".to_owned(), + ]; + let tempdir = TempDir::new().unwrap(); + let f1 = tempdir.path().join("sample_metadata.tsv"); + + let io = Io::default(); + io.write_lines(&f1, &lines).unwrap(); + let err = SampleGroup::from_file(&f1).unwrap_err(); + + if let fgoxide::FgError::DelimFileHeaderError { expected, found } = err { + assert_eq!(expected, Sample::deserialize_header_line()); + assert_eq!(found, "sample_id,barcode"); + } else { + panic!() + } + } + #[test] fn test_reading_from_file_with_empty_lines_at_end() { let lines = vec![ @@ -222,16 +241,14 @@ mod tests { let io = Io::default(); io.write_lines(&f1, &lines).unwrap(); - let mut to_panic = true; - if let fgoxide::FgError::ConversionError(csv_e) = SampleGroup::from_file(&f1).unwrap_err() { - if let CsvErrorEnum::Deserialize { pos: _, err: csv_de_err } = csv_e.into_kind() { - if let CsvDeserializeErrorEnum::Message(s) = csv_de_err.kind() { - to_panic = false; - assert_eq!(s, &SerdeError::missing_field("sample_id").to_string()); - } - } + if let fgoxide::FgError::DelimFileHeaderError { expected, found } = + SampleGroup::from_file(&f1).unwrap_err() + { + assert_eq!(expected, Sample::deserialize_header_line()); + assert_eq!(found, "sample1\tGATTACA"); + } else { + panic!("Different error type than expected reading from headerless file.") } - assert!(!to_panic, "Different error type than expected reading from headerless file."); } #[test]