fd icon indicating copy to clipboard operation
fd copied to clipboard

Allow working directory to be nonexistent if search path is given

Open vijfhoek opened this issue 3 years ago • 3 comments

Fixes #1072

vijfhoek avatar Aug 01 '22 21:08 vijfhoek

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

sharkdp avatar Aug 03 '22 06:08 sharkdp

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

vijfhoek avatar Aug 03 '22 13:08 vijfhoek

I think you'll have to do something like

create_dir("./dir");
set_current_dir("./dir");
remove_dir("../dir");
run(["fd", ".", "/some/absolute/path"]);

tavianator avatar Aug 04 '22 14:08 tavianator

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

vijfhoek avatar Aug 08 '22 15:08 vijfhoek