summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Peter <mail@david-peter.de>2021-08-08 14:13:32 +0200
committerDavid Peter <sharkdp@users.noreply.github.com>2021-08-08 15:02:01 +0200
commitaeff525c300481dc3eaa57cbbe1340cf798641d0 (patch)
tree8c49b2fe6010fa4a3064bb540e3675dd6585dd03
parent2d398dc4a7849d6074b166482548195c187b46f7 (diff)
Attempt to fix #365
-rw-r--r--src/main.rs3
-rw-r--r--tests/tests.rs30
2 files changed, 21 insertions, 12 deletions
diff --git a/src/main.rs b/src/main.rs
index 5221d95..8654688 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -21,6 +21,7 @@ use atty::Stream;
use globset::GlobBuilder;
use lscolors::LsColors;
use regex::bytes::{RegexBuilder, RegexSetBuilder};
+use normpath::PathExt;
use crate::error::print_error;
use crate::exec::CommandTemplate;
@@ -120,7 +121,7 @@ fn run() -> Result<ExitCode> {
.iter()
.map(|path_buffer| {
path_buffer
- .canonicalize()
+ .normalize()
.and_then(|pb| filesystem::absolute_path(pb.as_path()))
.unwrap()
})
diff --git a/tests/tests.rs b/tests/tests.rs
index 783420a..7fe2c70 100644
--- a/tests/tests.rs
+++ b/tests/tests.rs
@@ -5,6 +5,7 @@ use std::io::Write;
use std::path::Path;
use std::time::{Duration, SystemTime};
+use normpath::PathExt;
use regex::escape;
use crate::testenv::TestEnv;
@@ -26,8 +27,9 @@ static DEFAULT_FILES: &[&str] = &[
fn get_absolute_root_path(env: &TestEnv) -> String {
let path = env
.test_root()
- .canonicalize()
+ .normalize()
.expect("absolute path")
+ .as_path()
.to_str()
.expect("string")
.to_string();
@@ -1090,16 +1092,19 @@ fn test_symlink_as_root() {
fn test_symlink_and_absolute_path() {
let (te, abs_path) = get_test_env_with_abs_path(DEFAULT_DIRS, DEFAULT_FILES);
+ let expected_path = if cfg!(windows) { "symlink" } else { "one/two" };
+
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
+ "{abs_path}/{expected_path}/c.foo
+ {abs_path}/{expected_path}/C.Foo2
+ {abs_path}/{expected_path}/three
+ {abs_path}/{expected_path}/three/d.foo
+ {abs_path}/{expected_path}/three/directory_foo",
+ abs_path = &abs_path,
+ expected_path = expected_path
),
);
}
@@ -1127,6 +1132,8 @@ fn test_symlink_and_full_path() {
let root = te.system_root();
let prefix = escape(&root.to_string_lossy());
+ let expected_path = if cfg!(windows) { "symlink" } else { "one/two" };
+
te.assert_output_subdirectory(
"symlink",
&[
@@ -1135,10 +1142,11 @@ fn test_symlink_and_full_path() {
&format!("^{prefix}.*three", prefix = prefix),
],
&format!(
- "{abs_path}/one/two/three
- {abs_path}/one/two/three/d.foo
- {abs_path}/one/two/three/directory_foo",
- abs_path = &abs_path
+ "{abs_path}/{expected_path}/three
+ {abs_path}/{expected_path}/three/d.foo
+ {abs_path}/{expected_path}/three/directory_foo",
+ abs_path = &abs_path,
+ expected_path = expected_path
),
);
}