2017-10-04 23:19:30 +02:00
|
|
|
//! Integration tests for the CLI interface of fd.
|
|
|
|
|
|
|
|
mod testenv;
|
|
|
|
|
|
|
|
use testenv::TestEnv;
|
|
|
|
|
2017-10-14 19:57:15 +02:00
|
|
|
fn get_absolute_root_path(env: &TestEnv) -> String {
|
|
|
|
let path = env.root()
|
|
|
|
.canonicalize()
|
|
|
|
.expect("absolute path")
|
|
|
|
.to_str()
|
|
|
|
.expect("string")
|
|
|
|
.to_string();
|
|
|
|
|
|
|
|
#[cfg(windows)]
|
|
|
|
let path = path.trim_left_matches(r"\\?\").to_string();
|
|
|
|
|
|
|
|
path
|
|
|
|
}
|
|
|
|
|
2017-10-04 23:19:30 +02:00
|
|
|
/// Simple tests
|
|
|
|
#[test]
|
|
|
|
fn test_simple() {
|
|
|
|
let te = TestEnv::new();
|
|
|
|
|
|
|
|
te.assert_output(&["a.foo"], "a.foo");
|
|
|
|
te.assert_output(&["b.foo"], "one/b.foo");
|
|
|
|
te.assert_output(&["d.foo"], "one/two/three/d.foo");
|
|
|
|
|
|
|
|
te.assert_output(
|
|
|
|
&["foo"],
|
|
|
|
"a.foo
|
|
|
|
one/b.foo
|
|
|
|
one/two/c.foo
|
|
|
|
one/two/C.Foo2
|
|
|
|
one/two/three/d.foo
|
2017-10-12 08:01:51 +02:00
|
|
|
one/two/three/directory_foo",
|
|
|
|
);
|
2017-10-04 23:19:30 +02:00
|
|
|
|
|
|
|
te.assert_output(
|
|
|
|
&[],
|
|
|
|
"a.foo
|
|
|
|
one
|
|
|
|
one/b.foo
|
|
|
|
one/two
|
|
|
|
one/two/c.foo
|
|
|
|
one/two/C.Foo2
|
|
|
|
one/two/three
|
|
|
|
one/two/three/d.foo
|
|
|
|
one/two/three/directory_foo
|
2017-10-12 08:01:51 +02:00
|
|
|
symlink",
|
|
|
|
);
|
2017-10-04 23:19:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Explicit root path
|
|
|
|
#[test]
|
|
|
|
fn test_explicit_root_path() {
|
|
|
|
let te = TestEnv::new();
|
|
|
|
|
|
|
|
te.assert_output(
|
|
|
|
&["foo", "one"],
|
|
|
|
"one/b.foo
|
|
|
|
one/two/c.foo
|
|
|
|
one/two/C.Foo2
|
|
|
|
one/two/three/d.foo
|
2017-10-12 08:01:51 +02:00
|
|
|
one/two/three/directory_foo",
|
|
|
|
);
|
2017-10-04 23:19:30 +02:00
|
|
|
|
|
|
|
te.assert_output(
|
|
|
|
&["foo", "one/two/three"],
|
|
|
|
"one/two/three/d.foo
|
2017-10-12 08:01:51 +02:00
|
|
|
one/two/three/directory_foo",
|
|
|
|
);
|
2017-10-04 23:19:30 +02:00
|
|
|
|
|
|
|
te.assert_output_subdirectory(
|
|
|
|
"one/two",
|
|
|
|
&["foo", "../../"],
|
|
|
|
"../../a.foo
|
2017-10-14 19:57:15 +02:00
|
|
|
../../one/b.foo
|
|
|
|
../../one/two/c.foo
|
|
|
|
../../one/two/C.Foo2
|
|
|
|
../../one/two/three/d.foo
|
|
|
|
../../one/two/three/directory_foo",
|
2017-10-12 08:01:51 +02:00
|
|
|
);
|
2017-10-11 23:08:41 +02:00
|
|
|
|
|
|
|
te.assert_output_subdirectory(
|
|
|
|
"one/two/three",
|
|
|
|
&["", ".."],
|
2017-10-14 19:57:15 +02:00
|
|
|
"../c.foo
|
2017-10-11 23:08:41 +02:00
|
|
|
../C.Foo2
|
2017-10-14 19:57:15 +02:00
|
|
|
../three
|
|
|
|
../three/d.foo
|
|
|
|
../three/directory_foo",
|
2017-10-11 23:08:41 +02:00
|
|
|
);
|
2017-10-04 23:19:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Regex searches
|
|
|
|
#[test]
|
|
|
|
fn test_regex_searches() {
|
|
|
|
let te = TestEnv::new();
|
|
|
|
|
|
|
|
te.assert_output(
|
|
|
|
&["[a-c].foo"],
|
|
|
|
"a.foo
|
|
|
|
one/b.foo
|
|
|
|
one/two/c.foo
|
2017-10-12 08:01:51 +02:00
|
|
|
one/two/C.Foo2",
|
|
|
|
);
|
2017-10-04 23:19:30 +02:00
|
|
|
|
|
|
|
te.assert_output(
|
|
|
|
&["--case-sensitive", "[a-c].foo"],
|
|
|
|
"a.foo
|
|
|
|
one/b.foo
|
2017-10-12 08:01:51 +02:00
|
|
|
one/two/c.foo",
|
|
|
|
);
|
2017-10-04 23:19:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Smart case
|
|
|
|
#[test]
|
|
|
|
fn test_smart_case() {
|
|
|
|
let te = TestEnv::new();
|
|
|
|
|
|
|
|
te.assert_output(
|
|
|
|
&["c.foo"],
|
|
|
|
"one/two/c.foo
|
2017-10-12 08:01:51 +02:00
|
|
|
one/two/C.Foo2",
|
|
|
|
);
|
2017-10-04 23:19:30 +02:00
|
|
|
|
2017-10-12 08:01:51 +02:00
|
|
|
te.assert_output(&["C.Foo"], "one/two/C.Foo2");
|
2017-10-04 23:19:30 +02:00
|
|
|
|
2017-10-12 08:01:51 +02:00
|
|
|
te.assert_output(&["Foo"], "one/two/C.Foo2");
|
2017-10-13 21:46:00 +02:00
|
|
|
|
|
|
|
// Only literal uppercase chars should trigger case sensitivity.
|
|
|
|
te.assert_output(
|
|
|
|
&["\\Ac"],
|
|
|
|
"one/two/c.foo
|
|
|
|
one/two/C.Foo2",
|
|
|
|
);
|
|
|
|
te.assert_output(&["\\AC"], "one/two/C.Foo2");
|
2017-10-04 23:19:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Case sensitivity (--case-sensitive)
|
|
|
|
#[test]
|
|
|
|
fn test_case_sensitive() {
|
|
|
|
let te = TestEnv::new();
|
|
|
|
|
2017-10-12 08:01:51 +02:00
|
|
|
te.assert_output(&["--case-sensitive", "c.foo"], "one/two/c.foo");
|
2017-10-04 23:19:30 +02:00
|
|
|
|
2017-10-12 08:01:51 +02:00
|
|
|
te.assert_output(&["--case-sensitive", "C.Foo"], "one/two/C.Foo2");
|
2017-10-12 01:21:44 +02:00
|
|
|
|
|
|
|
te.assert_output(
|
|
|
|
&["--ignore-case", "--case-sensitive", "C.Foo"],
|
2017-10-12 08:01:51 +02:00
|
|
|
"one/two/C.Foo2",
|
|
|
|
);
|
2017-10-12 01:21:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Case insensitivity (--ignore-case)
|
|
|
|
#[test]
|
|
|
|
fn test_case_insensitive() {
|
|
|
|
let te = TestEnv::new();
|
|
|
|
|
|
|
|
te.assert_output(
|
|
|
|
&["--ignore-case", "C.Foo"],
|
|
|
|
"one/two/c.foo
|
2017-10-12 08:01:51 +02:00
|
|
|
one/two/C.Foo2",
|
|
|
|
);
|
2017-10-12 01:21:44 +02:00
|
|
|
|
|
|
|
te.assert_output(
|
|
|
|
&["--case-sensitive", "--ignore-case", "C.Foo"],
|
|
|
|
"one/two/c.foo
|
2017-10-12 08:01:51 +02:00
|
|
|
one/two/C.Foo2",
|
|
|
|
);
|
2017-10-04 23:19:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Full path search (--full-path)
|
|
|
|
#[test]
|
|
|
|
fn test_full_path() {
|
|
|
|
let te = TestEnv::new();
|
|
|
|
|
|
|
|
te.assert_output(
|
|
|
|
&["--full-path", "three.*foo"],
|
|
|
|
"one/two/three/d.foo
|
2017-10-12 08:01:51 +02:00
|
|
|
one/two/three/directory_foo",
|
|
|
|
);
|
2017-10-04 23:19:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Hidden files (--hidden)
|
|
|
|
#[test]
|
|
|
|
fn test_hidden() {
|
|
|
|
let te = TestEnv::new();
|
|
|
|
|
|
|
|
te.assert_output(
|
|
|
|
&["--hidden", "foo"],
|
|
|
|
".hidden.foo
|
|
|
|
a.foo
|
|
|
|
one/b.foo
|
|
|
|
one/two/c.foo
|
|
|
|
one/two/C.Foo2
|
|
|
|
one/two/three/d.foo
|
2017-10-12 08:01:51 +02:00
|
|
|
one/two/three/directory_foo",
|
|
|
|
);
|
2017-10-04 23:19:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Ignored files (--no-ignore)
|
|
|
|
#[test]
|
|
|
|
fn test_no_ignore() {
|
|
|
|
let te = TestEnv::new();
|
|
|
|
|
|
|
|
te.assert_output(
|
|
|
|
&["--no-ignore", "foo"],
|
|
|
|
"a.foo
|
|
|
|
ignored.foo
|
|
|
|
one/b.foo
|
|
|
|
one/two/c.foo
|
|
|
|
one/two/C.Foo2
|
|
|
|
one/two/three/d.foo
|
2017-10-12 08:01:51 +02:00
|
|
|
one/two/three/directory_foo",
|
|
|
|
);
|
2017-10-04 23:19:30 +02:00
|
|
|
|
|
|
|
te.assert_output(
|
|
|
|
&["--hidden", "--no-ignore", "foo"],
|
|
|
|
".hidden.foo
|
|
|
|
a.foo
|
|
|
|
ignored.foo
|
|
|
|
one/b.foo
|
|
|
|
one/two/c.foo
|
|
|
|
one/two/C.Foo2
|
|
|
|
one/two/three/d.foo
|
2017-10-12 08:01:51 +02:00
|
|
|
one/two/three/directory_foo",
|
|
|
|
);
|
2017-10-11 13:07:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Ignored files with ripgrep aliases (-u / -uu)
|
|
|
|
#[test]
|
|
|
|
fn test_no_ignore_aliases() {
|
|
|
|
let te = TestEnv::new();
|
|
|
|
|
|
|
|
te.assert_output(
|
|
|
|
&["-u", "foo"],
|
|
|
|
"a.foo
|
|
|
|
ignored.foo
|
|
|
|
one/b.foo
|
|
|
|
one/two/c.foo
|
|
|
|
one/two/C.Foo2
|
|
|
|
one/two/three/d.foo
|
2017-10-12 08:01:51 +02:00
|
|
|
one/two/three/directory_foo",
|
|
|
|
);
|
2017-10-11 13:07:50 +02:00
|
|
|
|
|
|
|
te.assert_output(
|
|
|
|
&["-uu", "foo"],
|
|
|
|
".hidden.foo
|
|
|
|
a.foo
|
|
|
|
ignored.foo
|
|
|
|
one/b.foo
|
|
|
|
one/two/c.foo
|
|
|
|
one/two/C.Foo2
|
|
|
|
one/two/three/d.foo
|
2017-10-12 08:01:51 +02:00
|
|
|
one/two/three/directory_foo",
|
|
|
|
);
|
2017-10-04 23:19:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Symlinks (--follow)
|
|
|
|
#[test]
|
|
|
|
fn test_follow() {
|
|
|
|
let te = TestEnv::new();
|
|
|
|
|
|
|
|
te.assert_output(
|
|
|
|
&["--follow", "c.foo"],
|
|
|
|
"one/two/c.foo
|
|
|
|
one/two/C.Foo2
|
|
|
|
symlink/c.foo
|
2017-10-12 08:01:51 +02:00
|
|
|
symlink/C.Foo2",
|
|
|
|
);
|
2017-10-04 23:19:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Null separator (--print0)
|
|
|
|
#[test]
|
|
|
|
fn test_print0() {
|
|
|
|
let te = TestEnv::new();
|
|
|
|
|
|
|
|
te.assert_output(
|
|
|
|
&["--print0", "foo"],
|
|
|
|
"a.fooNULL
|
|
|
|
one/b.fooNULL
|
|
|
|
one/two/C.Foo2NULL
|
|
|
|
one/two/c.fooNULL
|
|
|
|
one/two/three/d.fooNULL
|
2017-10-12 08:01:51 +02:00
|
|
|
one/two/three/directory_fooNULL",
|
|
|
|
);
|
2017-10-04 23:19:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Maximum depth (--max-depth)
|
|
|
|
#[test]
|
|
|
|
fn test_max_depth() {
|
|
|
|
let te = TestEnv::new();
|
|
|
|
|
|
|
|
te.assert_output(
|
|
|
|
&["--max-depth", "3"],
|
|
|
|
"a.foo
|
|
|
|
one
|
|
|
|
one/b.foo
|
|
|
|
one/two
|
|
|
|
one/two/c.foo
|
|
|
|
one/two/C.Foo2
|
|
|
|
one/two/three
|
2017-10-12 08:01:51 +02:00
|
|
|
symlink",
|
|
|
|
);
|
2017-10-04 23:19:30 +02:00
|
|
|
|
|
|
|
te.assert_output(
|
|
|
|
&["--max-depth", "2"],
|
|
|
|
"a.foo
|
|
|
|
one
|
|
|
|
one/b.foo
|
|
|
|
one/two
|
2017-10-12 08:01:51 +02:00
|
|
|
symlink",
|
|
|
|
);
|
2017-10-04 23:19:30 +02:00
|
|
|
|
|
|
|
te.assert_output(
|
|
|
|
&["--max-depth", "1"],
|
|
|
|
"a.foo
|
|
|
|
one
|
2017-10-12 08:01:51 +02:00
|
|
|
symlink",
|
|
|
|
);
|
2017-10-04 23:19:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Absolute paths (--absolute-path)
|
|
|
|
#[test]
|
|
|
|
fn test_absolute_path() {
|
|
|
|
let te = TestEnv::new();
|
|
|
|
|
2017-10-14 19:57:15 +02:00
|
|
|
let abs_path = get_absolute_root_path(&te);
|
2017-10-07 09:40:44 +02:00
|
|
|
|
2017-10-11 23:08:41 +02:00
|
|
|
te.assert_output(
|
|
|
|
&["--absolute-path"],
|
|
|
|
&format!(
|
|
|
|
"{abs_path}/a.foo
|
|
|
|
{abs_path}/one
|
|
|
|
{abs_path}/one/b.foo
|
|
|
|
{abs_path}/one/two
|
|
|
|
{abs_path}/one/two/c.foo
|
|
|
|
{abs_path}/one/two/C.Foo2
|
|
|
|
{abs_path}/one/two/three
|
|
|
|
{abs_path}/one/two/three/d.foo
|
|
|
|
{abs_path}/one/two/three/directory_foo
|
|
|
|
{abs_path}/symlink",
|
|
|
|
abs_path = abs_path
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2017-10-04 23:19:30 +02:00
|
|
|
te.assert_output(
|
|
|
|
&["--absolute-path", "foo"],
|
|
|
|
&format!(
|
|
|
|
"{abs_path}/a.foo
|
|
|
|
{abs_path}/one/b.foo
|
|
|
|
{abs_path}/one/two/c.foo
|
|
|
|
{abs_path}/one/two/C.Foo2
|
|
|
|
{abs_path}/one/two/three/d.foo
|
|
|
|
{abs_path}/one/two/three/directory_foo",
|
2017-10-12 08:01:51 +02:00
|
|
|
abs_path = abs_path
|
|
|
|
),
|
2017-10-04 23:19:30 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
te.assert_output(
|
|
|
|
&["foo", &abs_path],
|
|
|
|
&format!(
|
|
|
|
"{abs_path}/a.foo
|
|
|
|
{abs_path}/one/b.foo
|
|
|
|
{abs_path}/one/two/c.foo
|
|
|
|
{abs_path}/one/two/C.Foo2
|
|
|
|
{abs_path}/one/two/three/d.foo
|
|
|
|
{abs_path}/one/two/three/directory_foo",
|
2017-10-12 08:01:51 +02:00
|
|
|
abs_path = abs_path
|
|
|
|
),
|
2017-10-04 23:19:30 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// File type filter (--type)
|
|
|
|
#[test]
|
|
|
|
fn test_type() {
|
|
|
|
let te = TestEnv::new();
|
|
|
|
|
|
|
|
te.assert_output(
|
|
|
|
&["--type", "f"],
|
|
|
|
"a.foo
|
|
|
|
one/b.foo
|
|
|
|
one/two/c.foo
|
|
|
|
one/two/C.Foo2
|
2017-10-12 08:01:51 +02:00
|
|
|
one/two/three/d.foo",
|
|
|
|
);
|
2017-10-04 23:19:30 +02:00
|
|
|
|
|
|
|
te.assert_output(
|
|
|
|
&["--type", "d"],
|
|
|
|
"one
|
|
|
|
one/two
|
|
|
|
one/two/three
|
2017-10-12 08:01:51 +02:00
|
|
|
one/two/three/directory_foo",
|
|
|
|
);
|
2017-10-04 23:19:30 +02:00
|
|
|
|
2017-10-12 08:01:51 +02:00
|
|
|
te.assert_output(&["--type", "l"], "symlink");
|
2017-10-04 23:19:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/// File extension (--extension)
|
|
|
|
#[test]
|
|
|
|
fn test_extension() {
|
|
|
|
let te = TestEnv::new();
|
|
|
|
|
|
|
|
te.assert_output(
|
|
|
|
&["--extension", "foo"],
|
|
|
|
"a.foo
|
|
|
|
one/b.foo
|
|
|
|
one/two/c.foo
|
2017-10-12 08:01:51 +02:00
|
|
|
one/two/three/d.foo",
|
|
|
|
);
|
2017-10-04 23:19:30 +02:00
|
|
|
|
|
|
|
te.assert_output(
|
|
|
|
&["--extension", ".foo"],
|
|
|
|
"a.foo
|
|
|
|
one/b.foo
|
|
|
|
one/two/c.foo
|
2017-10-12 08:01:51 +02:00
|
|
|
one/two/three/d.foo",
|
|
|
|
);
|
2017-10-04 23:19:30 +02:00
|
|
|
|
2017-10-12 08:01:51 +02:00
|
|
|
te.assert_output(&["--extension", "foo2"], "one/two/C.Foo2");
|
2017-10-04 23:19:30 +02:00
|
|
|
}
|
2017-10-14 19:57:15 +02:00
|
|
|
|
|
|
|
/// Symlinks misc
|
|
|
|
#[test]
|
|
|
|
fn test_symlink() {
|
|
|
|
let te = TestEnv::new();
|
|
|
|
|
|
|
|
let abs_path = get_absolute_root_path(&te);
|
|
|
|
|
|
|
|
// From: http://pubs.opengroup.org/onlinepubs/9699919799/functions/getcwd.html
|
|
|
|
// The getcwd() function shall place an absolute pathname of the current working directory in
|
|
|
|
// the array pointed to by buf, and return buf. The pathname shall contain no components that
|
|
|
|
// are dot or dot-dot, or are symbolic links.
|
|
|
|
//
|
|
|
|
// Symlinks on Unix are aliases to real paths, only has one redirection.
|
|
|
|
//
|
|
|
|
// Symlinks on Windows can refer to symlinks, and are resolved after logical step "..".
|
|
|
|
|
|
|
|
let parent_parent = if cfg!(windows) { ".." } else { "../.." };
|
|
|
|
te.assert_output_subdirectory(
|
|
|
|
"symlink",
|
|
|
|
&["", &parent_parent],
|
|
|
|
&format!(
|
|
|
|
"{dir}/a.foo
|
|
|
|
{dir}/one
|
|
|
|
{dir}/one/b.foo
|
|
|
|
{dir}/one/two
|
|
|
|
{dir}/one/two/c.foo
|
|
|
|
{dir}/one/two/C.Foo2
|
|
|
|
{dir}/one/two/three
|
|
|
|
{dir}/one/two/three/d.foo
|
|
|
|
{dir}/one/two/three/directory_foo
|
|
|
|
{dir}/symlink",
|
|
|
|
dir = &parent_parent
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
te.assert_output_subdirectory(
|
|
|
|
"symlink",
|
|
|
|
&["--absolute-path"],
|
|
|
|
&format!(
|
|
|
|
"{abs_path}/one/two/c.foo
|
|
|
|
{abs_path}/one/two/C.Foo2
|
|
|
|
{abs_path}/one/two/three
|
|
|
|
{abs_path}/one/two/three/d.foo
|
|
|
|
{abs_path}/one/two/three/directory_foo",
|
|
|
|
abs_path = abs_path
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
te.assert_output(
|
|
|
|
&["", &format!("{abs_path}/symlink", abs_path = abs_path)],
|
|
|
|
&format!(
|
|
|
|
"{abs_path}/symlink/c.foo
|
|
|
|
{abs_path}/symlink/C.Foo2
|
|
|
|
{abs_path}/symlink/three
|
|
|
|
{abs_path}/symlink/three/d.foo
|
|
|
|
{abs_path}/symlink/three/directory_foo",
|
|
|
|
abs_path = abs_path
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|