From 8ca75427d9718c4b4af469cbc86d6cb12cc26691 Mon Sep 17 00:00:00 2001 From: fdai7451 Date: Thu, 19 Jan 2023 14:30:59 +0100 Subject: [PATCH] test: add cd not existent directory test --- src/builtins/cd.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/builtins/cd.rs b/src/builtins/cd.rs index a4ba4d9..44dcca5 100644 --- a/src/builtins/cd.rs +++ b/src/builtins/cd.rs @@ -18,9 +18,25 @@ impl Builtin for Cd { #[cfg(test)] mod tests { use super::*; + use std::path::Path; #[test] fn cd_current() { assert_eq!(Cd.execute(vec![".".to_string()]), Ok(())) } + + #[test] + fn cd_not_existent() { + // find a path which does not exists + let mut path = Path::new("test").to_path_buf(); + while path.exists() { + path.set_file_name(format!( + "{}test", + path.file_name().unwrap_or_default().to_string_lossy() + )) + } + + // No such file or directory (os error 2) + assert_ne!(Cd.execute(vec![path.to_string_lossy().to_string()]), Ok(())) + } }