Browse Source

test: add cd not existent directory test

main
fdai7451 2 years ago
parent
commit
8ca75427d9
  1. 16
      src/builtins/cd.rs

16
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(()))
}
}
Loading…
Cancel
Save