mirror of
https://github.com/nushell/nushell.git
synced 2025-04-18 02:08:20 +02:00
Fixed mv not throwing error when the source path was invalid (#1351)
* Fixed mv not throwing error when the source path was invalid * Fixed failing test * Fixed another lint error * Fix $PATH conflicts in .gitpod.Dockerfile (#1349) - Use the correct user for gitpod Dockerfile. - Remove unneeded packages (curl, rustc) from gitpod Dockerfile. * Added test to check for the error * Fixed linting error * Fixed mv not moving files on Windows. (#1342) Move files correctly in windows. * Fixed mv not throwing error when the source path was invalid * Fixed failing test * Fixed another lint error * Added test to check for the error * Fixed linting error * Changed error message * Typo and fixed test Co-authored-by: Sean Hellum <seanhellum45@gmail.com>
This commit is contained in:
parent
ed86b1fbe8
commit
643b532537
@ -546,6 +546,13 @@ impl Shell for FilesystemShell {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if sources.is_empty() {
|
||||||
|
return Err(ShellError::labeled_error(
|
||||||
|
"Invalid File or Pattern.",
|
||||||
|
"Invalid File or Pattern",
|
||||||
|
src.tag,
|
||||||
|
));
|
||||||
|
}
|
||||||
let destination_file_name = {
|
let destination_file_name = {
|
||||||
match destination.file_name() {
|
match destination.file_name() {
|
||||||
Some(name) => PathBuf::from(name),
|
Some(name) => PathBuf::from(name),
|
||||||
@ -559,6 +566,14 @@ impl Shell for FilesystemShell {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if sources.is_empty() {
|
||||||
|
return Err(ShellError::labeled_error(
|
||||||
|
"Move aborted. Not a valid destination",
|
||||||
|
"not a valid destination",
|
||||||
|
src.tag,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
if sources.len() == 1 {
|
if sources.len() == 1 {
|
||||||
if let Ok(entry) = &sources[0] {
|
if let Ok(entry) = &sources[0] {
|
||||||
let entry_file_name = match entry.file_name() {
|
let entry_file_name = match entry.file_name() {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use nu_test_support::fs::{files_exist_at, Stub::EmptyFile};
|
use nu_test_support::fs::{files_exist_at, Stub::EmptyFile};
|
||||||
use nu_test_support::nu;
|
|
||||||
use nu_test_support::playground::Playground;
|
use nu_test_support::playground::Playground;
|
||||||
|
use nu_test_support::{nu, nu_error};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn moves_a_file() {
|
fn moves_a_file() {
|
||||||
@ -218,3 +218,15 @@ fn moves_a_directory_with_files() {
|
|||||||
));
|
));
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn errors_if_source_doesnt_exist() {
|
||||||
|
Playground::setup("mv_test_10", |dirs, sandbox| {
|
||||||
|
sandbox.mkdir("test_folder");
|
||||||
|
let actual = nu_error!(
|
||||||
|
cwd: dirs.root(),
|
||||||
|
"mv non-existing-file test_folder/"
|
||||||
|
);
|
||||||
|
assert!(actual.contains("Invalid File or Pattern"));
|
||||||
|
})
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user