Add test when running from non-existent directory

When fd is run from a non-existent directory, but a search path is
passed in the arguments, it should still run. This tests for that.
This commit is contained in:
Sijmen 2022-08-08 17:07:57 +02:00 committed by David Peter
parent cb6295d025
commit 922f127aca
2 changed files with 27 additions and 0 deletions

View file

@ -185,6 +185,11 @@ impl TestEnv {
self.temp_dir.path().to_path_buf()
}
/// Get the path of the fd executable.
pub fn test_exe(&self) -> &PathBuf {
&self.fd_exe
}
/// Get the root directory of the file system.
pub fn system_root(&self) -> PathBuf {
let mut components = self.temp_dir.path().components();

View file

@ -2114,3 +2114,25 @@ fn test_strip_cwd_prefix() {
symlink",
);
}
/// When fd is ran from a non-existent working directory, but an existent
/// directory is passed in the arguments, it should still run fine
#[test]
fn test_invalid_cwd() {
let te = TestEnv::new(&[], &[]);
let root = te.test_root().join("foo");
fs::create_dir(&root).unwrap();
std::env::set_current_dir(&root).unwrap();
fs::remove_dir(&root).unwrap();
let output = std::process::Command::new(&te.test_exe())
.arg("query")
.arg(te.test_root())
.output()
.unwrap();
if !output.status.success() {
panic!("{:?}", output);
}
}