From f0eb210ab59ac11dd137544583a1881e28ff74b9 Mon Sep 17 00:00:00 2001 From: ReggaeMuffin <644950+reggaemuffin@users.noreply.github.com> Date: Wed, 31 Mar 2021 21:35:24 +0100 Subject: [PATCH 01/13] rm: add verbose output and trim multiple slashes Uses the normalize_path used in cargo to strip duplicate slashes With a link to a std rfc https://github.com/rust-lang/rfcs/issues/2208 This fixes https://github.com/uutils/coreutils/issues/1829 This also touches https://github.com/uutils/coreutils/issues/1768 but does not attempt to fully solve it --- src/uu/rm/src/rm.rs | 47 ++++++++++++++++++++++++++++++++++++---- tests/by-util/test_rm.rs | 23 ++++++++++++++++++++ 2 files changed, 66 insertions(+), 4 deletions(-) diff --git a/src/uu/rm/src/rm.rs b/src/uu/rm/src/rm.rs index 033a1a4aa75..9b88493de00 100644 --- a/src/uu/rm/src/rm.rs +++ b/src/uu/rm/src/rm.rs @@ -16,7 +16,7 @@ use std::collections::VecDeque; use std::fs; use std::io::{stderr, stdin, BufRead, Write}; use std::ops::BitOr; -use std::path::Path; +use std::path::{Component, Path, PathBuf}; use walkdir::{DirEntry, WalkDir}; #[derive(Eq, PartialEq, Clone, Copy)] @@ -251,7 +251,7 @@ fn handle_dir(path: &Path, options: &Options) -> bool { let is_root = path.has_root() && path.parent().is_none(); if options.recursive && (!is_root || !options.preserve_root) { - if options.interactive != InteractiveMode::Always { + if options.interactive != InteractiveMode::Always && !options.verbose { // we need the extra crate because apparently fs::remove_dir_all() does not function // correctly on Windows if let Err(e) = remove_dir_all(path) { @@ -311,7 +311,7 @@ fn remove_dir(path: &Path, options: &Options) -> bool { match fs::remove_dir(path) { Ok(_) => { if options.verbose { - println!("removed directory '{}'", path.display()); + println!("removed directory '{}'", unify(path).display()); } } Err(e) => { @@ -349,7 +349,7 @@ fn remove_file(path: &Path, options: &Options) -> bool { match fs::remove_file(path) { Ok(_) => { if options.verbose { - println!("removed '{}'", path.display()); + println!("removed '{}'", unify(path).display()); } } Err(e) => { @@ -370,6 +370,45 @@ fn prompt_file(path: &Path, is_dir: bool) -> bool { } } +// copied from https://github.com/rust-lang/cargo/blob/2e4cfc2b7d43328b207879228a2ca7d427d188bb/src/cargo/util/paths.rs#L65-L90 +// both projects are MIT https://github.com/rust-lang/cargo/blob/master/LICENSE-MIT +// for std impl progress see rfc https://github.com/rust-lang/rfcs/issues/2208 +// replace this once that lands +pub fn normalize_path(path: &Path) -> PathBuf { + let mut components = path.components().peekable(); + let mut ret = if let Some(c @ Component::Prefix(..)) = components.peek().cloned() { + components.next(); + PathBuf::from(c.as_os_str()) + } else { + PathBuf::new() + }; + + for component in components { + match component { + Component::Prefix(..) => unreachable!(), + Component::RootDir => { + ret.push(component.as_os_str()); + } + Component::CurDir => {} + Component::ParentDir => { + ret.pop(); + } + Component::Normal(c) => { + ret.push(c); + } + } + } + ret +} + +fn unify(path: &Path) -> PathBuf { + // copied from https://github.com/rust-lang/cargo/blob/2e4cfc2b7d43328b207879228a2ca7d427d188bb/src/cargo/util/paths.rs#L65-L90 + // both projects are MIT https://github.com/rust-lang/cargo/blob/master/LICENSE-MIT + // for std impl progress see rfc https://github.com/rust-lang/rfcs/issues/2208 + // TODO: replace this once that lands + normalize_path(path) +} + fn prompt(msg: &str) -> bool { let _ = stderr().write_all(msg.as_bytes()); let _ = stderr().flush(); diff --git a/tests/by-util/test_rm.rs b/tests/by-util/test_rm.rs index 149d509c531..1352951ae90 100644 --- a/tests/by-util/test_rm.rs +++ b/tests/by-util/test_rm.rs @@ -263,3 +263,26 @@ fn test_rm_no_operand() { ucmd.fails() .stderr_is("rm: error: missing an argument\nrm: error: for help, try 'rm --help'\n"); } + +#[test] +fn test_rm_verbose_slash() { + let (at, mut ucmd) = at_and_ucmd!(); + let dir = "test_rm_verbose_slash_directory"; + let file_a = &format!("{}/test_rm_verbose_slash_file_a", dir); + + at.mkdir(dir); + at.touch(file_a); + + ucmd.arg("-r") + .arg("-f") + .arg("-v") + .arg(&format!("{}///", dir)) + .succeeds() + .stdout_only(format!( + "removed '{}'\nremoved directory '{}'\n", + file_a, dir + )); + + assert!(!at.dir_exists(dir)); + assert!(!at.file_exists(file_a)); +} From a635b23f7edab75eb05ce19cc8e8de7047587a13 Mon Sep 17 00:00:00 2001 From: ReggaeMuffin <644950+reggaemuffin@users.noreply.github.com> Date: Wed, 31 Mar 2021 21:53:09 +0100 Subject: [PATCH 02/13] rm: fix the test for windows using \\ This is ambiguous as we have no precedent for how windows paths should be formatted So I picked the canonical form --- tests/by-util/test_rm.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/by-util/test_rm.rs b/tests/by-util/test_rm.rs index 1352951ae90..404517dfcdd 100644 --- a/tests/by-util/test_rm.rs +++ b/tests/by-util/test_rm.rs @@ -273,6 +273,13 @@ fn test_rm_verbose_slash() { at.mkdir(dir); at.touch(file_a); + let separator = if cfg!(windows) { + "\\" + } else { + "/" + }; + let file_a_normalized = &format!("{}{}test_rm_verbose_slash_file_a", dir, separator); + ucmd.arg("-r") .arg("-f") .arg("-v") @@ -280,7 +287,7 @@ fn test_rm_verbose_slash() { .succeeds() .stdout_only(format!( "removed '{}'\nremoved directory '{}'\n", - file_a, dir + file_a_normalized, dir )); assert!(!at.dir_exists(dir)); From d90f5c355a8642adb74a8653c1f03b8316858ad0 Mon Sep 17 00:00:00 2001 From: ReggaeMuffin <644950+reggaemuffin@users.noreply.github.com> Date: Thu, 1 Apr 2021 09:13:13 +0100 Subject: [PATCH 03/13] rm: test format Seems like I got hit by https://github.com/rust-lang/rustfmt/issues/803 It did not ran formatting on the tests --- tests/by-util/test_rm.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/tests/by-util/test_rm.rs b/tests/by-util/test_rm.rs index 404517dfcdd..fc0f2f62883 100644 --- a/tests/by-util/test_rm.rs +++ b/tests/by-util/test_rm.rs @@ -273,11 +273,7 @@ fn test_rm_verbose_slash() { at.mkdir(dir); at.touch(file_a); - let separator = if cfg!(windows) { - "\\" - } else { - "/" - }; + let separator = if cfg!(windows) { "\\" } else { "/" }; let file_a_normalized = &format!("{}{}test_rm_verbose_slash_file_a", dir, separator); ucmd.arg("-r") From 63d0a6ec664602ed06b5d699d2b4345619172bcc Mon Sep 17 00:00:00 2001 From: ReggaeMuffin <644950+reggaemuffin@users.noreply.github.com> Date: Thu, 1 Apr 2021 09:15:33 +0100 Subject: [PATCH 04/13] rm: rename unify to normalize as that is the name used elsewhere --- src/uu/rm/src/rm.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/uu/rm/src/rm.rs b/src/uu/rm/src/rm.rs index 9b88493de00..8789d4225e0 100644 --- a/src/uu/rm/src/rm.rs +++ b/src/uu/rm/src/rm.rs @@ -311,7 +311,7 @@ fn remove_dir(path: &Path, options: &Options) -> bool { match fs::remove_dir(path) { Ok(_) => { if options.verbose { - println!("removed directory '{}'", unify(path).display()); + println!("removed directory '{}'", normalize(path).display()); } } Err(e) => { @@ -349,7 +349,7 @@ fn remove_file(path: &Path, options: &Options) -> bool { match fs::remove_file(path) { Ok(_) => { if options.verbose { - println!("removed '{}'", unify(path).display()); + println!("removed '{}'", normalize(path).display()); } } Err(e) => { @@ -401,7 +401,7 @@ pub fn normalize_path(path: &Path) -> PathBuf { ret } -fn unify(path: &Path) -> PathBuf { +fn normalize(path: &Path) -> PathBuf { // copied from https://github.com/rust-lang/cargo/blob/2e4cfc2b7d43328b207879228a2ca7d427d188bb/src/cargo/util/paths.rs#L65-L90 // both projects are MIT https://github.com/rust-lang/cargo/blob/master/LICENSE-MIT // for std impl progress see rfc https://github.com/rust-lang/rfcs/issues/2208 From f1e2e7bfaeb0f9d9cbe205e0e13d9ca954eb028a Mon Sep 17 00:00:00 2001 From: ReggaeMuffin <644950+reggaemuffin@users.noreply.github.com> Date: Thu, 1 Apr 2021 12:31:46 +0100 Subject: [PATCH 05/13] rm: use separator constant --- tests/by-util/test_rm.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/by-util/test_rm.rs b/tests/by-util/test_rm.rs index fc0f2f62883..0d77d9b016d 100644 --- a/tests/by-util/test_rm.rs +++ b/tests/by-util/test_rm.rs @@ -273,8 +273,11 @@ fn test_rm_verbose_slash() { at.mkdir(dir); at.touch(file_a); - let separator = if cfg!(windows) { "\\" } else { "/" }; - let file_a_normalized = &format!("{}{}test_rm_verbose_slash_file_a", dir, separator); + let file_a_normalized = &format!( + "{}{}test_rm_verbose_slash_file_a", + dir, + std::path::MAIN_SEPARATOR + ); ucmd.arg("-r") .arg("-f") From 3e381312058197a4b0e83b149fcf0002ec6006dc Mon Sep 17 00:00:00 2001 From: ReggaeMuffin <644950+reggaemuffin@users.noreply.github.com> Date: Fri, 2 Apr 2021 13:27:13 +0100 Subject: [PATCH 06/13] rm: move `normalize_path` to uucore and add tests Since we don't run uucore tests by default I added them to our ci and readme --- .github/workflows/CICD.yml | 13 +++++- Cargo.lock | 2 +- README.md | 5 +++ src/uu/rm/Cargo.toml | 3 +- src/uu/rm/src/rm.rs | 35 +-------------- src/uucore/src/lib/features/fs.rs | 74 +++++++++++++++++++++++++++++++ 6 files changed, 96 insertions(+), 36 deletions(-) diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml index f1ddf9be112..13dec17f4a9 100644 --- a/.github/workflows/CICD.yml +++ b/.github/workflows/CICD.yml @@ -150,7 +150,7 @@ jobs: uses: actions-rs/cargo@v1 with: command: test - args: --features "feat_os_unix" + args: --features "feat_os_unix" -p uucore -p coreutils env: RUSTFLAGS: '-Awarnings' @@ -514,6 +514,17 @@ jobs: CARGO_UTILITY_LIST_OPTIONS="$(for u in ${UTILITY_LIST}; do echo "-puu_${u}"; done;)" echo set-output name=UTILITY_LIST::${UTILITY_LIST} echo ::set-output name=CARGO_UTILITY_LIST_OPTIONS::${CARGO_UTILITY_LIST_OPTIONS} + - name: Test uucore + uses: actions-rs/cargo@v1 + with: + command: test + args: ${{ steps.vars.outputs.CARGO_FEATURES_OPTION }} --no-fail-fast -p uucore + env: + CARGO_INCREMENTAL: '0' + RUSTC_WRAPPER: '' + RUSTFLAGS: '-Zprofile -Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -Coverflow-checks=off -Zpanic_abort_tests -Cpanic=abort' + RUSTDOCFLAGS: '-Cpanic=abort' + # RUSTUP_TOOLCHAIN: ${{ steps.vars.outputs.TOOLCHAIN }} - name: Test uses: actions-rs/cargo@v1 with: diff --git a/Cargo.lock b/Cargo.lock index f40d512ce45..88984362b8c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2181,7 +2181,7 @@ dependencies = [ name = "uu_relpath" version = "0.0.4" dependencies = [ - "getopts", + "clap", "uucore", "uucore_procs", ] diff --git a/README.md b/README.md index b6d26527829..b2257b3fd07 100644 --- a/README.md +++ b/README.md @@ -226,6 +226,11 @@ If you would prefer to test a select few utilities: $ cargo test --features "chmod mv tail" --no-default-features ``` +If you also want to test the core utilities: +```bash +$ cargo test -p uucore -p coreutils +``` + To debug: ```bash $ gdb --args target/debug/coreutils ls diff --git a/src/uu/rm/Cargo.toml b/src/uu/rm/Cargo.toml index b916412d8da..0ee738d16cb 100644 --- a/src/uu/rm/Cargo.toml +++ b/src/uu/rm/Cargo.toml @@ -18,9 +18,10 @@ path = "src/rm.rs" clap = "2.33" walkdir = "2.2" remove_dir_all = "0.5.1" -uucore = { version=">=0.0.7", package="uucore", path="../../uucore" } +uucore = { version=">=0.0.7", package="uucore", path="../../uucore", features=["fs"] } uucore_procs = { version=">=0.0.5", package="uucore_procs", path="../../uucore_procs" } [[bin]] name = "rm" path = "src/main.rs" + diff --git a/src/uu/rm/src/rm.rs b/src/uu/rm/src/rm.rs index 8789d4225e0..09671768b1d 100644 --- a/src/uu/rm/src/rm.rs +++ b/src/uu/rm/src/rm.rs @@ -16,7 +16,7 @@ use std::collections::VecDeque; use std::fs; use std::io::{stderr, stdin, BufRead, Write}; use std::ops::BitOr; -use std::path::{Component, Path, PathBuf}; +use std::path::{Path, PathBuf}; use walkdir::{DirEntry, WalkDir}; #[derive(Eq, PartialEq, Clone, Copy)] @@ -370,43 +370,12 @@ fn prompt_file(path: &Path, is_dir: bool) -> bool { } } -// copied from https://github.com/rust-lang/cargo/blob/2e4cfc2b7d43328b207879228a2ca7d427d188bb/src/cargo/util/paths.rs#L65-L90 -// both projects are MIT https://github.com/rust-lang/cargo/blob/master/LICENSE-MIT -// for std impl progress see rfc https://github.com/rust-lang/rfcs/issues/2208 -// replace this once that lands -pub fn normalize_path(path: &Path) -> PathBuf { - let mut components = path.components().peekable(); - let mut ret = if let Some(c @ Component::Prefix(..)) = components.peek().cloned() { - components.next(); - PathBuf::from(c.as_os_str()) - } else { - PathBuf::new() - }; - - for component in components { - match component { - Component::Prefix(..) => unreachable!(), - Component::RootDir => { - ret.push(component.as_os_str()); - } - Component::CurDir => {} - Component::ParentDir => { - ret.pop(); - } - Component::Normal(c) => { - ret.push(c); - } - } - } - ret -} - fn normalize(path: &Path) -> PathBuf { // copied from https://github.com/rust-lang/cargo/blob/2e4cfc2b7d43328b207879228a2ca7d427d188bb/src/cargo/util/paths.rs#L65-L90 // both projects are MIT https://github.com/rust-lang/cargo/blob/master/LICENSE-MIT // for std impl progress see rfc https://github.com/rust-lang/rfcs/issues/2208 // TODO: replace this once that lands - normalize_path(path) + uucore::fs::normalize_path(path) } fn prompt(msg: &str) -> bool { diff --git a/src/uucore/src/lib/features/fs.rs b/src/uucore/src/lib/features/fs.rs index adf4f6f829a..c5979b910ff 100644 --- a/src/uucore/src/lib/features/fs.rs +++ b/src/uucore/src/lib/features/fs.rs @@ -60,6 +60,37 @@ pub enum CanonicalizeMode { Missing, } +// copied from https://github.com/rust-lang/cargo/blob/2e4cfc2b7d43328b207879228a2ca7d427d188bb/src/cargo/util/paths.rs#L65-L90 +// both projects are MIT https://github.com/rust-lang/cargo/blob/master/LICENSE-MIT +// for std impl progress see rfc https://github.com/rust-lang/rfcs/issues/2208 +// replace this once that lands +pub fn normalize_path(path: &Path) -> PathBuf { + let mut components = path.components().peekable(); + let mut ret = if let Some(c @ Component::Prefix(..)) = components.peek().cloned() { + components.next(); + PathBuf::from(c.as_os_str()) + } else { + PathBuf::new() + }; + + for component in components { + match component { + Component::Prefix(..) => unreachable!(), + Component::RootDir => { + ret.push(component.as_os_str()); + } + Component::CurDir => {} + Component::ParentDir => { + ret.pop(); + } + Component::Normal(c) => { + ret.push(c); + } + } + } + ret +} + fn resolve>(original: P) -> IOResult { const MAX_LINKS_FOLLOWED: u32 = 255; let mut followed = 0; @@ -266,3 +297,46 @@ pub fn display_permissions_unix(mode: u32) -> String { result } + +#[cfg(test)] +mod tests { + // Note this useful idiom: importing names from outer (for mod tests) scope. + use super::*; + + struct NormalizePathTestCase<'a> { + path: &'a str, + test: &'a str, + } + + const NORMALIZE_PATH_TESTS: [NormalizePathTestCase; 5] = [ + NormalizePathTestCase { + path: "./foo/bar.txt", + test: "foo/bar.txt", + }, + NormalizePathTestCase { + path: "bar/../foo/bar.txt", + test: "foo/bar.txt", + }, + NormalizePathTestCase { + path: "foo///bar.txt", + test: "foo/bar.txt", + }, + NormalizePathTestCase { + path: "foo///bar", + test: "foo/bar", + }, + NormalizePathTestCase { + path: "foo//./bar", + test: "foo/bar", + }, + ]; + + #[test] + fn test_normalize_path() { + for test in NORMALIZE_PATH_TESTS.iter() { + let path = Path::new(test.path); + let normalized = normalize_path(path); + assert_eq!(test.test, normalized.to_str().expect("Path is not valid utf-8!")); + } + } +} From 84cc40b9e61fff55971544b55ec497508b55cda1 Mon Sep 17 00:00:00 2001 From: ReggaeMuffin <644950+reggaemuffin@users.noreply.github.com> Date: Fri, 2 Apr 2021 13:30:13 +0100 Subject: [PATCH 07/13] rm: run format --- src/uucore/src/lib/features/fs.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/uucore/src/lib/features/fs.rs b/src/uucore/src/lib/features/fs.rs index c5979b910ff..20dae887192 100644 --- a/src/uucore/src/lib/features/fs.rs +++ b/src/uucore/src/lib/features/fs.rs @@ -336,7 +336,10 @@ mod tests { for test in NORMALIZE_PATH_TESTS.iter() { let path = Path::new(test.path); let normalized = normalize_path(path); - assert_eq!(test.test, normalized.to_str().expect("Path is not valid utf-8!")); + assert_eq!( + test.test, + normalized.to_str().expect("Path is not valid utf-8!") + ); } } } From be74e81532949712ab24aab4c4ba48702b9de2cc Mon Sep 17 00:00:00 2001 From: ReggaeMuffin <644950+reggaemuffin@users.noreply.github.com> Date: Fri, 2 Apr 2021 13:35:23 +0100 Subject: [PATCH 08/13] rm: support windows --- src/uucore/src/lib/features/fs.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/uucore/src/lib/features/fs.rs b/src/uucore/src/lib/features/fs.rs index 20dae887192..df0caa176e5 100644 --- a/src/uucore/src/lib/features/fs.rs +++ b/src/uucore/src/lib/features/fs.rs @@ -337,7 +337,7 @@ mod tests { let path = Path::new(test.path); let normalized = normalize_path(path); assert_eq!( - test.test, + test.test.replace("/", std::path::MAIN_SEPARATOR.as_str), normalized.to_str().expect("Path is not valid utf-8!") ); } From 973229c721fe0124fe081a63c09b73fd108d6891 Mon Sep 17 00:00:00 2001 From: ReggaeMuffin <644950+reggaemuffin@users.noreply.github.com> Date: Fri, 2 Apr 2021 13:56:50 +0100 Subject: [PATCH 09/13] rm: more char magic --- src/uucore/src/lib/features/fs.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/uucore/src/lib/features/fs.rs b/src/uucore/src/lib/features/fs.rs index df0caa176e5..b23c71b9cd2 100644 --- a/src/uucore/src/lib/features/fs.rs +++ b/src/uucore/src/lib/features/fs.rs @@ -337,7 +337,7 @@ mod tests { let path = Path::new(test.path); let normalized = normalize_path(path); assert_eq!( - test.test.replace("/", std::path::MAIN_SEPARATOR.as_str), + test.test.replace("/", std::path::MAIN_SEPARATOR.to_string().as_str()), normalized.to_str().expect("Path is not valid utf-8!") ); } From 8b7b09b21a2d031b5487a2027e49ba49cf166aa6 Mon Sep 17 00:00:00 2001 From: ReggaeMuffin <644950+reggaemuffin@users.noreply.github.com> Date: Fri, 2 Apr 2021 14:18:09 +0100 Subject: [PATCH 10/13] rm: add some extra test cases to bump coverage --- src/uucore/src/lib/features/fs.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/uucore/src/lib/features/fs.rs b/src/uucore/src/lib/features/fs.rs index b23c71b9cd2..1daf87816e9 100644 --- a/src/uucore/src/lib/features/fs.rs +++ b/src/uucore/src/lib/features/fs.rs @@ -308,7 +308,7 @@ mod tests { test: &'a str, } - const NORMALIZE_PATH_TESTS: [NormalizePathTestCase; 5] = [ + const NORMALIZE_PATH_TESTS: [NormalizePathTestCase; 7] = [ NormalizePathTestCase { path: "./foo/bar.txt", test: "foo/bar.txt", @@ -329,6 +329,14 @@ mod tests { path: "foo//./bar", test: "foo/bar", }, + NormalizePathTestCase { + path: "/foo//./bar", + test: "/foo/bar", + }, + NormalizePathTestCase { + path: "C://foo//./bar", + test: "C:/foo/bar", + }, ]; #[test] From 433cef642e743b89b849389ac53602783210943f Mon Sep 17 00:00:00 2001 From: ReggaeMuffin <644950+reggaemuffin@users.noreply.github.com> Date: Fri, 2 Apr 2021 15:14:06 +0100 Subject: [PATCH 11/13] rm: cover windows network shares --- src/uucore/src/lib/features/fs.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/uucore/src/lib/features/fs.rs b/src/uucore/src/lib/features/fs.rs index 1daf87816e9..0be20e755ee 100644 --- a/src/uucore/src/lib/features/fs.rs +++ b/src/uucore/src/lib/features/fs.rs @@ -308,7 +308,7 @@ mod tests { test: &'a str, } - const NORMALIZE_PATH_TESTS: [NormalizePathTestCase; 7] = [ + const NORMALIZE_PATH_TESTS: [NormalizePathTestCase; 8] = [ NormalizePathTestCase { path: "./foo/bar.txt", test: "foo/bar.txt", @@ -334,8 +334,12 @@ mod tests { test: "/foo/bar", }, NormalizePathTestCase { - path: "C://foo//./bar", - test: "C:/foo/bar", + path: r"C:/you/later/", + test: "C:/you/later", + }, + NormalizePathTestCase { + path: "\\networkshare/a//foo//./bar", + test: "\\networkshare/a/foo/bar", }, ]; From a9de357bcf354840947d25f478189af25df123e4 Mon Sep 17 00:00:00 2001 From: ReggaeMuffin <644950+reggaemuffin@users.noreply.github.com> Date: Fri, 2 Apr 2021 16:11:02 +0100 Subject: [PATCH 12/13] rm: run fmt --- src/uucore/src/lib/features/fs.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/uucore/src/lib/features/fs.rs b/src/uucore/src/lib/features/fs.rs index 0be20e755ee..a72d6ea82fc 100644 --- a/src/uucore/src/lib/features/fs.rs +++ b/src/uucore/src/lib/features/fs.rs @@ -349,7 +349,8 @@ mod tests { let path = Path::new(test.path); let normalized = normalize_path(path); assert_eq!( - test.test.replace("/", std::path::MAIN_SEPARATOR.to_string().as_str()), + test.test + .replace("/", std::path::MAIN_SEPARATOR.to_string().as_str()), normalized.to_str().expect("Path is not valid utf-8!") ); } From 77f3b088ec38c49520b5d3cb4410b4af4df28292 Mon Sep 17 00:00:00 2001 From: ReggaeMuffin <644950+reggaemuffin@users.noreply.github.com> Date: Mon, 5 Apr 2021 16:17:57 +0100 Subject: [PATCH 13/13] rm: remove trailing whitespace --- src/uu/rm/Cargo.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/src/uu/rm/Cargo.toml b/src/uu/rm/Cargo.toml index 049e26b19cd..9974111aabd 100644 --- a/src/uu/rm/Cargo.toml +++ b/src/uu/rm/Cargo.toml @@ -25,4 +25,3 @@ uucore_procs = { version=">=0.0.5", package="uucore_procs", path="../../uucore_p [[bin]] name = "rm" path = "src/main.rs" -