nushell/crates/nu-command/tests/commands/cp.rs

616 lines
19 KiB
Rust
Raw Normal View History

use nu_test_support::fs::file_contents;
use nu_test_support::fs::{
files_exist_at, AbsoluteFile,
Stub::{EmptyFile, FileWithContent, FileWithPermission},
};
use nu_test_support::nu;
2019-12-17 18:54:39 +00:00
use nu_test_support::playground::Playground;
2019-08-29 06:31:56 +00:00
use std::path::Path;
2019-08-06 07:05:47 +00:00
`cp` progress bar implementation (#8012) # NOTE Clean duplicate of #7825 Sorry about all the mess guys... I got confuse with GitHub and and ended up mankind that mess. This the same code I just cleaned the commits. # Description Progress bar implementation for the `cp` command. Now if the flag `-p` or `--progress` is set, then the user will be able to see the progress of the file or files being copy ![progressbar_cp01](https://user-images.githubusercontent.com/38369407/213899494-0f6a4aa9-ee82-48c3-a1f1-1816f3fc1d9c.jpg) ![progressbar_cp02](https://user-images.githubusercontent.com/38369407/213899497-2f9e6e8c-fdd9-400b-bd8d-c59899ae0368.jpg) # User-Facing Changes A new flag (`--progress` `-p`) was added to the `cp` command Examples: ```nu cp -p test_file.txt test_folder_1\ cp -r -p test_folder\* test_folder_1\ cp -r -p -i test_folder\* test_folder_1\ ``` ## Notes - The progress bar uses `std::io::{Read, Write}` instead of `std::fs::copy` to get the progress. that means that when the progress bar is used the copy process might be a bit slower. - Progress bar for symbolic links TBD: Since symbolic links are usually very light I think is not worth it to duplicate the function `copy_symlink` just to add a progress bar that will be so fast to the point is not needed, but.. for consistency purposes we might need to added it, In that case I would have to pass the variable `progress` by parameter (to not duplicate code unnecessary). If I do that i would have to pass the `progress` var to every function to respect `copy_impl: impl Fn(PathBuf, PathBuf, Span)`. Please let me know if this is not clear :p --------- Co-authored-by: Reilly Wood <reilly.wood@icloud.com>
2023-02-22 19:57:38 +00:00
fn get_file_hash<T: std::fmt::Display>(file: T) -> String {
nu!("open -r {} | to text | hash md5", file).out
`cp` progress bar implementation (#8012) # NOTE Clean duplicate of #7825 Sorry about all the mess guys... I got confuse with GitHub and and ended up mankind that mess. This the same code I just cleaned the commits. # Description Progress bar implementation for the `cp` command. Now if the flag `-p` or `--progress` is set, then the user will be able to see the progress of the file or files being copy ![progressbar_cp01](https://user-images.githubusercontent.com/38369407/213899494-0f6a4aa9-ee82-48c3-a1f1-1816f3fc1d9c.jpg) ![progressbar_cp02](https://user-images.githubusercontent.com/38369407/213899497-2f9e6e8c-fdd9-400b-bd8d-c59899ae0368.jpg) # User-Facing Changes A new flag (`--progress` `-p`) was added to the `cp` command Examples: ```nu cp -p test_file.txt test_folder_1\ cp -r -p test_folder\* test_folder_1\ cp -r -p -i test_folder\* test_folder_1\ ``` ## Notes - The progress bar uses `std::io::{Read, Write}` instead of `std::fs::copy` to get the progress. that means that when the progress bar is used the copy process might be a bit slower. - Progress bar for symbolic links TBD: Since symbolic links are usually very light I think is not worth it to duplicate the function `copy_symlink` just to add a progress bar that will be so fast to the point is not needed, but.. for consistency purposes we might need to added it, In that case I would have to pass the variable `progress` by parameter (to not duplicate code unnecessary). If I do that i would have to pass the `progress` var to every function to respect `copy_impl: impl Fn(PathBuf, PathBuf, Span)`. Please let me know if this is not clear :p --------- Co-authored-by: Reilly Wood <reilly.wood@icloud.com>
2023-02-22 19:57:38 +00:00
}
2019-08-06 07:05:47 +00:00
#[test]
fn copies_a_file() {
`cp` progress bar implementation (#8012) # NOTE Clean duplicate of #7825 Sorry about all the mess guys... I got confuse with GitHub and and ended up mankind that mess. This the same code I just cleaned the commits. # Description Progress bar implementation for the `cp` command. Now if the flag `-p` or `--progress` is set, then the user will be able to see the progress of the file or files being copy ![progressbar_cp01](https://user-images.githubusercontent.com/38369407/213899494-0f6a4aa9-ee82-48c3-a1f1-1816f3fc1d9c.jpg) ![progressbar_cp02](https://user-images.githubusercontent.com/38369407/213899497-2f9e6e8c-fdd9-400b-bd8d-c59899ae0368.jpg) # User-Facing Changes A new flag (`--progress` `-p`) was added to the `cp` command Examples: ```nu cp -p test_file.txt test_folder_1\ cp -r -p test_folder\* test_folder_1\ cp -r -p -i test_folder\* test_folder_1\ ``` ## Notes - The progress bar uses `std::io::{Read, Write}` instead of `std::fs::copy` to get the progress. that means that when the progress bar is used the copy process might be a bit slower. - Progress bar for symbolic links TBD: Since symbolic links are usually very light I think is not worth it to duplicate the function `copy_symlink` just to add a progress bar that will be so fast to the point is not needed, but.. for consistency purposes we might need to added it, In that case I would have to pass the variable `progress` by parameter (to not duplicate code unnecessary). If I do that i would have to pass the `progress` var to every function to respect `copy_impl: impl Fn(PathBuf, PathBuf, Span)`. Please let me know if this is not clear :p --------- Co-authored-by: Reilly Wood <reilly.wood@icloud.com>
2023-02-22 19:57:38 +00:00
copies_a_file_impl(false);
copies_a_file_impl(true);
}
fn copies_a_file_impl(progress: bool) {
Playground::setup("cp_test_1", |dirs, _| {
`cp` progress bar implementation (#8012) # NOTE Clean duplicate of #7825 Sorry about all the mess guys... I got confuse with GitHub and and ended up mankind that mess. This the same code I just cleaned the commits. # Description Progress bar implementation for the `cp` command. Now if the flag `-p` or `--progress` is set, then the user will be able to see the progress of the file or files being copy ![progressbar_cp01](https://user-images.githubusercontent.com/38369407/213899494-0f6a4aa9-ee82-48c3-a1f1-1816f3fc1d9c.jpg) ![progressbar_cp02](https://user-images.githubusercontent.com/38369407/213899497-2f9e6e8c-fdd9-400b-bd8d-c59899ae0368.jpg) # User-Facing Changes A new flag (`--progress` `-p`) was added to the `cp` command Examples: ```nu cp -p test_file.txt test_folder_1\ cp -r -p test_folder\* test_folder_1\ cp -r -p -i test_folder\* test_folder_1\ ``` ## Notes - The progress bar uses `std::io::{Read, Write}` instead of `std::fs::copy` to get the progress. that means that when the progress bar is used the copy process might be a bit slower. - Progress bar for symbolic links TBD: Since symbolic links are usually very light I think is not worth it to duplicate the function `copy_symlink` just to add a progress bar that will be so fast to the point is not needed, but.. for consistency purposes we might need to added it, In that case I would have to pass the variable `progress` by parameter (to not duplicate code unnecessary). If I do that i would have to pass the `progress` var to every function to respect `copy_impl: impl Fn(PathBuf, PathBuf, Span)`. Please let me know if this is not clear :p --------- Co-authored-by: Reilly Wood <reilly.wood@icloud.com>
2023-02-22 19:57:38 +00:00
let test_file = dirs.formats().join("sample.ini");
let progress_flag = if progress { "-p" } else { "" };
// Get the hash of the file content to check integrity after copy.
Resolve Clippy warnings inside tests. (#8315) # Description Command: `cargo clippy --workspace --all-targets` Resolve those warnings: ``` warning: this expression creates a reference which is immediately dereferenced by the compiler --> crates/nu-parser/tests/test_parser.rs:86:59 | 86 | compare_rhs_binaryOp(test_tag, &expected_val, &observed_val); | ^^^^^^^^^^^^^ help: change this to: `observed_val` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow = note: `#[warn(clippy::needless_borrow)]` on by default warning: `assert!(false, ..)` should probably be replaced --> crates/nu-cli/src/completions/command_completions.rs:319:17 | 319 | assert!(false, "Merge delta has failed: {}", err); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: use `panic!(..)` or `unreachable!(..)` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#assertions_on_constants = note: `#[warn(clippy::assertions_on_constants)]` on by default warning: 1 warning emitted warning: `assert!(false, ..)` should probably be replaced --> crates/nu-cli/src/completions/completer.rs:600:13 | 600 | assert!(false, "Error merging delta: {:?}", err); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: use `panic!(..)` or `unreachable!(..)` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#assertions_on_constants warning: length comparison to zero --> crates/nu-cli/src/completions/completer.rs:620:24 | 620 | assert_eq!(result.len() > 0, has_result, "line: {}", line); | ^^^^^^^^^^^^^^^^ help: using `!is_empty` is clearer and more explicit: `!result.is_empty()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#len_zero = note: `#[warn(clippy::len_zero)]` on by default warning: equality checks against true are unnecessary --> crates/nu-cli/src/completions/completer.rs:632:33 | 632 | .filter(|x| *x == true) | ^^^^^^^^^^ help: try simplifying it as shown: `*x` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#bool_comparison = note: `#[warn(clippy::bool_comparison)]` on by default Checking nu v0.76.1 (/home/jaudiger/Development/git-repositories/jaudiger/nushell) warning: 4 warnings emitted warning: the borrowed expression implements the required traits --> crates/nu-command/tests/commands/cp.rs:26:40 | 26 | let first_hash = get_file_hash(&test_file.display()); | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `test_file.display()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow = note: `#[warn(clippy::needless_borrow)]` on by default warning: the borrowed expression implements the required traits --> crates/nu-command/tests/commands/cp.rs:178:13 | 178 | &jonathans_expected_copied_dir | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: change this to: `jonathans_expected_copied_dir` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow warning: the borrowed expression implements the required traits --> crates/nu-command/tests/commands/cp.rs:182:13 | 182 | &andres_expected_copied_dir | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: change this to: `andres_expected_copied_dir` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow warning: the borrowed expression implements the required traits --> crates/nu-command/tests/commands/cp.rs:186:13 | 186 | &yehudas_expected_copied_dir | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: change this to: `yehudas_expected_copied_dir` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow warning: 4 warnings emitted ``` # User-Facing Changes None. # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
2023-03-04 13:58:20 +00:00
let first_hash = get_file_hash(test_file.display());
`cp` progress bar implementation (#8012) # NOTE Clean duplicate of #7825 Sorry about all the mess guys... I got confuse with GitHub and and ended up mankind that mess. This the same code I just cleaned the commits. # Description Progress bar implementation for the `cp` command. Now if the flag `-p` or `--progress` is set, then the user will be able to see the progress of the file or files being copy ![progressbar_cp01](https://user-images.githubusercontent.com/38369407/213899494-0f6a4aa9-ee82-48c3-a1f1-1816f3fc1d9c.jpg) ![progressbar_cp02](https://user-images.githubusercontent.com/38369407/213899497-2f9e6e8c-fdd9-400b-bd8d-c59899ae0368.jpg) # User-Facing Changes A new flag (`--progress` `-p`) was added to the `cp` command Examples: ```nu cp -p test_file.txt test_folder_1\ cp -r -p test_folder\* test_folder_1\ cp -r -p -i test_folder\* test_folder_1\ ``` ## Notes - The progress bar uses `std::io::{Read, Write}` instead of `std::fs::copy` to get the progress. that means that when the progress bar is used the copy process might be a bit slower. - Progress bar for symbolic links TBD: Since symbolic links are usually very light I think is not worth it to duplicate the function `copy_symlink` just to add a progress bar that will be so fast to the point is not needed, but.. for consistency purposes we might need to added it, In that case I would have to pass the variable `progress` by parameter (to not duplicate code unnecessary). If I do that i would have to pass the `progress` var to every function to respect `copy_impl: impl Fn(PathBuf, PathBuf, Span)`. Please let me know if this is not clear :p --------- Co-authored-by: Reilly Wood <reilly.wood@icloud.com>
2023-02-22 19:57:38 +00:00
nu!(
2019-08-29 06:31:56 +00:00
cwd: dirs.root(),
`cp` progress bar implementation (#8012) # NOTE Clean duplicate of #7825 Sorry about all the mess guys... I got confuse with GitHub and and ended up mankind that mess. This the same code I just cleaned the commits. # Description Progress bar implementation for the `cp` command. Now if the flag `-p` or `--progress` is set, then the user will be able to see the progress of the file or files being copy ![progressbar_cp01](https://user-images.githubusercontent.com/38369407/213899494-0f6a4aa9-ee82-48c3-a1f1-1816f3fc1d9c.jpg) ![progressbar_cp02](https://user-images.githubusercontent.com/38369407/213899497-2f9e6e8c-fdd9-400b-bd8d-c59899ae0368.jpg) # User-Facing Changes A new flag (`--progress` `-p`) was added to the `cp` command Examples: ```nu cp -p test_file.txt test_folder_1\ cp -r -p test_folder\* test_folder_1\ cp -r -p -i test_folder\* test_folder_1\ ``` ## Notes - The progress bar uses `std::io::{Read, Write}` instead of `std::fs::copy` to get the progress. that means that when the progress bar is used the copy process might be a bit slower. - Progress bar for symbolic links TBD: Since symbolic links are usually very light I think is not worth it to duplicate the function `copy_symlink` just to add a progress bar that will be so fast to the point is not needed, but.. for consistency purposes we might need to added it, In that case I would have to pass the variable `progress` by parameter (to not duplicate code unnecessary). If I do that i would have to pass the `progress` var to every function to respect `copy_impl: impl Fn(PathBuf, PathBuf, Span)`. Please let me know if this is not clear :p --------- Co-authored-by: Reilly Wood <reilly.wood@icloud.com>
2023-02-22 19:57:38 +00:00
"cp {} `{}` cp_test_1/sample.ini",
progress_flag,
test_file.display()
);
2019-08-29 06:31:56 +00:00
assert!(dirs.test().join("sample.ini").exists());
`cp` progress bar implementation (#8012) # NOTE Clean duplicate of #7825 Sorry about all the mess guys... I got confuse with GitHub and and ended up mankind that mess. This the same code I just cleaned the commits. # Description Progress bar implementation for the `cp` command. Now if the flag `-p` or `--progress` is set, then the user will be able to see the progress of the file or files being copy ![progressbar_cp01](https://user-images.githubusercontent.com/38369407/213899494-0f6a4aa9-ee82-48c3-a1f1-1816f3fc1d9c.jpg) ![progressbar_cp02](https://user-images.githubusercontent.com/38369407/213899497-2f9e6e8c-fdd9-400b-bd8d-c59899ae0368.jpg) # User-Facing Changes A new flag (`--progress` `-p`) was added to the `cp` command Examples: ```nu cp -p test_file.txt test_folder_1\ cp -r -p test_folder\* test_folder_1\ cp -r -p -i test_folder\* test_folder_1\ ``` ## Notes - The progress bar uses `std::io::{Read, Write}` instead of `std::fs::copy` to get the progress. that means that when the progress bar is used the copy process might be a bit slower. - Progress bar for symbolic links TBD: Since symbolic links are usually very light I think is not worth it to duplicate the function `copy_symlink` just to add a progress bar that will be so fast to the point is not needed, but.. for consistency purposes we might need to added it, In that case I would have to pass the variable `progress` by parameter (to not duplicate code unnecessary). If I do that i would have to pass the `progress` var to every function to respect `copy_impl: impl Fn(PathBuf, PathBuf, Span)`. Please let me know if this is not clear :p --------- Co-authored-by: Reilly Wood <reilly.wood@icloud.com>
2023-02-22 19:57:38 +00:00
// Get the hash of the copied file content to check against first_hash.
let after_cp_hash = get_file_hash(dirs.test().join("sample.ini").display());
assert_eq!(first_hash, after_cp_hash);
});
2019-08-06 07:05:47 +00:00
}
#[test]
fn copies_the_file_inside_directory_if_path_to_copy_is_directory() {
`cp` progress bar implementation (#8012) # NOTE Clean duplicate of #7825 Sorry about all the mess guys... I got confuse with GitHub and and ended up mankind that mess. This the same code I just cleaned the commits. # Description Progress bar implementation for the `cp` command. Now if the flag `-p` or `--progress` is set, then the user will be able to see the progress of the file or files being copy ![progressbar_cp01](https://user-images.githubusercontent.com/38369407/213899494-0f6a4aa9-ee82-48c3-a1f1-1816f3fc1d9c.jpg) ![progressbar_cp02](https://user-images.githubusercontent.com/38369407/213899497-2f9e6e8c-fdd9-400b-bd8d-c59899ae0368.jpg) # User-Facing Changes A new flag (`--progress` `-p`) was added to the `cp` command Examples: ```nu cp -p test_file.txt test_folder_1\ cp -r -p test_folder\* test_folder_1\ cp -r -p -i test_folder\* test_folder_1\ ``` ## Notes - The progress bar uses `std::io::{Read, Write}` instead of `std::fs::copy` to get the progress. that means that when the progress bar is used the copy process might be a bit slower. - Progress bar for symbolic links TBD: Since symbolic links are usually very light I think is not worth it to duplicate the function `copy_symlink` just to add a progress bar that will be so fast to the point is not needed, but.. for consistency purposes we might need to added it, In that case I would have to pass the variable `progress` by parameter (to not duplicate code unnecessary). If I do that i would have to pass the `progress` var to every function to respect `copy_impl: impl Fn(PathBuf, PathBuf, Span)`. Please let me know if this is not clear :p --------- Co-authored-by: Reilly Wood <reilly.wood@icloud.com>
2023-02-22 19:57:38 +00:00
copies_the_file_inside_directory_if_path_to_copy_is_directory_impl(false);
copies_the_file_inside_directory_if_path_to_copy_is_directory_impl(true);
}
fn copies_the_file_inside_directory_if_path_to_copy_is_directory_impl(progress: bool) {
Playground::setup("cp_test_2", |dirs, _| {
let expected_file = AbsoluteFile::new(dirs.test().join("sample.ini"));
`cp` progress bar implementation (#8012) # NOTE Clean duplicate of #7825 Sorry about all the mess guys... I got confuse with GitHub and and ended up mankind that mess. This the same code I just cleaned the commits. # Description Progress bar implementation for the `cp` command. Now if the flag `-p` or `--progress` is set, then the user will be able to see the progress of the file or files being copy ![progressbar_cp01](https://user-images.githubusercontent.com/38369407/213899494-0f6a4aa9-ee82-48c3-a1f1-1816f3fc1d9c.jpg) ![progressbar_cp02](https://user-images.githubusercontent.com/38369407/213899497-2f9e6e8c-fdd9-400b-bd8d-c59899ae0368.jpg) # User-Facing Changes A new flag (`--progress` `-p`) was added to the `cp` command Examples: ```nu cp -p test_file.txt test_folder_1\ cp -r -p test_folder\* test_folder_1\ cp -r -p -i test_folder\* test_folder_1\ ``` ## Notes - The progress bar uses `std::io::{Read, Write}` instead of `std::fs::copy` to get the progress. that means that when the progress bar is used the copy process might be a bit slower. - Progress bar for symbolic links TBD: Since symbolic links are usually very light I think is not worth it to duplicate the function `copy_symlink` just to add a progress bar that will be so fast to the point is not needed, but.. for consistency purposes we might need to added it, In that case I would have to pass the variable `progress` by parameter (to not duplicate code unnecessary). If I do that i would have to pass the `progress` var to every function to respect `copy_impl: impl Fn(PathBuf, PathBuf, Span)`. Please let me know if this is not clear :p --------- Co-authored-by: Reilly Wood <reilly.wood@icloud.com>
2023-02-22 19:57:38 +00:00
let progress_flag = if progress { "-p" } else { "" };
2019-08-06 07:05:47 +00:00
`cp` progress bar implementation (#8012) # NOTE Clean duplicate of #7825 Sorry about all the mess guys... I got confuse with GitHub and and ended up mankind that mess. This the same code I just cleaned the commits. # Description Progress bar implementation for the `cp` command. Now if the flag `-p` or `--progress` is set, then the user will be able to see the progress of the file or files being copy ![progressbar_cp01](https://user-images.githubusercontent.com/38369407/213899494-0f6a4aa9-ee82-48c3-a1f1-1816f3fc1d9c.jpg) ![progressbar_cp02](https://user-images.githubusercontent.com/38369407/213899497-2f9e6e8c-fdd9-400b-bd8d-c59899ae0368.jpg) # User-Facing Changes A new flag (`--progress` `-p`) was added to the `cp` command Examples: ```nu cp -p test_file.txt test_folder_1\ cp -r -p test_folder\* test_folder_1\ cp -r -p -i test_folder\* test_folder_1\ ``` ## Notes - The progress bar uses `std::io::{Read, Write}` instead of `std::fs::copy` to get the progress. that means that when the progress bar is used the copy process might be a bit slower. - Progress bar for symbolic links TBD: Since symbolic links are usually very light I think is not worth it to duplicate the function `copy_symlink` just to add a progress bar that will be so fast to the point is not needed, but.. for consistency purposes we might need to added it, In that case I would have to pass the variable `progress` by parameter (to not duplicate code unnecessary). If I do that i would have to pass the `progress` var to every function to respect `copy_impl: impl Fn(PathBuf, PathBuf, Span)`. Please let me know if this is not clear :p --------- Co-authored-by: Reilly Wood <reilly.wood@icloud.com>
2023-02-22 19:57:38 +00:00
// Get the hash of the file content to check integrity after copy.
let first_hash = get_file_hash(dirs.formats().join("../formats/sample.ini").display());
nu!(
2019-08-29 06:31:56 +00:00
cwd: dirs.formats(),
`cp` progress bar implementation (#8012) # NOTE Clean duplicate of #7825 Sorry about all the mess guys... I got confuse with GitHub and and ended up mankind that mess. This the same code I just cleaned the commits. # Description Progress bar implementation for the `cp` command. Now if the flag `-p` or `--progress` is set, then the user will be able to see the progress of the file or files being copy ![progressbar_cp01](https://user-images.githubusercontent.com/38369407/213899494-0f6a4aa9-ee82-48c3-a1f1-1816f3fc1d9c.jpg) ![progressbar_cp02](https://user-images.githubusercontent.com/38369407/213899497-2f9e6e8c-fdd9-400b-bd8d-c59899ae0368.jpg) # User-Facing Changes A new flag (`--progress` `-p`) was added to the `cp` command Examples: ```nu cp -p test_file.txt test_folder_1\ cp -r -p test_folder\* test_folder_1\ cp -r -p -i test_folder\* test_folder_1\ ``` ## Notes - The progress bar uses `std::io::{Read, Write}` instead of `std::fs::copy` to get the progress. that means that when the progress bar is used the copy process might be a bit slower. - Progress bar for symbolic links TBD: Since symbolic links are usually very light I think is not worth it to duplicate the function `copy_symlink` just to add a progress bar that will be so fast to the point is not needed, but.. for consistency purposes we might need to added it, In that case I would have to pass the variable `progress` by parameter (to not duplicate code unnecessary). If I do that i would have to pass the `progress` var to every function to respect `copy_impl: impl Fn(PathBuf, PathBuf, Span)`. Please let me know if this is not clear :p --------- Co-authored-by: Reilly Wood <reilly.wood@icloud.com>
2023-02-22 19:57:38 +00:00
"cp {} ../formats/sample.ini {}",
progress_flag,
expected_file.dir()
);
2019-08-06 07:05:47 +00:00
2019-08-29 06:31:56 +00:00
assert!(dirs.test().join("sample.ini").exists());
`cp` progress bar implementation (#8012) # NOTE Clean duplicate of #7825 Sorry about all the mess guys... I got confuse with GitHub and and ended up mankind that mess. This the same code I just cleaned the commits. # Description Progress bar implementation for the `cp` command. Now if the flag `-p` or `--progress` is set, then the user will be able to see the progress of the file or files being copy ![progressbar_cp01](https://user-images.githubusercontent.com/38369407/213899494-0f6a4aa9-ee82-48c3-a1f1-1816f3fc1d9c.jpg) ![progressbar_cp02](https://user-images.githubusercontent.com/38369407/213899497-2f9e6e8c-fdd9-400b-bd8d-c59899ae0368.jpg) # User-Facing Changes A new flag (`--progress` `-p`) was added to the `cp` command Examples: ```nu cp -p test_file.txt test_folder_1\ cp -r -p test_folder\* test_folder_1\ cp -r -p -i test_folder\* test_folder_1\ ``` ## Notes - The progress bar uses `std::io::{Read, Write}` instead of `std::fs::copy` to get the progress. that means that when the progress bar is used the copy process might be a bit slower. - Progress bar for symbolic links TBD: Since symbolic links are usually very light I think is not worth it to duplicate the function `copy_symlink` just to add a progress bar that will be so fast to the point is not needed, but.. for consistency purposes we might need to added it, In that case I would have to pass the variable `progress` by parameter (to not duplicate code unnecessary). If I do that i would have to pass the `progress` var to every function to respect `copy_impl: impl Fn(PathBuf, PathBuf, Span)`. Please let me know if this is not clear :p --------- Co-authored-by: Reilly Wood <reilly.wood@icloud.com>
2023-02-22 19:57:38 +00:00
// Check the integrity of the file.
let after_cp_hash = get_file_hash(expected_file);
assert_eq!(first_hash, after_cp_hash);
})
2019-08-06 07:05:47 +00:00
}
#[test]
fn error_if_attempting_to_copy_a_directory_to_another_directory() {
`cp` progress bar implementation (#8012) # NOTE Clean duplicate of #7825 Sorry about all the mess guys... I got confuse with GitHub and and ended up mankind that mess. This the same code I just cleaned the commits. # Description Progress bar implementation for the `cp` command. Now if the flag `-p` or `--progress` is set, then the user will be able to see the progress of the file or files being copy ![progressbar_cp01](https://user-images.githubusercontent.com/38369407/213899494-0f6a4aa9-ee82-48c3-a1f1-1816f3fc1d9c.jpg) ![progressbar_cp02](https://user-images.githubusercontent.com/38369407/213899497-2f9e6e8c-fdd9-400b-bd8d-c59899ae0368.jpg) # User-Facing Changes A new flag (`--progress` `-p`) was added to the `cp` command Examples: ```nu cp -p test_file.txt test_folder_1\ cp -r -p test_folder\* test_folder_1\ cp -r -p -i test_folder\* test_folder_1\ ``` ## Notes - The progress bar uses `std::io::{Read, Write}` instead of `std::fs::copy` to get the progress. that means that when the progress bar is used the copy process might be a bit slower. - Progress bar for symbolic links TBD: Since symbolic links are usually very light I think is not worth it to duplicate the function `copy_symlink` just to add a progress bar that will be so fast to the point is not needed, but.. for consistency purposes we might need to added it, In that case I would have to pass the variable `progress` by parameter (to not duplicate code unnecessary). If I do that i would have to pass the `progress` var to every function to respect `copy_impl: impl Fn(PathBuf, PathBuf, Span)`. Please let me know if this is not clear :p --------- Co-authored-by: Reilly Wood <reilly.wood@icloud.com>
2023-02-22 19:57:38 +00:00
error_if_attempting_to_copy_a_directory_to_another_directory_impl(false);
error_if_attempting_to_copy_a_directory_to_another_directory_impl(true);
}
fn error_if_attempting_to_copy_a_directory_to_another_directory_impl(progress: bool) {
Playground::setup("cp_test_3", |dirs, _| {
`cp` progress bar implementation (#8012) # NOTE Clean duplicate of #7825 Sorry about all the mess guys... I got confuse with GitHub and and ended up mankind that mess. This the same code I just cleaned the commits. # Description Progress bar implementation for the `cp` command. Now if the flag `-p` or `--progress` is set, then the user will be able to see the progress of the file or files being copy ![progressbar_cp01](https://user-images.githubusercontent.com/38369407/213899494-0f6a4aa9-ee82-48c3-a1f1-1816f3fc1d9c.jpg) ![progressbar_cp02](https://user-images.githubusercontent.com/38369407/213899497-2f9e6e8c-fdd9-400b-bd8d-c59899ae0368.jpg) # User-Facing Changes A new flag (`--progress` `-p`) was added to the `cp` command Examples: ```nu cp -p test_file.txt test_folder_1\ cp -r -p test_folder\* test_folder_1\ cp -r -p -i test_folder\* test_folder_1\ ``` ## Notes - The progress bar uses `std::io::{Read, Write}` instead of `std::fs::copy` to get the progress. that means that when the progress bar is used the copy process might be a bit slower. - Progress bar for symbolic links TBD: Since symbolic links are usually very light I think is not worth it to duplicate the function `copy_symlink` just to add a progress bar that will be so fast to the point is not needed, but.. for consistency purposes we might need to added it, In that case I would have to pass the variable `progress` by parameter (to not duplicate code unnecessary). If I do that i would have to pass the `progress` var to every function to respect `copy_impl: impl Fn(PathBuf, PathBuf, Span)`. Please let me know if this is not clear :p --------- Co-authored-by: Reilly Wood <reilly.wood@icloud.com>
2023-02-22 19:57:38 +00:00
let progress_flag = if progress { "-p" } else { "" };
let actual = nu!(
2019-08-29 06:31:56 +00:00
cwd: dirs.formats(),
`cp` progress bar implementation (#8012) # NOTE Clean duplicate of #7825 Sorry about all the mess guys... I got confuse with GitHub and and ended up mankind that mess. This the same code I just cleaned the commits. # Description Progress bar implementation for the `cp` command. Now if the flag `-p` or `--progress` is set, then the user will be able to see the progress of the file or files being copy ![progressbar_cp01](https://user-images.githubusercontent.com/38369407/213899494-0f6a4aa9-ee82-48c3-a1f1-1816f3fc1d9c.jpg) ![progressbar_cp02](https://user-images.githubusercontent.com/38369407/213899497-2f9e6e8c-fdd9-400b-bd8d-c59899ae0368.jpg) # User-Facing Changes A new flag (`--progress` `-p`) was added to the `cp` command Examples: ```nu cp -p test_file.txt test_folder_1\ cp -r -p test_folder\* test_folder_1\ cp -r -p -i test_folder\* test_folder_1\ ``` ## Notes - The progress bar uses `std::io::{Read, Write}` instead of `std::fs::copy` to get the progress. that means that when the progress bar is used the copy process might be a bit slower. - Progress bar for symbolic links TBD: Since symbolic links are usually very light I think is not worth it to duplicate the function `copy_symlink` just to add a progress bar that will be so fast to the point is not needed, but.. for consistency purposes we might need to added it, In that case I would have to pass the variable `progress` by parameter (to not duplicate code unnecessary). If I do that i would have to pass the `progress` var to every function to respect `copy_impl: impl Fn(PathBuf, PathBuf, Span)`. Please let me know if this is not clear :p --------- Co-authored-by: Reilly Wood <reilly.wood@icloud.com>
2023-02-22 19:57:38 +00:00
"cp {} ../formats {}",
progress_flag,
dirs.test().display()
2019-08-29 06:31:56 +00:00
);
2019-08-06 07:05:47 +00:00
assert!(actual.err.contains("../formats"));
assert!(actual.err.contains("resolves to a directory (not copied)"));
});
2019-08-06 07:05:47 +00:00
}
#[test]
fn copies_the_directory_inside_directory_if_path_to_copy_is_directory_and_with_recursive_flag() {
`cp` progress bar implementation (#8012) # NOTE Clean duplicate of #7825 Sorry about all the mess guys... I got confuse with GitHub and and ended up mankind that mess. This the same code I just cleaned the commits. # Description Progress bar implementation for the `cp` command. Now if the flag `-p` or `--progress` is set, then the user will be able to see the progress of the file or files being copy ![progressbar_cp01](https://user-images.githubusercontent.com/38369407/213899494-0f6a4aa9-ee82-48c3-a1f1-1816f3fc1d9c.jpg) ![progressbar_cp02](https://user-images.githubusercontent.com/38369407/213899497-2f9e6e8c-fdd9-400b-bd8d-c59899ae0368.jpg) # User-Facing Changes A new flag (`--progress` `-p`) was added to the `cp` command Examples: ```nu cp -p test_file.txt test_folder_1\ cp -r -p test_folder\* test_folder_1\ cp -r -p -i test_folder\* test_folder_1\ ``` ## Notes - The progress bar uses `std::io::{Read, Write}` instead of `std::fs::copy` to get the progress. that means that when the progress bar is used the copy process might be a bit slower. - Progress bar for symbolic links TBD: Since symbolic links are usually very light I think is not worth it to duplicate the function `copy_symlink` just to add a progress bar that will be so fast to the point is not needed, but.. for consistency purposes we might need to added it, In that case I would have to pass the variable `progress` by parameter (to not duplicate code unnecessary). If I do that i would have to pass the `progress` var to every function to respect `copy_impl: impl Fn(PathBuf, PathBuf, Span)`. Please let me know if this is not clear :p --------- Co-authored-by: Reilly Wood <reilly.wood@icloud.com>
2023-02-22 19:57:38 +00:00
copies_the_directory_inside_directory_if_path_to_copy_is_directory_and_with_recursive_flag_impl(
false,
);
copies_the_directory_inside_directory_if_path_to_copy_is_directory_and_with_recursive_flag_impl(
true,
);
}
fn copies_the_directory_inside_directory_if_path_to_copy_is_directory_and_with_recursive_flag_impl(
progress: bool,
) {
2019-08-29 00:32:42 +00:00
Playground::setup("cp_test_4", |dirs, sandbox| {
sandbox
.within("originals")
.with_files(vec![
EmptyFile("yehuda.txt"),
EmptyFile("jttxt"),
EmptyFile("andres.txt"),
])
.mkdir("expected");
let expected_dir = dirs.test().join("expected").join("originals");
`cp` progress bar implementation (#8012) # NOTE Clean duplicate of #7825 Sorry about all the mess guys... I got confuse with GitHub and and ended up mankind that mess. This the same code I just cleaned the commits. # Description Progress bar implementation for the `cp` command. Now if the flag `-p` or `--progress` is set, then the user will be able to see the progress of the file or files being copy ![progressbar_cp01](https://user-images.githubusercontent.com/38369407/213899494-0f6a4aa9-ee82-48c3-a1f1-1816f3fc1d9c.jpg) ![progressbar_cp02](https://user-images.githubusercontent.com/38369407/213899497-2f9e6e8c-fdd9-400b-bd8d-c59899ae0368.jpg) # User-Facing Changes A new flag (`--progress` `-p`) was added to the `cp` command Examples: ```nu cp -p test_file.txt test_folder_1\ cp -r -p test_folder\* test_folder_1\ cp -r -p -i test_folder\* test_folder_1\ ``` ## Notes - The progress bar uses `std::io::{Read, Write}` instead of `std::fs::copy` to get the progress. that means that when the progress bar is used the copy process might be a bit slower. - Progress bar for symbolic links TBD: Since symbolic links are usually very light I think is not worth it to duplicate the function `copy_symlink` just to add a progress bar that will be so fast to the point is not needed, but.. for consistency purposes we might need to added it, In that case I would have to pass the variable `progress` by parameter (to not duplicate code unnecessary). If I do that i would have to pass the `progress` var to every function to respect `copy_impl: impl Fn(PathBuf, PathBuf, Span)`. Please let me know if this is not clear :p --------- Co-authored-by: Reilly Wood <reilly.wood@icloud.com>
2023-02-22 19:57:38 +00:00
let progress_flag = if progress { "-p" } else { "" };
2019-08-29 06:31:56 +00:00
nu!(
cwd: dirs.test(),
`cp` progress bar implementation (#8012) # NOTE Clean duplicate of #7825 Sorry about all the mess guys... I got confuse with GitHub and and ended up mankind that mess. This the same code I just cleaned the commits. # Description Progress bar implementation for the `cp` command. Now if the flag `-p` or `--progress` is set, then the user will be able to see the progress of the file or files being copy ![progressbar_cp01](https://user-images.githubusercontent.com/38369407/213899494-0f6a4aa9-ee82-48c3-a1f1-1816f3fc1d9c.jpg) ![progressbar_cp02](https://user-images.githubusercontent.com/38369407/213899497-2f9e6e8c-fdd9-400b-bd8d-c59899ae0368.jpg) # User-Facing Changes A new flag (`--progress` `-p`) was added to the `cp` command Examples: ```nu cp -p test_file.txt test_folder_1\ cp -r -p test_folder\* test_folder_1\ cp -r -p -i test_folder\* test_folder_1\ ``` ## Notes - The progress bar uses `std::io::{Read, Write}` instead of `std::fs::copy` to get the progress. that means that when the progress bar is used the copy process might be a bit slower. - Progress bar for symbolic links TBD: Since symbolic links are usually very light I think is not worth it to duplicate the function `copy_symlink` just to add a progress bar that will be so fast to the point is not needed, but.. for consistency purposes we might need to added it, In that case I would have to pass the variable `progress` by parameter (to not duplicate code unnecessary). If I do that i would have to pass the `progress` var to every function to respect `copy_impl: impl Fn(PathBuf, PathBuf, Span)`. Please let me know if this is not clear :p --------- Co-authored-by: Reilly Wood <reilly.wood@icloud.com>
2023-02-22 19:57:38 +00:00
"cp {} originals expected -r",
progress_flag
2019-08-29 06:31:56 +00:00
);
2019-08-29 06:31:56 +00:00
assert!(expected_dir.exists());
assert!(files_exist_at(
vec![
Path::new("yehuda.txt"),
Path::new("jttxt"),
Path::new("andres.txt")
],
`cp` progress bar implementation (#8012) # NOTE Clean duplicate of #7825 Sorry about all the mess guys... I got confuse with GitHub and and ended up mankind that mess. This the same code I just cleaned the commits. # Description Progress bar implementation for the `cp` command. Now if the flag `-p` or `--progress` is set, then the user will be able to see the progress of the file or files being copy ![progressbar_cp01](https://user-images.githubusercontent.com/38369407/213899494-0f6a4aa9-ee82-48c3-a1f1-1816f3fc1d9c.jpg) ![progressbar_cp02](https://user-images.githubusercontent.com/38369407/213899497-2f9e6e8c-fdd9-400b-bd8d-c59899ae0368.jpg) # User-Facing Changes A new flag (`--progress` `-p`) was added to the `cp` command Examples: ```nu cp -p test_file.txt test_folder_1\ cp -r -p test_folder\* test_folder_1\ cp -r -p -i test_folder\* test_folder_1\ ``` ## Notes - The progress bar uses `std::io::{Read, Write}` instead of `std::fs::copy` to get the progress. that means that when the progress bar is used the copy process might be a bit slower. - Progress bar for symbolic links TBD: Since symbolic links are usually very light I think is not worth it to duplicate the function `copy_symlink` just to add a progress bar that will be so fast to the point is not needed, but.. for consistency purposes we might need to added it, In that case I would have to pass the variable `progress` by parameter (to not duplicate code unnecessary). If I do that i would have to pass the `progress` var to every function to respect `copy_impl: impl Fn(PathBuf, PathBuf, Span)`. Please let me know if this is not clear :p --------- Co-authored-by: Reilly Wood <reilly.wood@icloud.com>
2023-02-22 19:57:38 +00:00
&expected_dir
));
})
}
#[test]
fn deep_copies_with_recursive_flag() {
`cp` progress bar implementation (#8012) # NOTE Clean duplicate of #7825 Sorry about all the mess guys... I got confuse with GitHub and and ended up mankind that mess. This the same code I just cleaned the commits. # Description Progress bar implementation for the `cp` command. Now if the flag `-p` or `--progress` is set, then the user will be able to see the progress of the file or files being copy ![progressbar_cp01](https://user-images.githubusercontent.com/38369407/213899494-0f6a4aa9-ee82-48c3-a1f1-1816f3fc1d9c.jpg) ![progressbar_cp02](https://user-images.githubusercontent.com/38369407/213899497-2f9e6e8c-fdd9-400b-bd8d-c59899ae0368.jpg) # User-Facing Changes A new flag (`--progress` `-p`) was added to the `cp` command Examples: ```nu cp -p test_file.txt test_folder_1\ cp -r -p test_folder\* test_folder_1\ cp -r -p -i test_folder\* test_folder_1\ ``` ## Notes - The progress bar uses `std::io::{Read, Write}` instead of `std::fs::copy` to get the progress. that means that when the progress bar is used the copy process might be a bit slower. - Progress bar for symbolic links TBD: Since symbolic links are usually very light I think is not worth it to duplicate the function `copy_symlink` just to add a progress bar that will be so fast to the point is not needed, but.. for consistency purposes we might need to added it, In that case I would have to pass the variable `progress` by parameter (to not duplicate code unnecessary). If I do that i would have to pass the `progress` var to every function to respect `copy_impl: impl Fn(PathBuf, PathBuf, Span)`. Please let me know if this is not clear :p --------- Co-authored-by: Reilly Wood <reilly.wood@icloud.com>
2023-02-22 19:57:38 +00:00
deep_copies_with_recursive_flag_impl(false);
deep_copies_with_recursive_flag_impl(true);
}
fn deep_copies_with_recursive_flag_impl(progress: bool) {
2019-08-29 00:32:42 +00:00
Playground::setup("cp_test_5", |dirs, sandbox| {
sandbox
.within("originals")
.with_files(vec![EmptyFile("manifest.txt")])
.within("originals/contributors")
.with_files(vec![
EmptyFile("yehuda.txt"),
EmptyFile("jttxt"),
EmptyFile("andres.txt"),
])
.within("originals/contributors/JT")
.with_files(vec![EmptyFile("errors.txt"), EmptyFile("multishells.txt")])
.within("originals/contributors/andres")
.with_files(vec![EmptyFile("coverage.txt"), EmptyFile("commands.txt")])
.within("originals/contributors/yehuda")
.with_files(vec![EmptyFile("defer-evaluation.txt")])
.mkdir("expected");
let expected_dir = dirs.test().join("expected").join("originals");
`cp` progress bar implementation (#8012) # NOTE Clean duplicate of #7825 Sorry about all the mess guys... I got confuse with GitHub and and ended up mankind that mess. This the same code I just cleaned the commits. # Description Progress bar implementation for the `cp` command. Now if the flag `-p` or `--progress` is set, then the user will be able to see the progress of the file or files being copy ![progressbar_cp01](https://user-images.githubusercontent.com/38369407/213899494-0f6a4aa9-ee82-48c3-a1f1-1816f3fc1d9c.jpg) ![progressbar_cp02](https://user-images.githubusercontent.com/38369407/213899497-2f9e6e8c-fdd9-400b-bd8d-c59899ae0368.jpg) # User-Facing Changes A new flag (`--progress` `-p`) was added to the `cp` command Examples: ```nu cp -p test_file.txt test_folder_1\ cp -r -p test_folder\* test_folder_1\ cp -r -p -i test_folder\* test_folder_1\ ``` ## Notes - The progress bar uses `std::io::{Read, Write}` instead of `std::fs::copy` to get the progress. that means that when the progress bar is used the copy process might be a bit slower. - Progress bar for symbolic links TBD: Since symbolic links are usually very light I think is not worth it to duplicate the function `copy_symlink` just to add a progress bar that will be so fast to the point is not needed, but.. for consistency purposes we might need to added it, In that case I would have to pass the variable `progress` by parameter (to not duplicate code unnecessary). If I do that i would have to pass the `progress` var to every function to respect `copy_impl: impl Fn(PathBuf, PathBuf, Span)`. Please let me know if this is not clear :p --------- Co-authored-by: Reilly Wood <reilly.wood@icloud.com>
2023-02-22 19:57:38 +00:00
let progress_flag = if progress { "-p" } else { "" };
let jts_expected_copied_dir = expected_dir.join("contributors").join("JT");
let andres_expected_copied_dir = expected_dir.join("contributors").join("andres");
let yehudas_expected_copied_dir = expected_dir.join("contributors").join("yehuda");
2019-08-29 06:31:56 +00:00
nu!(
cwd: dirs.test(),
`cp` progress bar implementation (#8012) # NOTE Clean duplicate of #7825 Sorry about all the mess guys... I got confuse with GitHub and and ended up mankind that mess. This the same code I just cleaned the commits. # Description Progress bar implementation for the `cp` command. Now if the flag `-p` or `--progress` is set, then the user will be able to see the progress of the file or files being copy ![progressbar_cp01](https://user-images.githubusercontent.com/38369407/213899494-0f6a4aa9-ee82-48c3-a1f1-1816f3fc1d9c.jpg) ![progressbar_cp02](https://user-images.githubusercontent.com/38369407/213899497-2f9e6e8c-fdd9-400b-bd8d-c59899ae0368.jpg) # User-Facing Changes A new flag (`--progress` `-p`) was added to the `cp` command Examples: ```nu cp -p test_file.txt test_folder_1\ cp -r -p test_folder\* test_folder_1\ cp -r -p -i test_folder\* test_folder_1\ ``` ## Notes - The progress bar uses `std::io::{Read, Write}` instead of `std::fs::copy` to get the progress. that means that when the progress bar is used the copy process might be a bit slower. - Progress bar for symbolic links TBD: Since symbolic links are usually very light I think is not worth it to duplicate the function `copy_symlink` just to add a progress bar that will be so fast to the point is not needed, but.. for consistency purposes we might need to added it, In that case I would have to pass the variable `progress` by parameter (to not duplicate code unnecessary). If I do that i would have to pass the `progress` var to every function to respect `copy_impl: impl Fn(PathBuf, PathBuf, Span)`. Please let me know if this is not clear :p --------- Co-authored-by: Reilly Wood <reilly.wood@icloud.com>
2023-02-22 19:57:38 +00:00
"cp {} originals expected --recursive",
progress_flag
2019-08-29 06:31:56 +00:00
);
2019-08-29 06:31:56 +00:00
assert!(expected_dir.exists());
assert!(files_exist_at(
vec![Path::new("errors.txt"), Path::new("multishells.txt")],
jts_expected_copied_dir
));
assert!(files_exist_at(
vec![Path::new("coverage.txt"), Path::new("commands.txt")],
Resolve Clippy warnings inside tests. (#8315) # Description Command: `cargo clippy --workspace --all-targets` Resolve those warnings: ``` warning: this expression creates a reference which is immediately dereferenced by the compiler --> crates/nu-parser/tests/test_parser.rs:86:59 | 86 | compare_rhs_binaryOp(test_tag, &expected_val, &observed_val); | ^^^^^^^^^^^^^ help: change this to: `observed_val` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow = note: `#[warn(clippy::needless_borrow)]` on by default warning: `assert!(false, ..)` should probably be replaced --> crates/nu-cli/src/completions/command_completions.rs:319:17 | 319 | assert!(false, "Merge delta has failed: {}", err); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: use `panic!(..)` or `unreachable!(..)` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#assertions_on_constants = note: `#[warn(clippy::assertions_on_constants)]` on by default warning: 1 warning emitted warning: `assert!(false, ..)` should probably be replaced --> crates/nu-cli/src/completions/completer.rs:600:13 | 600 | assert!(false, "Error merging delta: {:?}", err); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: use `panic!(..)` or `unreachable!(..)` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#assertions_on_constants warning: length comparison to zero --> crates/nu-cli/src/completions/completer.rs:620:24 | 620 | assert_eq!(result.len() > 0, has_result, "line: {}", line); | ^^^^^^^^^^^^^^^^ help: using `!is_empty` is clearer and more explicit: `!result.is_empty()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#len_zero = note: `#[warn(clippy::len_zero)]` on by default warning: equality checks against true are unnecessary --> crates/nu-cli/src/completions/completer.rs:632:33 | 632 | .filter(|x| *x == true) | ^^^^^^^^^^ help: try simplifying it as shown: `*x` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#bool_comparison = note: `#[warn(clippy::bool_comparison)]` on by default Checking nu v0.76.1 (/home/jaudiger/Development/git-repositories/jaudiger/nushell) warning: 4 warnings emitted warning: the borrowed expression implements the required traits --> crates/nu-command/tests/commands/cp.rs:26:40 | 26 | let first_hash = get_file_hash(&test_file.display()); | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `test_file.display()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow = note: `#[warn(clippy::needless_borrow)]` on by default warning: the borrowed expression implements the required traits --> crates/nu-command/tests/commands/cp.rs:178:13 | 178 | &jonathans_expected_copied_dir | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: change this to: `jonathans_expected_copied_dir` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow warning: the borrowed expression implements the required traits --> crates/nu-command/tests/commands/cp.rs:182:13 | 182 | &andres_expected_copied_dir | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: change this to: `andres_expected_copied_dir` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow warning: the borrowed expression implements the required traits --> crates/nu-command/tests/commands/cp.rs:186:13 | 186 | &yehudas_expected_copied_dir | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: change this to: `yehudas_expected_copied_dir` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow warning: 4 warnings emitted ``` # User-Facing Changes None. # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
2023-03-04 13:58:20 +00:00
andres_expected_copied_dir
));
assert!(files_exist_at(
vec![Path::new("defer-evaluation.txt")],
Resolve Clippy warnings inside tests. (#8315) # Description Command: `cargo clippy --workspace --all-targets` Resolve those warnings: ``` warning: this expression creates a reference which is immediately dereferenced by the compiler --> crates/nu-parser/tests/test_parser.rs:86:59 | 86 | compare_rhs_binaryOp(test_tag, &expected_val, &observed_val); | ^^^^^^^^^^^^^ help: change this to: `observed_val` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow = note: `#[warn(clippy::needless_borrow)]` on by default warning: `assert!(false, ..)` should probably be replaced --> crates/nu-cli/src/completions/command_completions.rs:319:17 | 319 | assert!(false, "Merge delta has failed: {}", err); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: use `panic!(..)` or `unreachable!(..)` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#assertions_on_constants = note: `#[warn(clippy::assertions_on_constants)]` on by default warning: 1 warning emitted warning: `assert!(false, ..)` should probably be replaced --> crates/nu-cli/src/completions/completer.rs:600:13 | 600 | assert!(false, "Error merging delta: {:?}", err); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: use `panic!(..)` or `unreachable!(..)` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#assertions_on_constants warning: length comparison to zero --> crates/nu-cli/src/completions/completer.rs:620:24 | 620 | assert_eq!(result.len() > 0, has_result, "line: {}", line); | ^^^^^^^^^^^^^^^^ help: using `!is_empty` is clearer and more explicit: `!result.is_empty()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#len_zero = note: `#[warn(clippy::len_zero)]` on by default warning: equality checks against true are unnecessary --> crates/nu-cli/src/completions/completer.rs:632:33 | 632 | .filter(|x| *x == true) | ^^^^^^^^^^ help: try simplifying it as shown: `*x` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#bool_comparison = note: `#[warn(clippy::bool_comparison)]` on by default Checking nu v0.76.1 (/home/jaudiger/Development/git-repositories/jaudiger/nushell) warning: 4 warnings emitted warning: the borrowed expression implements the required traits --> crates/nu-command/tests/commands/cp.rs:26:40 | 26 | let first_hash = get_file_hash(&test_file.display()); | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `test_file.display()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow = note: `#[warn(clippy::needless_borrow)]` on by default warning: the borrowed expression implements the required traits --> crates/nu-command/tests/commands/cp.rs:178:13 | 178 | &jonathans_expected_copied_dir | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: change this to: `jonathans_expected_copied_dir` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow warning: the borrowed expression implements the required traits --> crates/nu-command/tests/commands/cp.rs:182:13 | 182 | &andres_expected_copied_dir | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: change this to: `andres_expected_copied_dir` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow warning: the borrowed expression implements the required traits --> crates/nu-command/tests/commands/cp.rs:186:13 | 186 | &yehudas_expected_copied_dir | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: change this to: `yehudas_expected_copied_dir` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow warning: 4 warnings emitted ``` # User-Facing Changes None. # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
2023-03-04 13:58:20 +00:00
yehudas_expected_copied_dir
));
})
}
#[test]
fn copies_using_path_with_wildcard() {
`cp` progress bar implementation (#8012) # NOTE Clean duplicate of #7825 Sorry about all the mess guys... I got confuse with GitHub and and ended up mankind that mess. This the same code I just cleaned the commits. # Description Progress bar implementation for the `cp` command. Now if the flag `-p` or `--progress` is set, then the user will be able to see the progress of the file or files being copy ![progressbar_cp01](https://user-images.githubusercontent.com/38369407/213899494-0f6a4aa9-ee82-48c3-a1f1-1816f3fc1d9c.jpg) ![progressbar_cp02](https://user-images.githubusercontent.com/38369407/213899497-2f9e6e8c-fdd9-400b-bd8d-c59899ae0368.jpg) # User-Facing Changes A new flag (`--progress` `-p`) was added to the `cp` command Examples: ```nu cp -p test_file.txt test_folder_1\ cp -r -p test_folder\* test_folder_1\ cp -r -p -i test_folder\* test_folder_1\ ``` ## Notes - The progress bar uses `std::io::{Read, Write}` instead of `std::fs::copy` to get the progress. that means that when the progress bar is used the copy process might be a bit slower. - Progress bar for symbolic links TBD: Since symbolic links are usually very light I think is not worth it to duplicate the function `copy_symlink` just to add a progress bar that will be so fast to the point is not needed, but.. for consistency purposes we might need to added it, In that case I would have to pass the variable `progress` by parameter (to not duplicate code unnecessary). If I do that i would have to pass the `progress` var to every function to respect `copy_impl: impl Fn(PathBuf, PathBuf, Span)`. Please let me know if this is not clear :p --------- Co-authored-by: Reilly Wood <reilly.wood@icloud.com>
2023-02-22 19:57:38 +00:00
copies_using_path_with_wildcard_impl(false);
copies_using_path_with_wildcard_impl(true);
}
fn copies_using_path_with_wildcard_impl(progress: bool) {
Playground::setup("cp_test_6", |dirs, _| {
`cp` progress bar implementation (#8012) # NOTE Clean duplicate of #7825 Sorry about all the mess guys... I got confuse with GitHub and and ended up mankind that mess. This the same code I just cleaned the commits. # Description Progress bar implementation for the `cp` command. Now if the flag `-p` or `--progress` is set, then the user will be able to see the progress of the file or files being copy ![progressbar_cp01](https://user-images.githubusercontent.com/38369407/213899494-0f6a4aa9-ee82-48c3-a1f1-1816f3fc1d9c.jpg) ![progressbar_cp02](https://user-images.githubusercontent.com/38369407/213899497-2f9e6e8c-fdd9-400b-bd8d-c59899ae0368.jpg) # User-Facing Changes A new flag (`--progress` `-p`) was added to the `cp` command Examples: ```nu cp -p test_file.txt test_folder_1\ cp -r -p test_folder\* test_folder_1\ cp -r -p -i test_folder\* test_folder_1\ ``` ## Notes - The progress bar uses `std::io::{Read, Write}` instead of `std::fs::copy` to get the progress. that means that when the progress bar is used the copy process might be a bit slower. - Progress bar for symbolic links TBD: Since symbolic links are usually very light I think is not worth it to duplicate the function `copy_symlink` just to add a progress bar that will be so fast to the point is not needed, but.. for consistency purposes we might need to added it, In that case I would have to pass the variable `progress` by parameter (to not duplicate code unnecessary). If I do that i would have to pass the `progress` var to every function to respect `copy_impl: impl Fn(PathBuf, PathBuf, Span)`. Please let me know if this is not clear :p --------- Co-authored-by: Reilly Wood <reilly.wood@icloud.com>
2023-02-22 19:57:38 +00:00
let progress_flag = if progress { "-p" } else { "" };
// Get the hash of the file content to check integrity after copy.
let src_hashes = nu!(
cwd: dirs.formats(),
"for file in (ls ../formats/*) { open --raw $file.name | to text | hash md5 }"
)
.out;
2019-08-29 06:31:56 +00:00
nu!(
cwd: dirs.formats(),
`cp` progress bar implementation (#8012) # NOTE Clean duplicate of #7825 Sorry about all the mess guys... I got confuse with GitHub and and ended up mankind that mess. This the same code I just cleaned the commits. # Description Progress bar implementation for the `cp` command. Now if the flag `-p` or `--progress` is set, then the user will be able to see the progress of the file or files being copy ![progressbar_cp01](https://user-images.githubusercontent.com/38369407/213899494-0f6a4aa9-ee82-48c3-a1f1-1816f3fc1d9c.jpg) ![progressbar_cp02](https://user-images.githubusercontent.com/38369407/213899497-2f9e6e8c-fdd9-400b-bd8d-c59899ae0368.jpg) # User-Facing Changes A new flag (`--progress` `-p`) was added to the `cp` command Examples: ```nu cp -p test_file.txt test_folder_1\ cp -r -p test_folder\* test_folder_1\ cp -r -p -i test_folder\* test_folder_1\ ``` ## Notes - The progress bar uses `std::io::{Read, Write}` instead of `std::fs::copy` to get the progress. that means that when the progress bar is used the copy process might be a bit slower. - Progress bar for symbolic links TBD: Since symbolic links are usually very light I think is not worth it to duplicate the function `copy_symlink` just to add a progress bar that will be so fast to the point is not needed, but.. for consistency purposes we might need to added it, In that case I would have to pass the variable `progress` by parameter (to not duplicate code unnecessary). If I do that i would have to pass the `progress` var to every function to respect `copy_impl: impl Fn(PathBuf, PathBuf, Span)`. Please let me know if this is not clear :p --------- Co-authored-by: Reilly Wood <reilly.wood@icloud.com>
2023-02-22 19:57:38 +00:00
"cp {} -r ../formats/* {}",
progress_flag,
dirs.test().display()
2019-08-29 06:31:56 +00:00
);
assert!(files_exist_at(
vec![
Path::new("caco3_plastics.csv"),
Path::new("cargo_sample.toml"),
Path::new("jt.xml"),
Path::new("sample.ini"),
Path::new("sgml_description.json"),
Path::new("utf16.ini"),
],
dirs.test()
));
`cp` progress bar implementation (#8012) # NOTE Clean duplicate of #7825 Sorry about all the mess guys... I got confuse with GitHub and and ended up mankind that mess. This the same code I just cleaned the commits. # Description Progress bar implementation for the `cp` command. Now if the flag `-p` or `--progress` is set, then the user will be able to see the progress of the file or files being copy ![progressbar_cp01](https://user-images.githubusercontent.com/38369407/213899494-0f6a4aa9-ee82-48c3-a1f1-1816f3fc1d9c.jpg) ![progressbar_cp02](https://user-images.githubusercontent.com/38369407/213899497-2f9e6e8c-fdd9-400b-bd8d-c59899ae0368.jpg) # User-Facing Changes A new flag (`--progress` `-p`) was added to the `cp` command Examples: ```nu cp -p test_file.txt test_folder_1\ cp -r -p test_folder\* test_folder_1\ cp -r -p -i test_folder\* test_folder_1\ ``` ## Notes - The progress bar uses `std::io::{Read, Write}` instead of `std::fs::copy` to get the progress. that means that when the progress bar is used the copy process might be a bit slower. - Progress bar for symbolic links TBD: Since symbolic links are usually very light I think is not worth it to duplicate the function `copy_symlink` just to add a progress bar that will be so fast to the point is not needed, but.. for consistency purposes we might need to added it, In that case I would have to pass the variable `progress` by parameter (to not duplicate code unnecessary). If I do that i would have to pass the `progress` var to every function to respect `copy_impl: impl Fn(PathBuf, PathBuf, Span)`. Please let me know if this is not clear :p --------- Co-authored-by: Reilly Wood <reilly.wood@icloud.com>
2023-02-22 19:57:38 +00:00
// Check integrity after the copy is done
let dst_hashes = nu!(
cwd: dirs.formats(),
"for file in (ls {}) {{ open --raw $file.name | to text | hash md5 }}", dirs.test().display()
).out;
assert_eq!(src_hashes, dst_hashes);
})
}
#[test]
fn copies_using_a_glob() {
`cp` progress bar implementation (#8012) # NOTE Clean duplicate of #7825 Sorry about all the mess guys... I got confuse with GitHub and and ended up mankind that mess. This the same code I just cleaned the commits. # Description Progress bar implementation for the `cp` command. Now if the flag `-p` or `--progress` is set, then the user will be able to see the progress of the file or files being copy ![progressbar_cp01](https://user-images.githubusercontent.com/38369407/213899494-0f6a4aa9-ee82-48c3-a1f1-1816f3fc1d9c.jpg) ![progressbar_cp02](https://user-images.githubusercontent.com/38369407/213899497-2f9e6e8c-fdd9-400b-bd8d-c59899ae0368.jpg) # User-Facing Changes A new flag (`--progress` `-p`) was added to the `cp` command Examples: ```nu cp -p test_file.txt test_folder_1\ cp -r -p test_folder\* test_folder_1\ cp -r -p -i test_folder\* test_folder_1\ ``` ## Notes - The progress bar uses `std::io::{Read, Write}` instead of `std::fs::copy` to get the progress. that means that when the progress bar is used the copy process might be a bit slower. - Progress bar for symbolic links TBD: Since symbolic links are usually very light I think is not worth it to duplicate the function `copy_symlink` just to add a progress bar that will be so fast to the point is not needed, but.. for consistency purposes we might need to added it, In that case I would have to pass the variable `progress` by parameter (to not duplicate code unnecessary). If I do that i would have to pass the `progress` var to every function to respect `copy_impl: impl Fn(PathBuf, PathBuf, Span)`. Please let me know if this is not clear :p --------- Co-authored-by: Reilly Wood <reilly.wood@icloud.com>
2023-02-22 19:57:38 +00:00
copies_using_a_glob_impl(false);
copies_using_a_glob_impl(true);
}
fn copies_using_a_glob_impl(progress: bool) {
Playground::setup("cp_test_7", |dirs, _| {
`cp` progress bar implementation (#8012) # NOTE Clean duplicate of #7825 Sorry about all the mess guys... I got confuse with GitHub and and ended up mankind that mess. This the same code I just cleaned the commits. # Description Progress bar implementation for the `cp` command. Now if the flag `-p` or `--progress` is set, then the user will be able to see the progress of the file or files being copy ![progressbar_cp01](https://user-images.githubusercontent.com/38369407/213899494-0f6a4aa9-ee82-48c3-a1f1-1816f3fc1d9c.jpg) ![progressbar_cp02](https://user-images.githubusercontent.com/38369407/213899497-2f9e6e8c-fdd9-400b-bd8d-c59899ae0368.jpg) # User-Facing Changes A new flag (`--progress` `-p`) was added to the `cp` command Examples: ```nu cp -p test_file.txt test_folder_1\ cp -r -p test_folder\* test_folder_1\ cp -r -p -i test_folder\* test_folder_1\ ``` ## Notes - The progress bar uses `std::io::{Read, Write}` instead of `std::fs::copy` to get the progress. that means that when the progress bar is used the copy process might be a bit slower. - Progress bar for symbolic links TBD: Since symbolic links are usually very light I think is not worth it to duplicate the function `copy_symlink` just to add a progress bar that will be so fast to the point is not needed, but.. for consistency purposes we might need to added it, In that case I would have to pass the variable `progress` by parameter (to not duplicate code unnecessary). If I do that i would have to pass the `progress` var to every function to respect `copy_impl: impl Fn(PathBuf, PathBuf, Span)`. Please let me know if this is not clear :p --------- Co-authored-by: Reilly Wood <reilly.wood@icloud.com>
2023-02-22 19:57:38 +00:00
let progress_flag = if progress { "-p" } else { "" };
// Get the hash of the file content to check integrity after copy.
let src_hashes = nu!(
cwd: dirs.formats(),
"for file in (ls *) { open --raw $file.name | to text | hash md5 }"
)
.out;
2019-08-29 06:31:56 +00:00
nu!(
cwd: dirs.formats(),
`cp` progress bar implementation (#8012) # NOTE Clean duplicate of #7825 Sorry about all the mess guys... I got confuse with GitHub and and ended up mankind that mess. This the same code I just cleaned the commits. # Description Progress bar implementation for the `cp` command. Now if the flag `-p` or `--progress` is set, then the user will be able to see the progress of the file or files being copy ![progressbar_cp01](https://user-images.githubusercontent.com/38369407/213899494-0f6a4aa9-ee82-48c3-a1f1-1816f3fc1d9c.jpg) ![progressbar_cp02](https://user-images.githubusercontent.com/38369407/213899497-2f9e6e8c-fdd9-400b-bd8d-c59899ae0368.jpg) # User-Facing Changes A new flag (`--progress` `-p`) was added to the `cp` command Examples: ```nu cp -p test_file.txt test_folder_1\ cp -r -p test_folder\* test_folder_1\ cp -r -p -i test_folder\* test_folder_1\ ``` ## Notes - The progress bar uses `std::io::{Read, Write}` instead of `std::fs::copy` to get the progress. that means that when the progress bar is used the copy process might be a bit slower. - Progress bar for symbolic links TBD: Since symbolic links are usually very light I think is not worth it to duplicate the function `copy_symlink` just to add a progress bar that will be so fast to the point is not needed, but.. for consistency purposes we might need to added it, In that case I would have to pass the variable `progress` by parameter (to not duplicate code unnecessary). If I do that i would have to pass the `progress` var to every function to respect `copy_impl: impl Fn(PathBuf, PathBuf, Span)`. Please let me know if this is not clear :p --------- Co-authored-by: Reilly Wood <reilly.wood@icloud.com>
2023-02-22 19:57:38 +00:00
"cp {} -r * {}",
progress_flag,
dirs.test().display()
2019-08-29 06:31:56 +00:00
);
assert!(files_exist_at(
vec![
Path::new("caco3_plastics.csv"),
Path::new("cargo_sample.toml"),
Path::new("jt.xml"),
Path::new("sample.ini"),
Path::new("sgml_description.json"),
Path::new("utf16.ini"),
],
dirs.test()
));
`cp` progress bar implementation (#8012) # NOTE Clean duplicate of #7825 Sorry about all the mess guys... I got confuse with GitHub and and ended up mankind that mess. This the same code I just cleaned the commits. # Description Progress bar implementation for the `cp` command. Now if the flag `-p` or `--progress` is set, then the user will be able to see the progress of the file or files being copy ![progressbar_cp01](https://user-images.githubusercontent.com/38369407/213899494-0f6a4aa9-ee82-48c3-a1f1-1816f3fc1d9c.jpg) ![progressbar_cp02](https://user-images.githubusercontent.com/38369407/213899497-2f9e6e8c-fdd9-400b-bd8d-c59899ae0368.jpg) # User-Facing Changes A new flag (`--progress` `-p`) was added to the `cp` command Examples: ```nu cp -p test_file.txt test_folder_1\ cp -r -p test_folder\* test_folder_1\ cp -r -p -i test_folder\* test_folder_1\ ``` ## Notes - The progress bar uses `std::io::{Read, Write}` instead of `std::fs::copy` to get the progress. that means that when the progress bar is used the copy process might be a bit slower. - Progress bar for symbolic links TBD: Since symbolic links are usually very light I think is not worth it to duplicate the function `copy_symlink` just to add a progress bar that will be so fast to the point is not needed, but.. for consistency purposes we might need to added it, In that case I would have to pass the variable `progress` by parameter (to not duplicate code unnecessary). If I do that i would have to pass the `progress` var to every function to respect `copy_impl: impl Fn(PathBuf, PathBuf, Span)`. Please let me know if this is not clear :p --------- Co-authored-by: Reilly Wood <reilly.wood@icloud.com>
2023-02-22 19:57:38 +00:00
// Check integrity after the copy is done
let dst_hashes = nu!(
cwd: dirs.formats(),
"for file in (ls {}) {{ open --raw $file.name | to text | hash md5 }}",
dirs.test().display()
)
.out;
assert_eq!(src_hashes, dst_hashes);
});
}
#[test]
fn copies_same_file_twice() {
`cp` progress bar implementation (#8012) # NOTE Clean duplicate of #7825 Sorry about all the mess guys... I got confuse with GitHub and and ended up mankind that mess. This the same code I just cleaned the commits. # Description Progress bar implementation for the `cp` command. Now if the flag `-p` or `--progress` is set, then the user will be able to see the progress of the file or files being copy ![progressbar_cp01](https://user-images.githubusercontent.com/38369407/213899494-0f6a4aa9-ee82-48c3-a1f1-1816f3fc1d9c.jpg) ![progressbar_cp02](https://user-images.githubusercontent.com/38369407/213899497-2f9e6e8c-fdd9-400b-bd8d-c59899ae0368.jpg) # User-Facing Changes A new flag (`--progress` `-p`) was added to the `cp` command Examples: ```nu cp -p test_file.txt test_folder_1\ cp -r -p test_folder\* test_folder_1\ cp -r -p -i test_folder\* test_folder_1\ ``` ## Notes - The progress bar uses `std::io::{Read, Write}` instead of `std::fs::copy` to get the progress. that means that when the progress bar is used the copy process might be a bit slower. - Progress bar for symbolic links TBD: Since symbolic links are usually very light I think is not worth it to duplicate the function `copy_symlink` just to add a progress bar that will be so fast to the point is not needed, but.. for consistency purposes we might need to added it, In that case I would have to pass the variable `progress` by parameter (to not duplicate code unnecessary). If I do that i would have to pass the `progress` var to every function to respect `copy_impl: impl Fn(PathBuf, PathBuf, Span)`. Please let me know if this is not clear :p --------- Co-authored-by: Reilly Wood <reilly.wood@icloud.com>
2023-02-22 19:57:38 +00:00
copies_same_file_twice_impl(false);
copies_same_file_twice_impl(true);
}
fn copies_same_file_twice_impl(progress: bool) {
Playground::setup("cp_test_8", |dirs, _| {
`cp` progress bar implementation (#8012) # NOTE Clean duplicate of #7825 Sorry about all the mess guys... I got confuse with GitHub and and ended up mankind that mess. This the same code I just cleaned the commits. # Description Progress bar implementation for the `cp` command. Now if the flag `-p` or `--progress` is set, then the user will be able to see the progress of the file or files being copy ![progressbar_cp01](https://user-images.githubusercontent.com/38369407/213899494-0f6a4aa9-ee82-48c3-a1f1-1816f3fc1d9c.jpg) ![progressbar_cp02](https://user-images.githubusercontent.com/38369407/213899497-2f9e6e8c-fdd9-400b-bd8d-c59899ae0368.jpg) # User-Facing Changes A new flag (`--progress` `-p`) was added to the `cp` command Examples: ```nu cp -p test_file.txt test_folder_1\ cp -r -p test_folder\* test_folder_1\ cp -r -p -i test_folder\* test_folder_1\ ``` ## Notes - The progress bar uses `std::io::{Read, Write}` instead of `std::fs::copy` to get the progress. that means that when the progress bar is used the copy process might be a bit slower. - Progress bar for symbolic links TBD: Since symbolic links are usually very light I think is not worth it to duplicate the function `copy_symlink` just to add a progress bar that will be so fast to the point is not needed, but.. for consistency purposes we might need to added it, In that case I would have to pass the variable `progress` by parameter (to not duplicate code unnecessary). If I do that i would have to pass the `progress` var to every function to respect `copy_impl: impl Fn(PathBuf, PathBuf, Span)`. Please let me know if this is not clear :p --------- Co-authored-by: Reilly Wood <reilly.wood@icloud.com>
2023-02-22 19:57:38 +00:00
let progress_flag = if progress { "-p" } else { "" };
nu!(
cwd: dirs.root(),
`cp` progress bar implementation (#8012) # NOTE Clean duplicate of #7825 Sorry about all the mess guys... I got confuse with GitHub and and ended up mankind that mess. This the same code I just cleaned the commits. # Description Progress bar implementation for the `cp` command. Now if the flag `-p` or `--progress` is set, then the user will be able to see the progress of the file or files being copy ![progressbar_cp01](https://user-images.githubusercontent.com/38369407/213899494-0f6a4aa9-ee82-48c3-a1f1-1816f3fc1d9c.jpg) ![progressbar_cp02](https://user-images.githubusercontent.com/38369407/213899497-2f9e6e8c-fdd9-400b-bd8d-c59899ae0368.jpg) # User-Facing Changes A new flag (`--progress` `-p`) was added to the `cp` command Examples: ```nu cp -p test_file.txt test_folder_1\ cp -r -p test_folder\* test_folder_1\ cp -r -p -i test_folder\* test_folder_1\ ``` ## Notes - The progress bar uses `std::io::{Read, Write}` instead of `std::fs::copy` to get the progress. that means that when the progress bar is used the copy process might be a bit slower. - Progress bar for symbolic links TBD: Since symbolic links are usually very light I think is not worth it to duplicate the function `copy_symlink` just to add a progress bar that will be so fast to the point is not needed, but.. for consistency purposes we might need to added it, In that case I would have to pass the variable `progress` by parameter (to not duplicate code unnecessary). If I do that i would have to pass the `progress` var to every function to respect `copy_impl: impl Fn(PathBuf, PathBuf, Span)`. Please let me know if this is not clear :p --------- Co-authored-by: Reilly Wood <reilly.wood@icloud.com>
2023-02-22 19:57:38 +00:00
"cp {} `{}` cp_test_8/sample.ini",
progress_flag,
Add decimals to int when using `into string --decimals` (#6085) * Add decimals to int when using `into string --decimals` * Add tests for `into string` when converting int with `--decimals` * Apply formatting * Merge `into_str` test files * Comment out unused code and add TODOs * Use decimal separator depending on system locale * Add test helper to run closure in different locale * Add tests for int-to-string conversion using different locales * Add utils function to get system locale * Add panic message when locking mutex fails * Catch and resume panic later to prevent Mutex poisoning when test fails * Move test to `nu-test-support` to keep `nu-utils` free of `nu-*` dependencies See https://github.com/nushell/nushell/pull/6085#issuecomment-1193131694 * Rename test support fn `with_fake_locale` to `with_locale_override` * Move `get_system_locale()` to `locale` module * Allow overriding locale with special env variable (when not in release) * Use special env var to override locale during testing * Allow callback to return a value in `with_locale_override()` * Allow multiple options in `nu!` macro * Allow to set locale as `nu!` macro option * Use new `locale` option of `nu!` macro instead of `with_locale_override` Using the `locale` options does not lock the `LOCALE_OVERRIDE_MUTEX` mutex in `nu-test-support::locale_override` but instead calls the `nu` command directly with the `NU_LOCALE_OVERRIDE` environment variable. This allows for parallel test excecution. * Fix: Add option identifier for `cwd` in usage of `nu!` macro * Rely on `Display` trait for formatting `nu!` macro command - Removed the `DisplayPath` trait - Implement `Display` for `AbsolutePath`, `RelativePath` and `AbsoluteFile` * Default to locale `en_US.UTF-8` for tests when using `nu!` macro * Add doc comment to `nu!` macro * Format code using `cargo fmt --all` * Pass function directly instead of wrapping the call in a closure https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure * Pass function to `or_else()` instead of calling it inside `or()` https://rust-lang.github.io/rust-clippy/master/index.html#or_fun_call * Fix: Add option identifier for `cwd` in usage of `nu!` macro
2022-08-13 02:13:50 +00:00
dirs.formats().join("sample.ini").display()
);
nu!(
cwd: dirs.root(),
`cp` progress bar implementation (#8012) # NOTE Clean duplicate of #7825 Sorry about all the mess guys... I got confuse with GitHub and and ended up mankind that mess. This the same code I just cleaned the commits. # Description Progress bar implementation for the `cp` command. Now if the flag `-p` or `--progress` is set, then the user will be able to see the progress of the file or files being copy ![progressbar_cp01](https://user-images.githubusercontent.com/38369407/213899494-0f6a4aa9-ee82-48c3-a1f1-1816f3fc1d9c.jpg) ![progressbar_cp02](https://user-images.githubusercontent.com/38369407/213899497-2f9e6e8c-fdd9-400b-bd8d-c59899ae0368.jpg) # User-Facing Changes A new flag (`--progress` `-p`) was added to the `cp` command Examples: ```nu cp -p test_file.txt test_folder_1\ cp -r -p test_folder\* test_folder_1\ cp -r -p -i test_folder\* test_folder_1\ ``` ## Notes - The progress bar uses `std::io::{Read, Write}` instead of `std::fs::copy` to get the progress. that means that when the progress bar is used the copy process might be a bit slower. - Progress bar for symbolic links TBD: Since symbolic links are usually very light I think is not worth it to duplicate the function `copy_symlink` just to add a progress bar that will be so fast to the point is not needed, but.. for consistency purposes we might need to added it, In that case I would have to pass the variable `progress` by parameter (to not duplicate code unnecessary). If I do that i would have to pass the `progress` var to every function to respect `copy_impl: impl Fn(PathBuf, PathBuf, Span)`. Please let me know if this is not clear :p --------- Co-authored-by: Reilly Wood <reilly.wood@icloud.com>
2023-02-22 19:57:38 +00:00
"cp {} `{}` cp_test_8/sample.ini",
progress_flag,
Add decimals to int when using `into string --decimals` (#6085) * Add decimals to int when using `into string --decimals` * Add tests for `into string` when converting int with `--decimals` * Apply formatting * Merge `into_str` test files * Comment out unused code and add TODOs * Use decimal separator depending on system locale * Add test helper to run closure in different locale * Add tests for int-to-string conversion using different locales * Add utils function to get system locale * Add panic message when locking mutex fails * Catch and resume panic later to prevent Mutex poisoning when test fails * Move test to `nu-test-support` to keep `nu-utils` free of `nu-*` dependencies See https://github.com/nushell/nushell/pull/6085#issuecomment-1193131694 * Rename test support fn `with_fake_locale` to `with_locale_override` * Move `get_system_locale()` to `locale` module * Allow overriding locale with special env variable (when not in release) * Use special env var to override locale during testing * Allow callback to return a value in `with_locale_override()` * Allow multiple options in `nu!` macro * Allow to set locale as `nu!` macro option * Use new `locale` option of `nu!` macro instead of `with_locale_override` Using the `locale` options does not lock the `LOCALE_OVERRIDE_MUTEX` mutex in `nu-test-support::locale_override` but instead calls the `nu` command directly with the `NU_LOCALE_OVERRIDE` environment variable. This allows for parallel test excecution. * Fix: Add option identifier for `cwd` in usage of `nu!` macro * Rely on `Display` trait for formatting `nu!` macro command - Removed the `DisplayPath` trait - Implement `Display` for `AbsolutePath`, `RelativePath` and `AbsoluteFile` * Default to locale `en_US.UTF-8` for tests when using `nu!` macro * Add doc comment to `nu!` macro * Format code using `cargo fmt --all` * Pass function directly instead of wrapping the call in a closure https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure * Pass function to `or_else()` instead of calling it inside `or()` https://rust-lang.github.io/rust-clippy/master/index.html#or_fun_call * Fix: Add option identifier for `cwd` in usage of `nu!` macro
2022-08-13 02:13:50 +00:00
dirs.formats().join("sample.ini").display()
);
assert!(dirs.test().join("sample.ini").exists());
});
}
#[test]
fn copy_files_using_glob_two_parents_up_using_multiple_dots() {
`cp` progress bar implementation (#8012) # NOTE Clean duplicate of #7825 Sorry about all the mess guys... I got confuse with GitHub and and ended up mankind that mess. This the same code I just cleaned the commits. # Description Progress bar implementation for the `cp` command. Now if the flag `-p` or `--progress` is set, then the user will be able to see the progress of the file or files being copy ![progressbar_cp01](https://user-images.githubusercontent.com/38369407/213899494-0f6a4aa9-ee82-48c3-a1f1-1816f3fc1d9c.jpg) ![progressbar_cp02](https://user-images.githubusercontent.com/38369407/213899497-2f9e6e8c-fdd9-400b-bd8d-c59899ae0368.jpg) # User-Facing Changes A new flag (`--progress` `-p`) was added to the `cp` command Examples: ```nu cp -p test_file.txt test_folder_1\ cp -r -p test_folder\* test_folder_1\ cp -r -p -i test_folder\* test_folder_1\ ``` ## Notes - The progress bar uses `std::io::{Read, Write}` instead of `std::fs::copy` to get the progress. that means that when the progress bar is used the copy process might be a bit slower. - Progress bar for symbolic links TBD: Since symbolic links are usually very light I think is not worth it to duplicate the function `copy_symlink` just to add a progress bar that will be so fast to the point is not needed, but.. for consistency purposes we might need to added it, In that case I would have to pass the variable `progress` by parameter (to not duplicate code unnecessary). If I do that i would have to pass the `progress` var to every function to respect `copy_impl: impl Fn(PathBuf, PathBuf, Span)`. Please let me know if this is not clear :p --------- Co-authored-by: Reilly Wood <reilly.wood@icloud.com>
2023-02-22 19:57:38 +00:00
copy_files_using_glob_two_parents_up_using_multiple_dots_imp(false);
copy_files_using_glob_two_parents_up_using_multiple_dots_imp(true);
}
fn copy_files_using_glob_two_parents_up_using_multiple_dots_imp(progress: bool) {
Playground::setup("cp_test_9", |dirs, sandbox| {
sandbox.within("foo").within("bar").with_files(vec![
EmptyFile("jtjson"),
EmptyFile("andres.xml"),
EmptyFile("yehuda.yaml"),
EmptyFile("kevin.txt"),
EmptyFile("many_more.ppl"),
]);
`cp` progress bar implementation (#8012) # NOTE Clean duplicate of #7825 Sorry about all the mess guys... I got confuse with GitHub and and ended up mankind that mess. This the same code I just cleaned the commits. # Description Progress bar implementation for the `cp` command. Now if the flag `-p` or `--progress` is set, then the user will be able to see the progress of the file or files being copy ![progressbar_cp01](https://user-images.githubusercontent.com/38369407/213899494-0f6a4aa9-ee82-48c3-a1f1-1816f3fc1d9c.jpg) ![progressbar_cp02](https://user-images.githubusercontent.com/38369407/213899497-2f9e6e8c-fdd9-400b-bd8d-c59899ae0368.jpg) # User-Facing Changes A new flag (`--progress` `-p`) was added to the `cp` command Examples: ```nu cp -p test_file.txt test_folder_1\ cp -r -p test_folder\* test_folder_1\ cp -r -p -i test_folder\* test_folder_1\ ``` ## Notes - The progress bar uses `std::io::{Read, Write}` instead of `std::fs::copy` to get the progress. that means that when the progress bar is used the copy process might be a bit slower. - Progress bar for symbolic links TBD: Since symbolic links are usually very light I think is not worth it to duplicate the function `copy_symlink` just to add a progress bar that will be so fast to the point is not needed, but.. for consistency purposes we might need to added it, In that case I would have to pass the variable `progress` by parameter (to not duplicate code unnecessary). If I do that i would have to pass the `progress` var to every function to respect `copy_impl: impl Fn(PathBuf, PathBuf, Span)`. Please let me know if this is not clear :p --------- Co-authored-by: Reilly Wood <reilly.wood@icloud.com>
2023-02-22 19:57:38 +00:00
let progress_flag = if progress { "-p" } else { "" };
nu!(
cwd: dirs.test().join("foo/bar"),
`cp` progress bar implementation (#8012) # NOTE Clean duplicate of #7825 Sorry about all the mess guys... I got confuse with GitHub and and ended up mankind that mess. This the same code I just cleaned the commits. # Description Progress bar implementation for the `cp` command. Now if the flag `-p` or `--progress` is set, then the user will be able to see the progress of the file or files being copy ![progressbar_cp01](https://user-images.githubusercontent.com/38369407/213899494-0f6a4aa9-ee82-48c3-a1f1-1816f3fc1d9c.jpg) ![progressbar_cp02](https://user-images.githubusercontent.com/38369407/213899497-2f9e6e8c-fdd9-400b-bd8d-c59899ae0368.jpg) # User-Facing Changes A new flag (`--progress` `-p`) was added to the `cp` command Examples: ```nu cp -p test_file.txt test_folder_1\ cp -r -p test_folder\* test_folder_1\ cp -r -p -i test_folder\* test_folder_1\ ``` ## Notes - The progress bar uses `std::io::{Read, Write}` instead of `std::fs::copy` to get the progress. that means that when the progress bar is used the copy process might be a bit slower. - Progress bar for symbolic links TBD: Since symbolic links are usually very light I think is not worth it to duplicate the function `copy_symlink` just to add a progress bar that will be so fast to the point is not needed, but.. for consistency purposes we might need to added it, In that case I would have to pass the variable `progress` by parameter (to not duplicate code unnecessary). If I do that i would have to pass the `progress` var to every function to respect `copy_impl: impl Fn(PathBuf, PathBuf, Span)`. Please let me know if this is not clear :p --------- Co-authored-by: Reilly Wood <reilly.wood@icloud.com>
2023-02-22 19:57:38 +00:00
" cp {} * ...",
progress_flag,
);
assert!(files_exist_at(
vec![
"yehuda.yaml",
"jtjson",
"andres.xml",
"kevin.txt",
"many_more.ppl",
],
dirs.test()
));
})
}
#[test]
fn copy_file_and_dir_from_two_parents_up_using_multiple_dots_to_current_dir_recursive() {
`cp` progress bar implementation (#8012) # NOTE Clean duplicate of #7825 Sorry about all the mess guys... I got confuse with GitHub and and ended up mankind that mess. This the same code I just cleaned the commits. # Description Progress bar implementation for the `cp` command. Now if the flag `-p` or `--progress` is set, then the user will be able to see the progress of the file or files being copy ![progressbar_cp01](https://user-images.githubusercontent.com/38369407/213899494-0f6a4aa9-ee82-48c3-a1f1-1816f3fc1d9c.jpg) ![progressbar_cp02](https://user-images.githubusercontent.com/38369407/213899497-2f9e6e8c-fdd9-400b-bd8d-c59899ae0368.jpg) # User-Facing Changes A new flag (`--progress` `-p`) was added to the `cp` command Examples: ```nu cp -p test_file.txt test_folder_1\ cp -r -p test_folder\* test_folder_1\ cp -r -p -i test_folder\* test_folder_1\ ``` ## Notes - The progress bar uses `std::io::{Read, Write}` instead of `std::fs::copy` to get the progress. that means that when the progress bar is used the copy process might be a bit slower. - Progress bar for symbolic links TBD: Since symbolic links are usually very light I think is not worth it to duplicate the function `copy_symlink` just to add a progress bar that will be so fast to the point is not needed, but.. for consistency purposes we might need to added it, In that case I would have to pass the variable `progress` by parameter (to not duplicate code unnecessary). If I do that i would have to pass the `progress` var to every function to respect `copy_impl: impl Fn(PathBuf, PathBuf, Span)`. Please let me know if this is not clear :p --------- Co-authored-by: Reilly Wood <reilly.wood@icloud.com>
2023-02-22 19:57:38 +00:00
copy_file_and_dir_from_two_parents_up_using_multiple_dots_to_current_dir_recursive_impl(false);
copy_file_and_dir_from_two_parents_up_using_multiple_dots_to_current_dir_recursive_impl(true);
}
fn copy_file_and_dir_from_two_parents_up_using_multiple_dots_to_current_dir_recursive_impl(
progress: bool,
) {
Playground::setup("cp_test_10", |dirs, sandbox| {
sandbox.with_files(vec![EmptyFile("hello_there")]);
sandbox.mkdir("hello_again");
sandbox.within("foo").mkdir("bar");
`cp` progress bar implementation (#8012) # NOTE Clean duplicate of #7825 Sorry about all the mess guys... I got confuse with GitHub and and ended up mankind that mess. This the same code I just cleaned the commits. # Description Progress bar implementation for the `cp` command. Now if the flag `-p` or `--progress` is set, then the user will be able to see the progress of the file or files being copy ![progressbar_cp01](https://user-images.githubusercontent.com/38369407/213899494-0f6a4aa9-ee82-48c3-a1f1-1816f3fc1d9c.jpg) ![progressbar_cp02](https://user-images.githubusercontent.com/38369407/213899497-2f9e6e8c-fdd9-400b-bd8d-c59899ae0368.jpg) # User-Facing Changes A new flag (`--progress` `-p`) was added to the `cp` command Examples: ```nu cp -p test_file.txt test_folder_1\ cp -r -p test_folder\* test_folder_1\ cp -r -p -i test_folder\* test_folder_1\ ``` ## Notes - The progress bar uses `std::io::{Read, Write}` instead of `std::fs::copy` to get the progress. that means that when the progress bar is used the copy process might be a bit slower. - Progress bar for symbolic links TBD: Since symbolic links are usually very light I think is not worth it to duplicate the function `copy_symlink` just to add a progress bar that will be so fast to the point is not needed, but.. for consistency purposes we might need to added it, In that case I would have to pass the variable `progress` by parameter (to not duplicate code unnecessary). If I do that i would have to pass the `progress` var to every function to respect `copy_impl: impl Fn(PathBuf, PathBuf, Span)`. Please let me know if this is not clear :p --------- Co-authored-by: Reilly Wood <reilly.wood@icloud.com>
2023-02-22 19:57:38 +00:00
let progress_flag = if progress { "-p" } else { "" };
nu!(
cwd: dirs.test().join("foo/bar"),
`cp` progress bar implementation (#8012) # NOTE Clean duplicate of #7825 Sorry about all the mess guys... I got confuse with GitHub and and ended up mankind that mess. This the same code I just cleaned the commits. # Description Progress bar implementation for the `cp` command. Now if the flag `-p` or `--progress` is set, then the user will be able to see the progress of the file or files being copy ![progressbar_cp01](https://user-images.githubusercontent.com/38369407/213899494-0f6a4aa9-ee82-48c3-a1f1-1816f3fc1d9c.jpg) ![progressbar_cp02](https://user-images.githubusercontent.com/38369407/213899497-2f9e6e8c-fdd9-400b-bd8d-c59899ae0368.jpg) # User-Facing Changes A new flag (`--progress` `-p`) was added to the `cp` command Examples: ```nu cp -p test_file.txt test_folder_1\ cp -r -p test_folder\* test_folder_1\ cp -r -p -i test_folder\* test_folder_1\ ``` ## Notes - The progress bar uses `std::io::{Read, Write}` instead of `std::fs::copy` to get the progress. that means that when the progress bar is used the copy process might be a bit slower. - Progress bar for symbolic links TBD: Since symbolic links are usually very light I think is not worth it to duplicate the function `copy_symlink` just to add a progress bar that will be so fast to the point is not needed, but.. for consistency purposes we might need to added it, In that case I would have to pass the variable `progress` by parameter (to not duplicate code unnecessary). If I do that i would have to pass the `progress` var to every function to respect `copy_impl: impl Fn(PathBuf, PathBuf, Span)`. Please let me know if this is not clear :p --------- Co-authored-by: Reilly Wood <reilly.wood@icloud.com>
2023-02-22 19:57:38 +00:00
"cp {} -r .../hello* .",
progress_flag
);
let expected = dirs.test().join("foo/bar");
assert!(files_exist_at(vec!["hello_there", "hello_again"], expected));
})
}
#[test]
fn copy_to_non_existing_dir() {
`cp` progress bar implementation (#8012) # NOTE Clean duplicate of #7825 Sorry about all the mess guys... I got confuse with GitHub and and ended up mankind that mess. This the same code I just cleaned the commits. # Description Progress bar implementation for the `cp` command. Now if the flag `-p` or `--progress` is set, then the user will be able to see the progress of the file or files being copy ![progressbar_cp01](https://user-images.githubusercontent.com/38369407/213899494-0f6a4aa9-ee82-48c3-a1f1-1816f3fc1d9c.jpg) ![progressbar_cp02](https://user-images.githubusercontent.com/38369407/213899497-2f9e6e8c-fdd9-400b-bd8d-c59899ae0368.jpg) # User-Facing Changes A new flag (`--progress` `-p`) was added to the `cp` command Examples: ```nu cp -p test_file.txt test_folder_1\ cp -r -p test_folder\* test_folder_1\ cp -r -p -i test_folder\* test_folder_1\ ``` ## Notes - The progress bar uses `std::io::{Read, Write}` instead of `std::fs::copy` to get the progress. that means that when the progress bar is used the copy process might be a bit slower. - Progress bar for symbolic links TBD: Since symbolic links are usually very light I think is not worth it to duplicate the function `copy_symlink` just to add a progress bar that will be so fast to the point is not needed, but.. for consistency purposes we might need to added it, In that case I would have to pass the variable `progress` by parameter (to not duplicate code unnecessary). If I do that i would have to pass the `progress` var to every function to respect `copy_impl: impl Fn(PathBuf, PathBuf, Span)`. Please let me know if this is not clear :p --------- Co-authored-by: Reilly Wood <reilly.wood@icloud.com>
2023-02-22 19:57:38 +00:00
copy_to_non_existing_dir_impl(false);
copy_to_non_existing_dir_impl(true);
}
fn copy_to_non_existing_dir_impl(progress: bool) {
Playground::setup("cp_test_11", |_dirs, sandbox| {
sandbox.with_files(vec![EmptyFile("empty_file")]);
`cp` progress bar implementation (#8012) # NOTE Clean duplicate of #7825 Sorry about all the mess guys... I got confuse with GitHub and and ended up mankind that mess. This the same code I just cleaned the commits. # Description Progress bar implementation for the `cp` command. Now if the flag `-p` or `--progress` is set, then the user will be able to see the progress of the file or files being copy ![progressbar_cp01](https://user-images.githubusercontent.com/38369407/213899494-0f6a4aa9-ee82-48c3-a1f1-1816f3fc1d9c.jpg) ![progressbar_cp02](https://user-images.githubusercontent.com/38369407/213899497-2f9e6e8c-fdd9-400b-bd8d-c59899ae0368.jpg) # User-Facing Changes A new flag (`--progress` `-p`) was added to the `cp` command Examples: ```nu cp -p test_file.txt test_folder_1\ cp -r -p test_folder\* test_folder_1\ cp -r -p -i test_folder\* test_folder_1\ ``` ## Notes - The progress bar uses `std::io::{Read, Write}` instead of `std::fs::copy` to get the progress. that means that when the progress bar is used the copy process might be a bit slower. - Progress bar for symbolic links TBD: Since symbolic links are usually very light I think is not worth it to duplicate the function `copy_symlink` just to add a progress bar that will be so fast to the point is not needed, but.. for consistency purposes we might need to added it, In that case I would have to pass the variable `progress` by parameter (to not duplicate code unnecessary). If I do that i would have to pass the `progress` var to every function to respect `copy_impl: impl Fn(PathBuf, PathBuf, Span)`. Please let me know if this is not clear :p --------- Co-authored-by: Reilly Wood <reilly.wood@icloud.com>
2023-02-22 19:57:38 +00:00
let progress_flag = if progress { "-p" } else { "" };
let actual = nu!(
cwd: sandbox.cwd(),
`cp` progress bar implementation (#8012) # NOTE Clean duplicate of #7825 Sorry about all the mess guys... I got confuse with GitHub and and ended up mankind that mess. This the same code I just cleaned the commits. # Description Progress bar implementation for the `cp` command. Now if the flag `-p` or `--progress` is set, then the user will be able to see the progress of the file or files being copy ![progressbar_cp01](https://user-images.githubusercontent.com/38369407/213899494-0f6a4aa9-ee82-48c3-a1f1-1816f3fc1d9c.jpg) ![progressbar_cp02](https://user-images.githubusercontent.com/38369407/213899497-2f9e6e8c-fdd9-400b-bd8d-c59899ae0368.jpg) # User-Facing Changes A new flag (`--progress` `-p`) was added to the `cp` command Examples: ```nu cp -p test_file.txt test_folder_1\ cp -r -p test_folder\* test_folder_1\ cp -r -p -i test_folder\* test_folder_1\ ``` ## Notes - The progress bar uses `std::io::{Read, Write}` instead of `std::fs::copy` to get the progress. that means that when the progress bar is used the copy process might be a bit slower. - Progress bar for symbolic links TBD: Since symbolic links are usually very light I think is not worth it to duplicate the function `copy_symlink` just to add a progress bar that will be so fast to the point is not needed, but.. for consistency purposes we might need to added it, In that case I would have to pass the variable `progress` by parameter (to not duplicate code unnecessary). If I do that i would have to pass the `progress` var to every function to respect `copy_impl: impl Fn(PathBuf, PathBuf, Span)`. Please let me know if this is not clear :p --------- Co-authored-by: Reilly Wood <reilly.wood@icloud.com>
2023-02-22 19:57:38 +00:00
"cp {} empty_file ~/not_a_dir/",
progress_flag
);
assert!(actual.err.contains("directory not found"));
assert!(actual.err.contains("destination directory does not exist"));
});
}
#[test]
fn copy_dir_contains_symlink_ignored() {
`cp` progress bar implementation (#8012) # NOTE Clean duplicate of #7825 Sorry about all the mess guys... I got confuse with GitHub and and ended up mankind that mess. This the same code I just cleaned the commits. # Description Progress bar implementation for the `cp` command. Now if the flag `-p` or `--progress` is set, then the user will be able to see the progress of the file or files being copy ![progressbar_cp01](https://user-images.githubusercontent.com/38369407/213899494-0f6a4aa9-ee82-48c3-a1f1-1816f3fc1d9c.jpg) ![progressbar_cp02](https://user-images.githubusercontent.com/38369407/213899497-2f9e6e8c-fdd9-400b-bd8d-c59899ae0368.jpg) # User-Facing Changes A new flag (`--progress` `-p`) was added to the `cp` command Examples: ```nu cp -p test_file.txt test_folder_1\ cp -r -p test_folder\* test_folder_1\ cp -r -p -i test_folder\* test_folder_1\ ``` ## Notes - The progress bar uses `std::io::{Read, Write}` instead of `std::fs::copy` to get the progress. that means that when the progress bar is used the copy process might be a bit slower. - Progress bar for symbolic links TBD: Since symbolic links are usually very light I think is not worth it to duplicate the function `copy_symlink` just to add a progress bar that will be so fast to the point is not needed, but.. for consistency purposes we might need to added it, In that case I would have to pass the variable `progress` by parameter (to not duplicate code unnecessary). If I do that i would have to pass the `progress` var to every function to respect `copy_impl: impl Fn(PathBuf, PathBuf, Span)`. Please let me know if this is not clear :p --------- Co-authored-by: Reilly Wood <reilly.wood@icloud.com>
2023-02-22 19:57:38 +00:00
copy_dir_contains_symlink_ignored_impl(false);
copy_dir_contains_symlink_ignored_impl(true);
}
fn copy_dir_contains_symlink_ignored_impl(progress: bool) {
Playground::setup("cp_test_12", |_dirs, sandbox| {
sandbox
.within("tmp_dir")
.with_files(vec![EmptyFile("hello_there"), EmptyFile("good_bye")])
.within("tmp_dir")
.symlink("good_bye", "dangle_symlink");
`cp` progress bar implementation (#8012) # NOTE Clean duplicate of #7825 Sorry about all the mess guys... I got confuse with GitHub and and ended up mankind that mess. This the same code I just cleaned the commits. # Description Progress bar implementation for the `cp` command. Now if the flag `-p` or `--progress` is set, then the user will be able to see the progress of the file or files being copy ![progressbar_cp01](https://user-images.githubusercontent.com/38369407/213899494-0f6a4aa9-ee82-48c3-a1f1-1816f3fc1d9c.jpg) ![progressbar_cp02](https://user-images.githubusercontent.com/38369407/213899497-2f9e6e8c-fdd9-400b-bd8d-c59899ae0368.jpg) # User-Facing Changes A new flag (`--progress` `-p`) was added to the `cp` command Examples: ```nu cp -p test_file.txt test_folder_1\ cp -r -p test_folder\* test_folder_1\ cp -r -p -i test_folder\* test_folder_1\ ``` ## Notes - The progress bar uses `std::io::{Read, Write}` instead of `std::fs::copy` to get the progress. that means that when the progress bar is used the copy process might be a bit slower. - Progress bar for symbolic links TBD: Since symbolic links are usually very light I think is not worth it to duplicate the function `copy_symlink` just to add a progress bar that will be so fast to the point is not needed, but.. for consistency purposes we might need to added it, In that case I would have to pass the variable `progress` by parameter (to not duplicate code unnecessary). If I do that i would have to pass the `progress` var to every function to respect `copy_impl: impl Fn(PathBuf, PathBuf, Span)`. Please let me know if this is not clear :p --------- Co-authored-by: Reilly Wood <reilly.wood@icloud.com>
2023-02-22 19:57:38 +00:00
let progress_flag = if progress { "-p" } else { "" };
// make symbolic link and copy.
nu!(
cwd: sandbox.cwd(),
`cp` progress bar implementation (#8012) # NOTE Clean duplicate of #7825 Sorry about all the mess guys... I got confuse with GitHub and and ended up mankind that mess. This the same code I just cleaned the commits. # Description Progress bar implementation for the `cp` command. Now if the flag `-p` or `--progress` is set, then the user will be able to see the progress of the file or files being copy ![progressbar_cp01](https://user-images.githubusercontent.com/38369407/213899494-0f6a4aa9-ee82-48c3-a1f1-1816f3fc1d9c.jpg) ![progressbar_cp02](https://user-images.githubusercontent.com/38369407/213899497-2f9e6e8c-fdd9-400b-bd8d-c59899ae0368.jpg) # User-Facing Changes A new flag (`--progress` `-p`) was added to the `cp` command Examples: ```nu cp -p test_file.txt test_folder_1\ cp -r -p test_folder\* test_folder_1\ cp -r -p -i test_folder\* test_folder_1\ ``` ## Notes - The progress bar uses `std::io::{Read, Write}` instead of `std::fs::copy` to get the progress. that means that when the progress bar is used the copy process might be a bit slower. - Progress bar for symbolic links TBD: Since symbolic links are usually very light I think is not worth it to duplicate the function `copy_symlink` just to add a progress bar that will be so fast to the point is not needed, but.. for consistency purposes we might need to added it, In that case I would have to pass the variable `progress` by parameter (to not duplicate code unnecessary). If I do that i would have to pass the `progress` var to every function to respect `copy_impl: impl Fn(PathBuf, PathBuf, Span)`. Please let me know if this is not clear :p --------- Co-authored-by: Reilly Wood <reilly.wood@icloud.com>
2023-02-22 19:57:38 +00:00
"rm {} tmp_dir/good_bye; cp -r tmp_dir tmp_dir_2",
progress_flag
);
// check hello_there exists inside `tmp_dir_2`, and `dangle_symlink` don't exists inside `tmp_dir_2`.
let expected = sandbox.cwd().join("tmp_dir_2");
assert!(files_exist_at(vec!["hello_there"], expected.clone()));
let path = expected.join("dangle_symlink");
assert!(!path.exists() && !path.is_symlink());
});
}
#[test]
fn copy_dir_contains_symlink() {
`cp` progress bar implementation (#8012) # NOTE Clean duplicate of #7825 Sorry about all the mess guys... I got confuse with GitHub and and ended up mankind that mess. This the same code I just cleaned the commits. # Description Progress bar implementation for the `cp` command. Now if the flag `-p` or `--progress` is set, then the user will be able to see the progress of the file or files being copy ![progressbar_cp01](https://user-images.githubusercontent.com/38369407/213899494-0f6a4aa9-ee82-48c3-a1f1-1816f3fc1d9c.jpg) ![progressbar_cp02](https://user-images.githubusercontent.com/38369407/213899497-2f9e6e8c-fdd9-400b-bd8d-c59899ae0368.jpg) # User-Facing Changes A new flag (`--progress` `-p`) was added to the `cp` command Examples: ```nu cp -p test_file.txt test_folder_1\ cp -r -p test_folder\* test_folder_1\ cp -r -p -i test_folder\* test_folder_1\ ``` ## Notes - The progress bar uses `std::io::{Read, Write}` instead of `std::fs::copy` to get the progress. that means that when the progress bar is used the copy process might be a bit slower. - Progress bar for symbolic links TBD: Since symbolic links are usually very light I think is not worth it to duplicate the function `copy_symlink` just to add a progress bar that will be so fast to the point is not needed, but.. for consistency purposes we might need to added it, In that case I would have to pass the variable `progress` by parameter (to not duplicate code unnecessary). If I do that i would have to pass the `progress` var to every function to respect `copy_impl: impl Fn(PathBuf, PathBuf, Span)`. Please let me know if this is not clear :p --------- Co-authored-by: Reilly Wood <reilly.wood@icloud.com>
2023-02-22 19:57:38 +00:00
copy_dir_contains_symlink_impl(false);
copy_dir_contains_symlink_impl(true);
}
fn copy_dir_contains_symlink_impl(progress: bool) {
Playground::setup("cp_test_13", |_dirs, sandbox| {
sandbox
.within("tmp_dir")
.with_files(vec![EmptyFile("hello_there"), EmptyFile("good_bye")])
.within("tmp_dir")
.symlink("good_bye", "dangle_symlink");
`cp` progress bar implementation (#8012) # NOTE Clean duplicate of #7825 Sorry about all the mess guys... I got confuse with GitHub and and ended up mankind that mess. This the same code I just cleaned the commits. # Description Progress bar implementation for the `cp` command. Now if the flag `-p` or `--progress` is set, then the user will be able to see the progress of the file or files being copy ![progressbar_cp01](https://user-images.githubusercontent.com/38369407/213899494-0f6a4aa9-ee82-48c3-a1f1-1816f3fc1d9c.jpg) ![progressbar_cp02](https://user-images.githubusercontent.com/38369407/213899497-2f9e6e8c-fdd9-400b-bd8d-c59899ae0368.jpg) # User-Facing Changes A new flag (`--progress` `-p`) was added to the `cp` command Examples: ```nu cp -p test_file.txt test_folder_1\ cp -r -p test_folder\* test_folder_1\ cp -r -p -i test_folder\* test_folder_1\ ``` ## Notes - The progress bar uses `std::io::{Read, Write}` instead of `std::fs::copy` to get the progress. that means that when the progress bar is used the copy process might be a bit slower. - Progress bar for symbolic links TBD: Since symbolic links are usually very light I think is not worth it to duplicate the function `copy_symlink` just to add a progress bar that will be so fast to the point is not needed, but.. for consistency purposes we might need to added it, In that case I would have to pass the variable `progress` by parameter (to not duplicate code unnecessary). If I do that i would have to pass the `progress` var to every function to respect `copy_impl: impl Fn(PathBuf, PathBuf, Span)`. Please let me know if this is not clear :p --------- Co-authored-by: Reilly Wood <reilly.wood@icloud.com>
2023-02-22 19:57:38 +00:00
let progress_flag = if progress { "-p" } else { "" };
// make symbolic link and copy.
nu!(
cwd: sandbox.cwd(),
`cp` progress bar implementation (#8012) # NOTE Clean duplicate of #7825 Sorry about all the mess guys... I got confuse with GitHub and and ended up mankind that mess. This the same code I just cleaned the commits. # Description Progress bar implementation for the `cp` command. Now if the flag `-p` or `--progress` is set, then the user will be able to see the progress of the file or files being copy ![progressbar_cp01](https://user-images.githubusercontent.com/38369407/213899494-0f6a4aa9-ee82-48c3-a1f1-1816f3fc1d9c.jpg) ![progressbar_cp02](https://user-images.githubusercontent.com/38369407/213899497-2f9e6e8c-fdd9-400b-bd8d-c59899ae0368.jpg) # User-Facing Changes A new flag (`--progress` `-p`) was added to the `cp` command Examples: ```nu cp -p test_file.txt test_folder_1\ cp -r -p test_folder\* test_folder_1\ cp -r -p -i test_folder\* test_folder_1\ ``` ## Notes - The progress bar uses `std::io::{Read, Write}` instead of `std::fs::copy` to get the progress. that means that when the progress bar is used the copy process might be a bit slower. - Progress bar for symbolic links TBD: Since symbolic links are usually very light I think is not worth it to duplicate the function `copy_symlink` just to add a progress bar that will be so fast to the point is not needed, but.. for consistency purposes we might need to added it, In that case I would have to pass the variable `progress` by parameter (to not duplicate code unnecessary). If I do that i would have to pass the `progress` var to every function to respect `copy_impl: impl Fn(PathBuf, PathBuf, Span)`. Please let me know if this is not clear :p --------- Co-authored-by: Reilly Wood <reilly.wood@icloud.com>
2023-02-22 19:57:38 +00:00
"rm tmp_dir/good_bye; cp {} -r -n tmp_dir tmp_dir_2",
progress_flag
);
// check hello_there exists inside `tmp_dir_2`, and `dangle_symlink` also exists inside `tmp_dir_2`.
let expected = sandbox.cwd().join("tmp_dir_2");
assert!(files_exist_at(vec!["hello_there"], expected.clone()));
let path = expected.join("dangle_symlink");
assert!(path.is_symlink());
});
}
#[test]
fn copy_dir_symlink_file_body_not_changed() {
`cp` progress bar implementation (#8012) # NOTE Clean duplicate of #7825 Sorry about all the mess guys... I got confuse with GitHub and and ended up mankind that mess. This the same code I just cleaned the commits. # Description Progress bar implementation for the `cp` command. Now if the flag `-p` or `--progress` is set, then the user will be able to see the progress of the file or files being copy ![progressbar_cp01](https://user-images.githubusercontent.com/38369407/213899494-0f6a4aa9-ee82-48c3-a1f1-1816f3fc1d9c.jpg) ![progressbar_cp02](https://user-images.githubusercontent.com/38369407/213899497-2f9e6e8c-fdd9-400b-bd8d-c59899ae0368.jpg) # User-Facing Changes A new flag (`--progress` `-p`) was added to the `cp` command Examples: ```nu cp -p test_file.txt test_folder_1\ cp -r -p test_folder\* test_folder_1\ cp -r -p -i test_folder\* test_folder_1\ ``` ## Notes - The progress bar uses `std::io::{Read, Write}` instead of `std::fs::copy` to get the progress. that means that when the progress bar is used the copy process might be a bit slower. - Progress bar for symbolic links TBD: Since symbolic links are usually very light I think is not worth it to duplicate the function `copy_symlink` just to add a progress bar that will be so fast to the point is not needed, but.. for consistency purposes we might need to added it, In that case I would have to pass the variable `progress` by parameter (to not duplicate code unnecessary). If I do that i would have to pass the `progress` var to every function to respect `copy_impl: impl Fn(PathBuf, PathBuf, Span)`. Please let me know if this is not clear :p --------- Co-authored-by: Reilly Wood <reilly.wood@icloud.com>
2023-02-22 19:57:38 +00:00
copy_dir_symlink_file_body_not_changed_impl(false);
copy_dir_symlink_file_body_not_changed_impl(true);
}
fn copy_dir_symlink_file_body_not_changed_impl(progress: bool) {
Playground::setup("cp_test_14", |_dirs, sandbox| {
sandbox
.within("tmp_dir")
.with_files(vec![EmptyFile("hello_there"), EmptyFile("good_bye")])
.within("tmp_dir")
.symlink("good_bye", "dangle_symlink");
`cp` progress bar implementation (#8012) # NOTE Clean duplicate of #7825 Sorry about all the mess guys... I got confuse with GitHub and and ended up mankind that mess. This the same code I just cleaned the commits. # Description Progress bar implementation for the `cp` command. Now if the flag `-p` or `--progress` is set, then the user will be able to see the progress of the file or files being copy ![progressbar_cp01](https://user-images.githubusercontent.com/38369407/213899494-0f6a4aa9-ee82-48c3-a1f1-1816f3fc1d9c.jpg) ![progressbar_cp02](https://user-images.githubusercontent.com/38369407/213899497-2f9e6e8c-fdd9-400b-bd8d-c59899ae0368.jpg) # User-Facing Changes A new flag (`--progress` `-p`) was added to the `cp` command Examples: ```nu cp -p test_file.txt test_folder_1\ cp -r -p test_folder\* test_folder_1\ cp -r -p -i test_folder\* test_folder_1\ ``` ## Notes - The progress bar uses `std::io::{Read, Write}` instead of `std::fs::copy` to get the progress. that means that when the progress bar is used the copy process might be a bit slower. - Progress bar for symbolic links TBD: Since symbolic links are usually very light I think is not worth it to duplicate the function `copy_symlink` just to add a progress bar that will be so fast to the point is not needed, but.. for consistency purposes we might need to added it, In that case I would have to pass the variable `progress` by parameter (to not duplicate code unnecessary). If I do that i would have to pass the `progress` var to every function to respect `copy_impl: impl Fn(PathBuf, PathBuf, Span)`. Please let me know if this is not clear :p --------- Co-authored-by: Reilly Wood <reilly.wood@icloud.com>
2023-02-22 19:57:38 +00:00
let progress_flag = if progress { "-p" } else { "" };
// make symbolic link and copy.
nu!(
cwd: sandbox.cwd(),
`cp` progress bar implementation (#8012) # NOTE Clean duplicate of #7825 Sorry about all the mess guys... I got confuse with GitHub and and ended up mankind that mess. This the same code I just cleaned the commits. # Description Progress bar implementation for the `cp` command. Now if the flag `-p` or `--progress` is set, then the user will be able to see the progress of the file or files being copy ![progressbar_cp01](https://user-images.githubusercontent.com/38369407/213899494-0f6a4aa9-ee82-48c3-a1f1-1816f3fc1d9c.jpg) ![progressbar_cp02](https://user-images.githubusercontent.com/38369407/213899497-2f9e6e8c-fdd9-400b-bd8d-c59899ae0368.jpg) # User-Facing Changes A new flag (`--progress` `-p`) was added to the `cp` command Examples: ```nu cp -p test_file.txt test_folder_1\ cp -r -p test_folder\* test_folder_1\ cp -r -p -i test_folder\* test_folder_1\ ``` ## Notes - The progress bar uses `std::io::{Read, Write}` instead of `std::fs::copy` to get the progress. that means that when the progress bar is used the copy process might be a bit slower. - Progress bar for symbolic links TBD: Since symbolic links are usually very light I think is not worth it to duplicate the function `copy_symlink` just to add a progress bar that will be so fast to the point is not needed, but.. for consistency purposes we might need to added it, In that case I would have to pass the variable `progress` by parameter (to not duplicate code unnecessary). If I do that i would have to pass the `progress` var to every function to respect `copy_impl: impl Fn(PathBuf, PathBuf, Span)`. Please let me know if this is not clear :p --------- Co-authored-by: Reilly Wood <reilly.wood@icloud.com>
2023-02-22 19:57:38 +00:00
"rm tmp_dir/good_bye; cp {} -r -n tmp_dir tmp_dir_2; rm -r tmp_dir; cp {} -r -n tmp_dir_2 tmp_dir; echo hello_data | save tmp_dir/good_bye",
progress_flag,
progress_flag,
);
// check dangle_symlink in tmp_dir is no longer dangling.
let expected_file = sandbox.cwd().join("tmp_dir").join("dangle_symlink");
let actual = file_contents(expected_file);
assert!(actual.contains("hello_data"));
});
}
2022-05-31 23:24:33 +00:00
#[test]
fn copy_identical_file() {
`cp` progress bar implementation (#8012) # NOTE Clean duplicate of #7825 Sorry about all the mess guys... I got confuse with GitHub and and ended up mankind that mess. This the same code I just cleaned the commits. # Description Progress bar implementation for the `cp` command. Now if the flag `-p` or `--progress` is set, then the user will be able to see the progress of the file or files being copy ![progressbar_cp01](https://user-images.githubusercontent.com/38369407/213899494-0f6a4aa9-ee82-48c3-a1f1-1816f3fc1d9c.jpg) ![progressbar_cp02](https://user-images.githubusercontent.com/38369407/213899497-2f9e6e8c-fdd9-400b-bd8d-c59899ae0368.jpg) # User-Facing Changes A new flag (`--progress` `-p`) was added to the `cp` command Examples: ```nu cp -p test_file.txt test_folder_1\ cp -r -p test_folder\* test_folder_1\ cp -r -p -i test_folder\* test_folder_1\ ``` ## Notes - The progress bar uses `std::io::{Read, Write}` instead of `std::fs::copy` to get the progress. that means that when the progress bar is used the copy process might be a bit slower. - Progress bar for symbolic links TBD: Since symbolic links are usually very light I think is not worth it to duplicate the function `copy_symlink` just to add a progress bar that will be so fast to the point is not needed, but.. for consistency purposes we might need to added it, In that case I would have to pass the variable `progress` by parameter (to not duplicate code unnecessary). If I do that i would have to pass the `progress` var to every function to respect `copy_impl: impl Fn(PathBuf, PathBuf, Span)`. Please let me know if this is not clear :p --------- Co-authored-by: Reilly Wood <reilly.wood@icloud.com>
2023-02-22 19:57:38 +00:00
copy_identical_file_impl(false);
copy_identical_file_impl(true);
}
fn copy_identical_file_impl(progress: bool) {
2022-05-31 23:24:33 +00:00
Playground::setup("cp_test_15", |_dirs, sandbox| {
sandbox.with_files(vec![EmptyFile("same.txt")]);
`cp` progress bar implementation (#8012) # NOTE Clean duplicate of #7825 Sorry about all the mess guys... I got confuse with GitHub and and ended up mankind that mess. This the same code I just cleaned the commits. # Description Progress bar implementation for the `cp` command. Now if the flag `-p` or `--progress` is set, then the user will be able to see the progress of the file or files being copy ![progressbar_cp01](https://user-images.githubusercontent.com/38369407/213899494-0f6a4aa9-ee82-48c3-a1f1-1816f3fc1d9c.jpg) ![progressbar_cp02](https://user-images.githubusercontent.com/38369407/213899497-2f9e6e8c-fdd9-400b-bd8d-c59899ae0368.jpg) # User-Facing Changes A new flag (`--progress` `-p`) was added to the `cp` command Examples: ```nu cp -p test_file.txt test_folder_1\ cp -r -p test_folder\* test_folder_1\ cp -r -p -i test_folder\* test_folder_1\ ``` ## Notes - The progress bar uses `std::io::{Read, Write}` instead of `std::fs::copy` to get the progress. that means that when the progress bar is used the copy process might be a bit slower. - Progress bar for symbolic links TBD: Since symbolic links are usually very light I think is not worth it to duplicate the function `copy_symlink` just to add a progress bar that will be so fast to the point is not needed, but.. for consistency purposes we might need to added it, In that case I would have to pass the variable `progress` by parameter (to not duplicate code unnecessary). If I do that i would have to pass the `progress` var to every function to respect `copy_impl: impl Fn(PathBuf, PathBuf, Span)`. Please let me know if this is not clear :p --------- Co-authored-by: Reilly Wood <reilly.wood@icloud.com>
2023-02-22 19:57:38 +00:00
let progress_flag = if progress { "-p" } else { "" };
2022-05-31 23:24:33 +00:00
let actual = nu!(
cwd: sandbox.cwd(),
`cp` progress bar implementation (#8012) # NOTE Clean duplicate of #7825 Sorry about all the mess guys... I got confuse with GitHub and and ended up mankind that mess. This the same code I just cleaned the commits. # Description Progress bar implementation for the `cp` command. Now if the flag `-p` or `--progress` is set, then the user will be able to see the progress of the file or files being copy ![progressbar_cp01](https://user-images.githubusercontent.com/38369407/213899494-0f6a4aa9-ee82-48c3-a1f1-1816f3fc1d9c.jpg) ![progressbar_cp02](https://user-images.githubusercontent.com/38369407/213899497-2f9e6e8c-fdd9-400b-bd8d-c59899ae0368.jpg) # User-Facing Changes A new flag (`--progress` `-p`) was added to the `cp` command Examples: ```nu cp -p test_file.txt test_folder_1\ cp -r -p test_folder\* test_folder_1\ cp -r -p -i test_folder\* test_folder_1\ ``` ## Notes - The progress bar uses `std::io::{Read, Write}` instead of `std::fs::copy` to get the progress. that means that when the progress bar is used the copy process might be a bit slower. - Progress bar for symbolic links TBD: Since symbolic links are usually very light I think is not worth it to duplicate the function `copy_symlink` just to add a progress bar that will be so fast to the point is not needed, but.. for consistency purposes we might need to added it, In that case I would have to pass the variable `progress` by parameter (to not duplicate code unnecessary). If I do that i would have to pass the `progress` var to every function to respect `copy_impl: impl Fn(PathBuf, PathBuf, Span)`. Please let me know if this is not clear :p --------- Co-authored-by: Reilly Wood <reilly.wood@icloud.com>
2023-02-22 19:57:38 +00:00
"cp {} same.txt same.txt",
progress_flag,
2022-05-31 23:24:33 +00:00
);
assert!(actual.err.contains("Copy aborted"));
});
}
#[test]
fn copy_ignores_ansi() {
`cp` progress bar implementation (#8012) # NOTE Clean duplicate of #7825 Sorry about all the mess guys... I got confuse with GitHub and and ended up mankind that mess. This the same code I just cleaned the commits. # Description Progress bar implementation for the `cp` command. Now if the flag `-p` or `--progress` is set, then the user will be able to see the progress of the file or files being copy ![progressbar_cp01](https://user-images.githubusercontent.com/38369407/213899494-0f6a4aa9-ee82-48c3-a1f1-1816f3fc1d9c.jpg) ![progressbar_cp02](https://user-images.githubusercontent.com/38369407/213899497-2f9e6e8c-fdd9-400b-bd8d-c59899ae0368.jpg) # User-Facing Changes A new flag (`--progress` `-p`) was added to the `cp` command Examples: ```nu cp -p test_file.txt test_folder_1\ cp -r -p test_folder\* test_folder_1\ cp -r -p -i test_folder\* test_folder_1\ ``` ## Notes - The progress bar uses `std::io::{Read, Write}` instead of `std::fs::copy` to get the progress. that means that when the progress bar is used the copy process might be a bit slower. - Progress bar for symbolic links TBD: Since symbolic links are usually very light I think is not worth it to duplicate the function `copy_symlink` just to add a progress bar that will be so fast to the point is not needed, but.. for consistency purposes we might need to added it, In that case I would have to pass the variable `progress` by parameter (to not duplicate code unnecessary). If I do that i would have to pass the `progress` var to every function to respect `copy_impl: impl Fn(PathBuf, PathBuf, Span)`. Please let me know if this is not clear :p --------- Co-authored-by: Reilly Wood <reilly.wood@icloud.com>
2023-02-22 19:57:38 +00:00
copy_ignores_ansi_impl(false);
copy_ignores_ansi_impl(true);
}
fn copy_ignores_ansi_impl(progress: bool) {
Playground::setup("cp_test_16", |_dirs, sandbox| {
sandbox.with_files(vec![EmptyFile("test.txt")]);
`cp` progress bar implementation (#8012) # NOTE Clean duplicate of #7825 Sorry about all the mess guys... I got confuse with GitHub and and ended up mankind that mess. This the same code I just cleaned the commits. # Description Progress bar implementation for the `cp` command. Now if the flag `-p` or `--progress` is set, then the user will be able to see the progress of the file or files being copy ![progressbar_cp01](https://user-images.githubusercontent.com/38369407/213899494-0f6a4aa9-ee82-48c3-a1f1-1816f3fc1d9c.jpg) ![progressbar_cp02](https://user-images.githubusercontent.com/38369407/213899497-2f9e6e8c-fdd9-400b-bd8d-c59899ae0368.jpg) # User-Facing Changes A new flag (`--progress` `-p`) was added to the `cp` command Examples: ```nu cp -p test_file.txt test_folder_1\ cp -r -p test_folder\* test_folder_1\ cp -r -p -i test_folder\* test_folder_1\ ``` ## Notes - The progress bar uses `std::io::{Read, Write}` instead of `std::fs::copy` to get the progress. that means that when the progress bar is used the copy process might be a bit slower. - Progress bar for symbolic links TBD: Since symbolic links are usually very light I think is not worth it to duplicate the function `copy_symlink` just to add a progress bar that will be so fast to the point is not needed, but.. for consistency purposes we might need to added it, In that case I would have to pass the variable `progress` by parameter (to not duplicate code unnecessary). If I do that i would have to pass the `progress` var to every function to respect `copy_impl: impl Fn(PathBuf, PathBuf, Span)`. Please let me know if this is not clear :p --------- Co-authored-by: Reilly Wood <reilly.wood@icloud.com>
2023-02-22 19:57:38 +00:00
let progress_flag = if progress { "-p" } else { "" };
let actual = nu!(
cwd: sandbox.cwd(),
`cp` progress bar implementation (#8012) # NOTE Clean duplicate of #7825 Sorry about all the mess guys... I got confuse with GitHub and and ended up mankind that mess. This the same code I just cleaned the commits. # Description Progress bar implementation for the `cp` command. Now if the flag `-p` or `--progress` is set, then the user will be able to see the progress of the file or files being copy ![progressbar_cp01](https://user-images.githubusercontent.com/38369407/213899494-0f6a4aa9-ee82-48c3-a1f1-1816f3fc1d9c.jpg) ![progressbar_cp02](https://user-images.githubusercontent.com/38369407/213899497-2f9e6e8c-fdd9-400b-bd8d-c59899ae0368.jpg) # User-Facing Changes A new flag (`--progress` `-p`) was added to the `cp` command Examples: ```nu cp -p test_file.txt test_folder_1\ cp -r -p test_folder\* test_folder_1\ cp -r -p -i test_folder\* test_folder_1\ ``` ## Notes - The progress bar uses `std::io::{Read, Write}` instead of `std::fs::copy` to get the progress. that means that when the progress bar is used the copy process might be a bit slower. - Progress bar for symbolic links TBD: Since symbolic links are usually very light I think is not worth it to duplicate the function `copy_symlink` just to add a progress bar that will be so fast to the point is not needed, but.. for consistency purposes we might need to added it, In that case I would have to pass the variable `progress` by parameter (to not duplicate code unnecessary). If I do that i would have to pass the `progress` var to every function to respect `copy_impl: impl Fn(PathBuf, PathBuf, Span)`. Please let me know if this is not clear :p --------- Co-authored-by: Reilly Wood <reilly.wood@icloud.com>
2023-02-22 19:57:38 +00:00
"ls | find test | get name | cp {} $in.0 success.txt; ls | find success | get name | ansi strip | get 0",
progress_flag,
);
assert_eq!(actual.out, "success.txt");
});
}
#[test]
fn copy_file_not_exists_dst() {
`cp` progress bar implementation (#8012) # NOTE Clean duplicate of #7825 Sorry about all the mess guys... I got confuse with GitHub and and ended up mankind that mess. This the same code I just cleaned the commits. # Description Progress bar implementation for the `cp` command. Now if the flag `-p` or `--progress` is set, then the user will be able to see the progress of the file or files being copy ![progressbar_cp01](https://user-images.githubusercontent.com/38369407/213899494-0f6a4aa9-ee82-48c3-a1f1-1816f3fc1d9c.jpg) ![progressbar_cp02](https://user-images.githubusercontent.com/38369407/213899497-2f9e6e8c-fdd9-400b-bd8d-c59899ae0368.jpg) # User-Facing Changes A new flag (`--progress` `-p`) was added to the `cp` command Examples: ```nu cp -p test_file.txt test_folder_1\ cp -r -p test_folder\* test_folder_1\ cp -r -p -i test_folder\* test_folder_1\ ``` ## Notes - The progress bar uses `std::io::{Read, Write}` instead of `std::fs::copy` to get the progress. that means that when the progress bar is used the copy process might be a bit slower. - Progress bar for symbolic links TBD: Since symbolic links are usually very light I think is not worth it to duplicate the function `copy_symlink` just to add a progress bar that will be so fast to the point is not needed, but.. for consistency purposes we might need to added it, In that case I would have to pass the variable `progress` by parameter (to not duplicate code unnecessary). If I do that i would have to pass the `progress` var to every function to respect `copy_impl: impl Fn(PathBuf, PathBuf, Span)`. Please let me know if this is not clear :p --------- Co-authored-by: Reilly Wood <reilly.wood@icloud.com>
2023-02-22 19:57:38 +00:00
copy_file_not_exists_dst_impl(false);
copy_file_not_exists_dst_impl(true);
}
fn copy_file_not_exists_dst_impl(progress: bool) {
Playground::setup("cp_test_17", |_dirs, sandbox| {
sandbox.with_files(vec![EmptyFile("valid.txt")]);
`cp` progress bar implementation (#8012) # NOTE Clean duplicate of #7825 Sorry about all the mess guys... I got confuse with GitHub and and ended up mankind that mess. This the same code I just cleaned the commits. # Description Progress bar implementation for the `cp` command. Now if the flag `-p` or `--progress` is set, then the user will be able to see the progress of the file or files being copy ![progressbar_cp01](https://user-images.githubusercontent.com/38369407/213899494-0f6a4aa9-ee82-48c3-a1f1-1816f3fc1d9c.jpg) ![progressbar_cp02](https://user-images.githubusercontent.com/38369407/213899497-2f9e6e8c-fdd9-400b-bd8d-c59899ae0368.jpg) # User-Facing Changes A new flag (`--progress` `-p`) was added to the `cp` command Examples: ```nu cp -p test_file.txt test_folder_1\ cp -r -p test_folder\* test_folder_1\ cp -r -p -i test_folder\* test_folder_1\ ``` ## Notes - The progress bar uses `std::io::{Read, Write}` instead of `std::fs::copy` to get the progress. that means that when the progress bar is used the copy process might be a bit slower. - Progress bar for symbolic links TBD: Since symbolic links are usually very light I think is not worth it to duplicate the function `copy_symlink` just to add a progress bar that will be so fast to the point is not needed, but.. for consistency purposes we might need to added it, In that case I would have to pass the variable `progress` by parameter (to not duplicate code unnecessary). If I do that i would have to pass the `progress` var to every function to respect `copy_impl: impl Fn(PathBuf, PathBuf, Span)`. Please let me know if this is not clear :p --------- Co-authored-by: Reilly Wood <reilly.wood@icloud.com>
2023-02-22 19:57:38 +00:00
let progress_flag = if progress { "-p" } else { "" };
let actual = nu!(
cwd: sandbox.cwd(),
`cp` progress bar implementation (#8012) # NOTE Clean duplicate of #7825 Sorry about all the mess guys... I got confuse with GitHub and and ended up mankind that mess. This the same code I just cleaned the commits. # Description Progress bar implementation for the `cp` command. Now if the flag `-p` or `--progress` is set, then the user will be able to see the progress of the file or files being copy ![progressbar_cp01](https://user-images.githubusercontent.com/38369407/213899494-0f6a4aa9-ee82-48c3-a1f1-1816f3fc1d9c.jpg) ![progressbar_cp02](https://user-images.githubusercontent.com/38369407/213899497-2f9e6e8c-fdd9-400b-bd8d-c59899ae0368.jpg) # User-Facing Changes A new flag (`--progress` `-p`) was added to the `cp` command Examples: ```nu cp -p test_file.txt test_folder_1\ cp -r -p test_folder\* test_folder_1\ cp -r -p -i test_folder\* test_folder_1\ ``` ## Notes - The progress bar uses `std::io::{Read, Write}` instead of `std::fs::copy` to get the progress. that means that when the progress bar is used the copy process might be a bit slower. - Progress bar for symbolic links TBD: Since symbolic links are usually very light I think is not worth it to duplicate the function `copy_symlink` just to add a progress bar that will be so fast to the point is not needed, but.. for consistency purposes we might need to added it, In that case I would have to pass the variable `progress` by parameter (to not duplicate code unnecessary). If I do that i would have to pass the `progress` var to every function to respect `copy_impl: impl Fn(PathBuf, PathBuf, Span)`. Please let me know if this is not clear :p --------- Co-authored-by: Reilly Wood <reilly.wood@icloud.com>
2023-02-22 19:57:38 +00:00
"cp {} valid.txt ~/invalid_dir/invalid_dir1",
progress_flag,
);
assert!(
actual.err.contains("invalid_dir1") && actual.err.contains("copying to destination")
);
});
}
#[test]
fn copy_file_with_read_permission() {
`cp` progress bar implementation (#8012) # NOTE Clean duplicate of #7825 Sorry about all the mess guys... I got confuse with GitHub and and ended up mankind that mess. This the same code I just cleaned the commits. # Description Progress bar implementation for the `cp` command. Now if the flag `-p` or `--progress` is set, then the user will be able to see the progress of the file or files being copy ![progressbar_cp01](https://user-images.githubusercontent.com/38369407/213899494-0f6a4aa9-ee82-48c3-a1f1-1816f3fc1d9c.jpg) ![progressbar_cp02](https://user-images.githubusercontent.com/38369407/213899497-2f9e6e8c-fdd9-400b-bd8d-c59899ae0368.jpg) # User-Facing Changes A new flag (`--progress` `-p`) was added to the `cp` command Examples: ```nu cp -p test_file.txt test_folder_1\ cp -r -p test_folder\* test_folder_1\ cp -r -p -i test_folder\* test_folder_1\ ``` ## Notes - The progress bar uses `std::io::{Read, Write}` instead of `std::fs::copy` to get the progress. that means that when the progress bar is used the copy process might be a bit slower. - Progress bar for symbolic links TBD: Since symbolic links are usually very light I think is not worth it to duplicate the function `copy_symlink` just to add a progress bar that will be so fast to the point is not needed, but.. for consistency purposes we might need to added it, In that case I would have to pass the variable `progress` by parameter (to not duplicate code unnecessary). If I do that i would have to pass the `progress` var to every function to respect `copy_impl: impl Fn(PathBuf, PathBuf, Span)`. Please let me know if this is not clear :p --------- Co-authored-by: Reilly Wood <reilly.wood@icloud.com>
2023-02-22 19:57:38 +00:00
copy_file_with_read_permission_impl(false);
copy_file_with_read_permission_impl(true);
}
fn copy_file_with_read_permission_impl(progress: bool) {
Playground::setup("cp_test_18", |_dirs, sandbox| {
sandbox.with_files(vec![
EmptyFile("valid.txt"),
FileWithPermission("invalid_prem.txt", false),
]);
`cp` progress bar implementation (#8012) # NOTE Clean duplicate of #7825 Sorry about all the mess guys... I got confuse with GitHub and and ended up mankind that mess. This the same code I just cleaned the commits. # Description Progress bar implementation for the `cp` command. Now if the flag `-p` or `--progress` is set, then the user will be able to see the progress of the file or files being copy ![progressbar_cp01](https://user-images.githubusercontent.com/38369407/213899494-0f6a4aa9-ee82-48c3-a1f1-1816f3fc1d9c.jpg) ![progressbar_cp02](https://user-images.githubusercontent.com/38369407/213899497-2f9e6e8c-fdd9-400b-bd8d-c59899ae0368.jpg) # User-Facing Changes A new flag (`--progress` `-p`) was added to the `cp` command Examples: ```nu cp -p test_file.txt test_folder_1\ cp -r -p test_folder\* test_folder_1\ cp -r -p -i test_folder\* test_folder_1\ ``` ## Notes - The progress bar uses `std::io::{Read, Write}` instead of `std::fs::copy` to get the progress. that means that when the progress bar is used the copy process might be a bit slower. - Progress bar for symbolic links TBD: Since symbolic links are usually very light I think is not worth it to duplicate the function `copy_symlink` just to add a progress bar that will be so fast to the point is not needed, but.. for consistency purposes we might need to added it, In that case I would have to pass the variable `progress` by parameter (to not duplicate code unnecessary). If I do that i would have to pass the `progress` var to every function to respect `copy_impl: impl Fn(PathBuf, PathBuf, Span)`. Please let me know if this is not clear :p --------- Co-authored-by: Reilly Wood <reilly.wood@icloud.com>
2023-02-22 19:57:38 +00:00
let progress_flag = if progress { "-p" } else { "" };
let actual = nu!(
cwd: sandbox.cwd(),
`cp` progress bar implementation (#8012) # NOTE Clean duplicate of #7825 Sorry about all the mess guys... I got confuse with GitHub and and ended up mankind that mess. This the same code I just cleaned the commits. # Description Progress bar implementation for the `cp` command. Now if the flag `-p` or `--progress` is set, then the user will be able to see the progress of the file or files being copy ![progressbar_cp01](https://user-images.githubusercontent.com/38369407/213899494-0f6a4aa9-ee82-48c3-a1f1-1816f3fc1d9c.jpg) ![progressbar_cp02](https://user-images.githubusercontent.com/38369407/213899497-2f9e6e8c-fdd9-400b-bd8d-c59899ae0368.jpg) # User-Facing Changes A new flag (`--progress` `-p`) was added to the `cp` command Examples: ```nu cp -p test_file.txt test_folder_1\ cp -r -p test_folder\* test_folder_1\ cp -r -p -i test_folder\* test_folder_1\ ``` ## Notes - The progress bar uses `std::io::{Read, Write}` instead of `std::fs::copy` to get the progress. that means that when the progress bar is used the copy process might be a bit slower. - Progress bar for symbolic links TBD: Since symbolic links are usually very light I think is not worth it to duplicate the function `copy_symlink` just to add a progress bar that will be so fast to the point is not needed, but.. for consistency purposes we might need to added it, In that case I would have to pass the variable `progress` by parameter (to not duplicate code unnecessary). If I do that i would have to pass the `progress` var to every function to respect `copy_impl: impl Fn(PathBuf, PathBuf, Span)`. Please let me know if this is not clear :p --------- Co-authored-by: Reilly Wood <reilly.wood@icloud.com>
2023-02-22 19:57:38 +00:00
"cp {} valid.txt invalid_prem.txt",
progress_flag,
);
assert!(
actual.err.contains("invalid_prem.txt")
&& actual.err.contains("copying to destination")
);
});
}
#[test]
fn copy_file_with_update_flag() {
copy_file_with_update_flag_impl(false);
copy_file_with_update_flag_impl(true);
}
fn copy_file_with_update_flag_impl(progress: bool) {
Playground::setup("cp_test_19", |_dirs, sandbox| {
sandbox.with_files(vec![
EmptyFile("valid.txt"),
FileWithContent("newer_valid.txt", "body"),
]);
let progress_flag = if progress { "-p" } else { "" };
let actual = nu!(
cwd: sandbox.cwd(),
"cp {} -u valid.txt newer_valid.txt; open newer_valid.txt",
progress_flag,
);
assert!(actual.out.contains("body"));
// create a file after assert to make sure that newest_valid.txt is newest
std::thread::sleep(std::time::Duration::from_secs(1));
sandbox.with_files(vec![FileWithContent("newest_valid.txt", "newest_body")]);
let actual = nu!(cwd: sandbox.cwd(), "cp {} -u newest_valid.txt valid.txt; open valid.txt", progress_flag);
assert_eq!(actual.out, "newest_body");
// when destination doesn't exist
let actual = nu!(cwd: sandbox.cwd(), "cp {} -u newest_valid.txt des_missing.txt; open des_missing.txt", progress_flag);
assert_eq!(actual.out, "newest_body");
});
}