Allow working directory to be nonexistent if search path is given
Fixes #1072
Thank you very much for this fix. The code looks good. It would be fantastic if we could add a simple regression test for this, based on your comment here: https://github.com/sharkdp/fd/issues/1072#issuecomment-1200502534
I've looked into making a test for this, but std::process::Command throws an error when the working directory doesn't exist so I don't know how to go about that.
#[test]
fn test_invalid_cwd() {
let te = TestEnv::new(&[], &[]);
te.assert_success_and_get_output(Path::new("thisdoesnotexist"), &["foo"]);
}
thread 'test_invalid_cwd' panicked at 'fd output: Os { code: 2, kind: NotFound, message: "No such file or directory" }', tests/testenv/mod.rs:207:35
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
I think you'll have to do something like
create_dir("./dir");
set_current_dir("./dir");
remove_dir("../dir");
run(["fd", ".", "/some/absolute/path"]);
Half expecting this test to break on Windows, will see though :slightly_smiling_face:
EDIT: Called it. I'll just exclude the test on Windows, because you can't delete a working directory anyway since it'll be in use