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:
George Tsomlektsis 2020-02-07 19:40:48 +02:00 committed by GitHub
parent ed86b1fbe8
commit 643b532537
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 1 deletions

View File

@ -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 = {
match destination.file_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 let Ok(entry) = &sources[0] {
let entry_file_name = match entry.file_name() {

View File

@ -1,6 +1,6 @@
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::{nu, nu_error};
#[test]
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"));
})
}