From 7b6685771fe350b8c532c04d4264e7a6d65d30c3 Mon Sep 17 00:00:00 2001 From: Nicolas Stalder Date: Tue, 31 Jan 2023 00:00:44 +0100 Subject: [PATCH] Add negative test --- src/fs.rs | 1 - src/path.rs | 18 +++++++++++++++--- tests/test_serde.rs | 1 - 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/fs.rs b/src/fs.rs index 5d3372812..7d19f8b7f 100644 --- a/src/fs.rs +++ b/src/fs.rs @@ -1305,7 +1305,6 @@ impl<'a, Storage: driver::Storage> Filesystem<'a, Storage> { mod tests { use super::*; use core::convert::TryInto; - use generic_array::typenum::consts; use driver::Storage as LfsStorage; use io::Result as LfsResult; const_ram_storage!(TestStorage, 4096); diff --git a/src/path.rs b/src/path.rs index 5f2a1bdb8..c31c6216f 100644 --- a/src/path.rs +++ b/src/path.rs @@ -441,14 +441,26 @@ mod tests { const EMPTY: &Path = path!(""); const SLASH: &Path = path!("/"); + #[test] + fn path_macro() { + assert_eq!(EMPTY, &*PathBuf::from("")); + assert_eq!(SLASH, &*PathBuf::from("/")); + } + // does not compile: // const NON_ASCII: &Path = path!("über"); // const NULL: &Path = path!("ub\0er"); #[test] - fn path_macro() { - assert_eq!(EMPTY, &*PathBuf::from("")); - assert_eq!(SLASH, &*PathBuf::from("/")); + #[should_panic] + fn nul_in_from_str_with_nul() { + Path::from_str_with_nul("ub\0er"); + } + + #[test] + #[should_panic] + fn non_ascii_in_from_str_with_nul() { + Path::from_str_with_nul("über"); } #[test] diff --git a/tests/test_serde.rs b/tests/test_serde.rs index da72d228d..21b11200e 100644 --- a/tests/test_serde.rs +++ b/tests/test_serde.rs @@ -1,5 +1,4 @@ use littlefs2::{ - consts, driver, fs::Filesystem, io::Result,