mirror of https://github.com/sharkdp/fd.git
* Normalize absolute paths, fixes #268 * Split unit tests into several tests
This commit is contained in:
parent
f9a32583a5
commit
8c1b037279
|
@ -73,7 +73,12 @@ fn main() {
|
||||||
if matches.is_present("absolute-path") {
|
if matches.is_present("absolute-path") {
|
||||||
dir_vec = dir_vec
|
dir_vec = dir_vec
|
||||||
.iter()
|
.iter()
|
||||||
.map(|path_buffer| fshelper::absolute_path(path_buffer).unwrap())
|
.map(|path_buffer| {
|
||||||
|
path_buffer
|
||||||
|
.canonicalize()
|
||||||
|
.and_then(|pb| fshelper::absolute_path(pb.as_path()))
|
||||||
|
.unwrap()
|
||||||
|
})
|
||||||
.collect();
|
.collect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -532,6 +532,26 @@ fn test_implicit_absolute_path() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Absolute paths should be normalized
|
||||||
|
#[test]
|
||||||
|
fn test_normalized_absolute_path() {
|
||||||
|
let (te, abs_path) = get_test_env_with_abs_path(DEFAULT_DIRS, DEFAULT_FILES);
|
||||||
|
|
||||||
|
te.assert_output_subdirectory(
|
||||||
|
"one",
|
||||||
|
&["--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",
|
||||||
|
abs_path = &abs_path
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/// File type filter (--type)
|
/// File type filter (--type)
|
||||||
#[test]
|
#[test]
|
||||||
fn test_type() {
|
fn test_type() {
|
||||||
|
@ -653,10 +673,10 @@ fn test_extension() {
|
||||||
te4.assert_output(&["--hidden", "--extension", ".hidden"], "test.hidden");
|
te4.assert_output(&["--hidden", "--extension", ".hidden"], "test.hidden");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Symlinks misc
|
/// Symlink as search directory
|
||||||
#[test]
|
#[test]
|
||||||
fn test_symlink() {
|
fn test_symlink_as_root() {
|
||||||
let (te, abs_path) = get_test_env_with_abs_path(DEFAULT_DIRS, DEFAULT_FILES);
|
let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);
|
||||||
|
|
||||||
// From: http://pubs.opengroup.org/onlinepubs/9699919799/functions/getcwd.html
|
// 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 getcwd() function shall place an absolute pathname of the current working directory in
|
||||||
|
@ -690,20 +710,29 @@ fn test_symlink() {
|
||||||
dir = &parent_parent
|
dir = &parent_parent
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_symlink_and_absolute_path() {
|
||||||
|
let (te, abs_path) = get_test_env_with_abs_path(DEFAULT_DIRS, DEFAULT_FILES);
|
||||||
|
|
||||||
te.assert_output_subdirectory(
|
te.assert_output_subdirectory(
|
||||||
"symlink",
|
"symlink",
|
||||||
&["--absolute-path"],
|
&["--absolute-path"],
|
||||||
&format!(
|
&format!(
|
||||||
"{abs_path}/{dir}/c.foo
|
"{abs_path}/one/two/c.foo
|
||||||
{abs_path}/{dir}/C.Foo2
|
{abs_path}/one/two/C.Foo2
|
||||||
{abs_path}/{dir}/three
|
{abs_path}/one/two/three
|
||||||
{abs_path}/{dir}/three/d.foo
|
{abs_path}/one/two/three/d.foo
|
||||||
{abs_path}/{dir}/three/directory_foo",
|
{abs_path}/one/two/three/directory_foo",
|
||||||
dir = if cfg!(windows) { "symlink" } else { "one/two" },
|
|
||||||
abs_path = &abs_path
|
abs_path = &abs_path
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_symlink_as_absolute_root() {
|
||||||
|
let (te, abs_path) = get_test_env_with_abs_path(DEFAULT_DIRS, DEFAULT_FILES);
|
||||||
|
|
||||||
te.assert_output(
|
te.assert_output(
|
||||||
&["", &format!("{abs_path}/symlink", abs_path = abs_path)],
|
&["", &format!("{abs_path}/symlink", abs_path = abs_path)],
|
||||||
|
@ -716,7 +745,11 @@ fn test_symlink() {
|
||||||
abs_path = &abs_path
|
abs_path = &abs_path
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_symlink_and_full_path() {
|
||||||
|
let (te, abs_path) = get_test_env_with_abs_path(DEFAULT_DIRS, DEFAULT_FILES);
|
||||||
let root = te.system_root();
|
let root = te.system_root();
|
||||||
let prefix = escape(&root.to_string_lossy());
|
let prefix = escape(&root.to_string_lossy());
|
||||||
|
|
||||||
|
@ -728,14 +761,19 @@ fn test_symlink() {
|
||||||
&format!("^{prefix}.*three", prefix = prefix),
|
&format!("^{prefix}.*three", prefix = prefix),
|
||||||
],
|
],
|
||||||
&format!(
|
&format!(
|
||||||
"{abs_path}/{dir}/three
|
"{abs_path}/one/two/three
|
||||||
{abs_path}/{dir}/three/d.foo
|
{abs_path}/one/two/three/d.foo
|
||||||
{abs_path}/{dir}/three/directory_foo",
|
{abs_path}/one/two/three/directory_foo",
|
||||||
dir = if cfg!(windows) { "symlink" } else { "one/two" },
|
|
||||||
abs_path = &abs_path
|
abs_path = &abs_path
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_symlink_and_full_path_abs_path() {
|
||||||
|
let (te, abs_path) = get_test_env_with_abs_path(DEFAULT_DIRS, DEFAULT_FILES);
|
||||||
|
let root = te.system_root();
|
||||||
|
let prefix = escape(&root.to_string_lossy());
|
||||||
te.assert_output(
|
te.assert_output(
|
||||||
&[
|
&[
|
||||||
"--full-path",
|
"--full-path",
|
||||||
|
|
Loading…
Reference in New Issue