Skip to content
Myr

Normalize absolute paths, fixes #268 (#270)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* Normalize absolute paths, fixes #268 * Split unit tests into several tests

authored by David Peter · committed by GitHub · parent f9a3258 · Browse files · 2 files+57 added−14 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+57 added−14 removed

  • tests:+51 added−13 removed
  • other:+6 added−1 removed

2 files+57 added−14 removed

modified:src/main.rs+6 added-1 removed
71 unmodified lines
7273 if matches.is_present("absolute-path") {74 dir_vec = dir_vec75 .iter()76 .map(|path_buffer| fshelper::absolute_path(path_buffer).unwrap())76 .map(|path_buffer| {77 path_buffer78 .canonicalize()79 .and_then(|pb| fshelper::absolute_path(pb.as_path()))80 .unwrap()81 })82 .collect();83 }8485 // Detect if the user accidentally supplied a path instead of a search pattern
125 unmodified lines
modified:tests/tests.rs+51 added-13 removed
530 unmodified lines
531 ),532 );533}534535/// Absolute paths should be normalized536#[test]537fn test_normalized_absolute_path() {538 let (te, abs_path) = get_test_env_with_abs_path(DEFAULT_DIRS, DEFAULT_FILES);539540 te.assert_output_subdirectory(541 "one",542 &["--absolute-path", "foo", ".."],543 &format!(544 "{abs_path}/a.foo545 {abs_path}/one/b.foo546 {abs_path}/one/two/c.foo547 {abs_path}/one/two/C.Foo2548 {abs_path}/one/two/three/d.foo549 {abs_path}/one/two/three/directory_foo",550 abs_path = &abs_path551 ),552 );553}554555/// File type filter (--type)556#[test]557fn test_type() {558 let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);
113 unmodified lines
672673 te4.assert_output(&["--hidden", "--extension", ".hidden"], "test.hidden");674}675656/// Symlinks misc676/// Symlink as search directory677#[test]658fn test_symlink() {659 let (te, abs_path) = get_test_env_with_abs_path(DEFAULT_DIRS, DEFAULT_FILES);678fn test_symlink_as_root() {679 let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);680681 // From: http://pubs.opengroup.org/onlinepubs/9699919799/functions/getcwd.html682 // The getcwd() function shall place an absolute pathname of the current working directory in683 // the array pointed to by buf, and return buf. The pathname shall contain no components that
25 unmodified lines
709 {dir}/symlink",710 dir = &parent_parent711 ),712 );713}714715#[test]716fn test_symlink_and_absolute_path() {717 let (te, abs_path) = get_test_env_with_abs_path(DEFAULT_DIRS, DEFAULT_FILES);718719 te.assert_output_subdirectory(720 "symlink",721 &["--absolute-path"],722 &format!(698 "{abs_path}/{dir}/c.foo699 {abs_path}/{dir}/C.Foo2700 {abs_path}/{dir}/three701 {abs_path}/{dir}/three/d.foo702 {abs_path}/{dir}/three/directory_foo",703 dir = if cfg!(windows) { "symlink" } else { "one/two" },723 "{abs_path}/one/two/c.foo724 {abs_path}/one/two/C.Foo2725 {abs_path}/one/two/three726 {abs_path}/one/two/three/d.foo727 {abs_path}/one/two/three/directory_foo",728 abs_path = &abs_path729 ),730 );731}732733#[test]734fn test_symlink_as_absolute_root() {735 let (te, abs_path) = get_test_env_with_abs_path(DEFAULT_DIRS, DEFAULT_FILES);736737 te.assert_output(738 &["", &format!("{abs_path}/symlink", abs_path = abs_path)],739 &format!(740 "{abs_path}/symlink/c.foo
3 unmodified lines
744 {abs_path}/symlink/three/directory_foo",745 abs_path = &abs_path746 ),747 );748}749750#[test]751fn test_symlink_and_full_path() {752 let (te, abs_path) = get_test_env_with_abs_path(DEFAULT_DIRS, DEFAULT_FILES);753 let root = te.system_root();754 let prefix = escape(&root.to_string_lossy());755756 te.assert_output_subdirectory(
3 unmodified lines
760 "--full-path",761 &format!("^{prefix}.*three", prefix = prefix),762 ],763 &format!(731 "{abs_path}/{dir}/three732 {abs_path}/{dir}/three/d.foo733 {abs_path}/{dir}/three/directory_foo",734 dir = if cfg!(windows) { "symlink" } else { "one/two" },764 "{abs_path}/one/two/three765 {abs_path}/one/two/three/d.foo766 {abs_path}/one/two/three/directory_foo",767 abs_path = &abs_path768 ),769 );770}771772#[test]773fn test_symlink_and_full_path_abs_path() {774 let (te, abs_path) = get_test_env_with_abs_path(DEFAULT_DIRS, DEFAULT_FILES);775 let root = te.system_root();776 let prefix = escape(&root.to_string_lossy());777 te.assert_output(778 &[779 "--full-path",780 &format!("^{prefix}.*symlink.*three", prefix = prefix),
204 unmodified lines