2022-05-26 17:42:52 +02:00
|
|
|
use nu_test_support::fs::file_contents;
|
2023-02-01 21:48:21 +01:00
|
|
|
use nu_test_support::fs::{
|
|
|
|
files_exist_at, AbsoluteFile,
|
|
|
|
Stub::{EmptyFile, FileWithPermission},
|
|
|
|
};
|
2020-05-07 13:03:43 +02:00
|
|
|
use nu_test_support::nu;
|
2019-12-17 19:54:39 +01:00
|
|
|
use nu_test_support::playground::Playground;
|
2019-08-29 08:31:56 +02:00
|
|
|
use std::path::Path;
|
2019-08-06 09:05:47 +02:00
|
|
|
|
2023-02-22 20:57:38 +01:00
|
|
|
fn get_file_hash<T: std::fmt::Display>(file: T) -> String {
|
|
|
|
nu!("open {} | to text | hash md5", file).out
|
|
|
|
}
|
|
|
|
|
2019-08-06 09:05:47 +02:00
|
|
|
#[test]
|
2019-08-07 16:45:50 +02:00
|
|
|
fn copies_a_file() {
|
2023-02-22 20:57:38 +01:00
|
|
|
copies_a_file_impl(false);
|
|
|
|
copies_a_file_impl(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn copies_a_file_impl(progress: bool) {
|
2019-08-28 19:01:16 +02:00
|
|
|
Playground::setup("cp_test_1", |dirs, _| {
|
2023-02-22 20:57:38 +01: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.
|
|
|
|
let first_hash = get_file_hash(&test_file.display());
|
|
|
|
|
2019-08-28 19:01:16 +02:00
|
|
|
nu!(
|
2019-08-29 08:31:56 +02:00
|
|
|
cwd: dirs.root(),
|
2023-02-22 20:57:38 +01:00
|
|
|
"cp {} `{}` cp_test_1/sample.ini",
|
|
|
|
progress_flag,
|
|
|
|
test_file.display()
|
2019-08-28 19:01:16 +02:00
|
|
|
);
|
|
|
|
|
2019-08-29 08:31:56 +02:00
|
|
|
assert!(dirs.test().join("sample.ini").exists());
|
2023-02-22 20:57:38 +01: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-28 19:01:16 +02:00
|
|
|
});
|
2019-08-06 09:05:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2019-08-07 16:45:50 +02:00
|
|
|
fn copies_the_file_inside_directory_if_path_to_copy_is_directory() {
|
2023-02-22 20:57:38 +01: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) {
|
2019-08-28 19:01:16 +02:00
|
|
|
Playground::setup("cp_test_2", |dirs, _| {
|
|
|
|
let expected_file = AbsoluteFile::new(dirs.test().join("sample.ini"));
|
2023-02-22 20:57:38 +01:00
|
|
|
let progress_flag = if progress { "-p" } else { "" };
|
2019-08-06 09:05:47 +02:00
|
|
|
|
2023-02-22 20:57:38 +01: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());
|
2019-08-28 19:01:16 +02:00
|
|
|
nu!(
|
2019-08-29 08:31:56 +02:00
|
|
|
cwd: dirs.formats(),
|
2023-02-22 20:57:38 +01:00
|
|
|
"cp {} ../formats/sample.ini {}",
|
|
|
|
progress_flag,
|
2019-08-28 19:01:16 +02:00
|
|
|
expected_file.dir()
|
|
|
|
);
|
2019-08-06 09:05:47 +02:00
|
|
|
|
2019-08-29 08:31:56 +02:00
|
|
|
assert!(dirs.test().join("sample.ini").exists());
|
2023-02-22 20:57:38 +01: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-28 19:01:16 +02:00
|
|
|
})
|
2019-08-06 09:05:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2019-08-07 16:45:50 +02:00
|
|
|
fn error_if_attempting_to_copy_a_directory_to_another_directory() {
|
2023-02-22 20:57:38 +01: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) {
|
2019-08-28 19:01:16 +02:00
|
|
|
Playground::setup("cp_test_3", |dirs, _| {
|
2023-02-22 20:57:38 +01:00
|
|
|
let progress_flag = if progress { "-p" } else { "" };
|
|
|
|
|
2020-05-07 13:03:43 +02:00
|
|
|
let actual = nu!(
|
2019-08-29 08:31:56 +02:00
|
|
|
cwd: dirs.formats(),
|
2023-02-22 20:57:38 +01:00
|
|
|
"cp {} ../formats {}",
|
|
|
|
progress_flag,
|
|
|
|
dirs.test().display()
|
2019-08-29 08:31:56 +02:00
|
|
|
);
|
2019-08-06 09:05:47 +02:00
|
|
|
|
2020-05-07 13:03:43 +02:00
|
|
|
assert!(actual.err.contains("../formats"));
|
|
|
|
assert!(actual.err.contains("resolves to a directory (not copied)"));
|
2019-08-28 19:01:16 +02:00
|
|
|
});
|
2019-08-06 09:05:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2019-08-07 16:45:50 +02:00
|
|
|
fn copies_the_directory_inside_directory_if_path_to_copy_is_directory_and_with_recursive_flag() {
|
2023-02-22 20:57:38 +01: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 02:32:42 +02:00
|
|
|
Playground::setup("cp_test_4", |dirs, sandbox| {
|
|
|
|
sandbox
|
2019-08-28 19:01:16 +02:00
|
|
|
.within("originals")
|
|
|
|
.with_files(vec![
|
|
|
|
EmptyFile("yehuda.txt"),
|
|
|
|
EmptyFile("jonathan.txt"),
|
|
|
|
EmptyFile("andres.txt"),
|
|
|
|
])
|
|
|
|
.mkdir("expected");
|
|
|
|
|
|
|
|
let expected_dir = dirs.test().join("expected").join("originals");
|
2023-02-22 20:57:38 +01:00
|
|
|
let progress_flag = if progress { "-p" } else { "" };
|
2019-08-28 19:01:16 +02:00
|
|
|
|
2019-08-29 08:31:56 +02:00
|
|
|
nu!(
|
|
|
|
cwd: dirs.test(),
|
2023-02-22 20:57:38 +01:00
|
|
|
"cp {} originals expected -r",
|
|
|
|
progress_flag
|
2019-08-29 08:31:56 +02:00
|
|
|
);
|
2019-08-28 19:01:16 +02:00
|
|
|
|
2019-08-29 08:31:56 +02:00
|
|
|
assert!(expected_dir.exists());
|
2019-08-28 19:01:16 +02:00
|
|
|
assert!(files_exist_at(
|
|
|
|
vec![
|
|
|
|
Path::new("yehuda.txt"),
|
|
|
|
Path::new("jonathan.txt"),
|
|
|
|
Path::new("andres.txt")
|
|
|
|
],
|
2023-02-22 20:57:38 +01:00
|
|
|
&expected_dir
|
2019-08-28 19:01:16 +02:00
|
|
|
));
|
|
|
|
})
|
2019-08-07 16:45:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn deep_copies_with_recursive_flag() {
|
2023-02-22 20:57:38 +01: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 02:32:42 +02:00
|
|
|
Playground::setup("cp_test_5", |dirs, sandbox| {
|
|
|
|
sandbox
|
2019-08-28 19:01:16 +02:00
|
|
|
.within("originals")
|
|
|
|
.with_files(vec![EmptyFile("manifest.txt")])
|
|
|
|
.within("originals/contributors")
|
|
|
|
.with_files(vec![
|
|
|
|
EmptyFile("yehuda.txt"),
|
|
|
|
EmptyFile("jonathan.txt"),
|
|
|
|
EmptyFile("andres.txt"),
|
|
|
|
])
|
|
|
|
.within("originals/contributors/jonathan")
|
|
|
|
.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");
|
2023-02-22 20:57:38 +01:00
|
|
|
let progress_flag = if progress { "-p" } else { "" };
|
2019-08-28 19:01:16 +02:00
|
|
|
|
|
|
|
let jonathans_expected_copied_dir = expected_dir.join("contributors").join("jonathan");
|
|
|
|
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 08:31:56 +02:00
|
|
|
nu!(
|
2019-09-03 02:49:51 +02:00
|
|
|
cwd: dirs.test(),
|
2023-02-22 20:57:38 +01:00
|
|
|
"cp {} originals expected --recursive",
|
|
|
|
progress_flag
|
2019-08-29 08:31:56 +02:00
|
|
|
);
|
2019-08-28 19:01:16 +02:00
|
|
|
|
2019-08-29 08:31:56 +02:00
|
|
|
assert!(expected_dir.exists());
|
2019-08-28 19:01:16 +02:00
|
|
|
assert!(files_exist_at(
|
|
|
|
vec![Path::new("errors.txt"), Path::new("multishells.txt")],
|
2023-02-22 20:57:38 +01:00
|
|
|
&jonathans_expected_copied_dir
|
2019-08-28 19:01:16 +02:00
|
|
|
));
|
|
|
|
assert!(files_exist_at(
|
|
|
|
vec![Path::new("coverage.txt"), Path::new("commands.txt")],
|
2023-02-22 20:57:38 +01:00
|
|
|
&andres_expected_copied_dir
|
2019-08-28 19:01:16 +02:00
|
|
|
));
|
|
|
|
assert!(files_exist_at(
|
|
|
|
vec![Path::new("defer-evaluation.txt")],
|
2023-02-22 20:57:38 +01:00
|
|
|
&yehudas_expected_copied_dir
|
2019-08-28 19:01:16 +02:00
|
|
|
));
|
|
|
|
})
|
2019-08-07 16:45:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2019-08-09 08:52:48 +02:00
|
|
|
fn copies_using_path_with_wildcard() {
|
2023-02-22 20:57:38 +01:00
|
|
|
copies_using_path_with_wildcard_impl(false);
|
|
|
|
copies_using_path_with_wildcard_impl(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn copies_using_path_with_wildcard_impl(progress: bool) {
|
2019-08-28 19:01:16 +02:00
|
|
|
Playground::setup("cp_test_6", |dirs, _| {
|
2023-02-22 20:57:38 +01: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 08:31:56 +02:00
|
|
|
nu!(
|
|
|
|
cwd: dirs.formats(),
|
2023-02-22 20:57:38 +01:00
|
|
|
"cp {} -r ../formats/* {}",
|
|
|
|
progress_flag,
|
|
|
|
dirs.test().display()
|
2019-08-29 08:31:56 +02:00
|
|
|
);
|
2019-08-28 19:01:16 +02:00
|
|
|
|
|
|
|
assert!(files_exist_at(
|
|
|
|
vec![
|
|
|
|
Path::new("caco3_plastics.csv"),
|
|
|
|
Path::new("cargo_sample.toml"),
|
|
|
|
Path::new("jonathan.xml"),
|
|
|
|
Path::new("sample.ini"),
|
|
|
|
Path::new("sgml_description.json"),
|
|
|
|
Path::new("utf16.ini"),
|
|
|
|
],
|
|
|
|
dirs.test()
|
|
|
|
));
|
2023-02-22 20:57:38 +01: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);
|
2019-08-28 19:01:16 +02:00
|
|
|
})
|
2019-08-07 16:45:50 +02:00
|
|
|
}
|
2019-08-09 08:52:48 +02:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn copies_using_a_glob() {
|
2023-02-22 20:57:38 +01:00
|
|
|
copies_using_a_glob_impl(false);
|
|
|
|
copies_using_a_glob_impl(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn copies_using_a_glob_impl(progress: bool) {
|
2019-08-28 19:01:16 +02:00
|
|
|
Playground::setup("cp_test_7", |dirs, _| {
|
2023-02-22 20:57:38 +01: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 08:31:56 +02:00
|
|
|
nu!(
|
|
|
|
cwd: dirs.formats(),
|
2023-02-22 20:57:38 +01:00
|
|
|
"cp {} -r * {}",
|
|
|
|
progress_flag,
|
|
|
|
dirs.test().display()
|
2019-08-29 08:31:56 +02:00
|
|
|
);
|
2019-08-28 19:01:16 +02:00
|
|
|
|
|
|
|
assert!(files_exist_at(
|
|
|
|
vec![
|
|
|
|
Path::new("caco3_plastics.csv"),
|
|
|
|
Path::new("cargo_sample.toml"),
|
|
|
|
Path::new("jonathan.xml"),
|
|
|
|
Path::new("sample.ini"),
|
|
|
|
Path::new("sgml_description.json"),
|
|
|
|
Path::new("utf16.ini"),
|
|
|
|
],
|
|
|
|
dirs.test()
|
|
|
|
));
|
2023-02-22 20:57:38 +01: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);
|
2019-08-28 19:01:16 +02:00
|
|
|
});
|
2019-08-09 08:52:48 +02:00
|
|
|
}
|
2020-02-05 07:54:05 +01:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn copies_same_file_twice() {
|
2023-02-22 20:57:38 +01:00
|
|
|
copies_same_file_twice_impl(false);
|
|
|
|
copies_same_file_twice_impl(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn copies_same_file_twice_impl(progress: bool) {
|
2020-02-05 07:54:05 +01:00
|
|
|
Playground::setup("cp_test_8", |dirs, _| {
|
2023-02-22 20:57:38 +01:00
|
|
|
let progress_flag = if progress { "-p" } else { "" };
|
|
|
|
|
2020-02-05 07:54:05 +01:00
|
|
|
nu!(
|
|
|
|
cwd: dirs.root(),
|
2023-02-22 20:57:38 +01:00
|
|
|
"cp {} `{}` cp_test_8/sample.ini",
|
|
|
|
progress_flag,
|
2022-08-13 04:13:50 +02:00
|
|
|
dirs.formats().join("sample.ini").display()
|
2020-02-05 07:54:05 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
nu!(
|
|
|
|
cwd: dirs.root(),
|
2023-02-22 20:57:38 +01:00
|
|
|
"cp {} `{}` cp_test_8/sample.ini",
|
|
|
|
progress_flag,
|
2022-08-13 04:13:50 +02:00
|
|
|
dirs.formats().join("sample.ini").display()
|
2020-02-05 07:54:05 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
assert!(dirs.test().join("sample.ini").exists());
|
|
|
|
});
|
|
|
|
}
|
2020-04-06 13:28:56 +02:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn copy_files_using_glob_two_parents_up_using_multiple_dots() {
|
2023-02-22 20:57:38 +01: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) {
|
2020-04-06 13:28:56 +02:00
|
|
|
Playground::setup("cp_test_9", |dirs, sandbox| {
|
Move external closer to internal (#1611)
* Refactor InputStream and affected commands.
First, making `values` private and leaning on the `Stream` implementation makes
consumes of `InputStream` less likely to have to change in the future, if we
change what an `InputStream` is internally.
Second, we're dropping `Option<InputStream>` as the input to pipelines,
internals, and externals. Instead, `InputStream.is_empty` can be used to check
for "emptiness". Empty streams are typically only ever used as the first input
to a pipeline.
* Add run_external internal command.
We want to push external commands closer to internal commands, eventually
eliminating the concept of "external" completely. This means we can consolidate
a couple of things:
- Variable evaluation (for example, `$it`, `$nu`, alias vars)
- Behaviour of whole stream vs per-item external execution
It should also make it easier for us to start introducing argument signatures
for external commands,
* Update run_external.rs
* Update run_external.rs
* Update run_external.rs
* Update run_external.rs
Co-authored-by: Jonathan Turner <jonathandturner@users.noreply.github.com>
2020-04-20 05:30:44 +02:00
|
|
|
sandbox.within("foo").within("bar").with_files(vec![
|
2020-04-06 13:28:56 +02:00
|
|
|
EmptyFile("jonathan.json"),
|
|
|
|
EmptyFile("andres.xml"),
|
|
|
|
EmptyFile("yehuda.yaml"),
|
|
|
|
EmptyFile("kevin.txt"),
|
|
|
|
EmptyFile("many_more.ppl"),
|
|
|
|
]);
|
|
|
|
|
2023-02-22 20:57:38 +01:00
|
|
|
let progress_flag = if progress { "-p" } else { "" };
|
|
|
|
|
2020-04-06 13:28:56 +02:00
|
|
|
nu!(
|
|
|
|
cwd: dirs.test().join("foo/bar"),
|
2023-02-22 20:57:38 +01:00
|
|
|
" cp {} * ...",
|
|
|
|
progress_flag,
|
2020-04-06 13:28:56 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
assert!(files_exist_at(
|
|
|
|
vec![
|
|
|
|
"yehuda.yaml",
|
|
|
|
"jonathan.json",
|
|
|
|
"andres.xml",
|
|
|
|
"kevin.txt",
|
2020-04-19 01:05:24 +02:00
|
|
|
"many_more.ppl",
|
2020-04-06 13:28:56 +02:00
|
|
|
],
|
|
|
|
dirs.test()
|
|
|
|
));
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2020-04-19 01:05:24 +02:00
|
|
|
fn copy_file_and_dir_from_two_parents_up_using_multiple_dots_to_current_dir_recursive() {
|
2023-02-22 20:57:38 +01: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,
|
|
|
|
) {
|
2020-04-06 13:28:56 +02:00
|
|
|
Playground::setup("cp_test_10", |dirs, sandbox| {
|
|
|
|
sandbox.with_files(vec![EmptyFile("hello_there")]);
|
2020-04-19 01:05:24 +02:00
|
|
|
sandbox.mkdir("hello_again");
|
2020-04-06 13:28:56 +02:00
|
|
|
sandbox.within("foo").mkdir("bar");
|
|
|
|
|
2023-02-22 20:57:38 +01:00
|
|
|
let progress_flag = if progress { "-p" } else { "" };
|
|
|
|
|
2020-04-06 13:28:56 +02:00
|
|
|
nu!(
|
|
|
|
cwd: dirs.test().join("foo/bar"),
|
2023-02-22 20:57:38 +01:00
|
|
|
"cp {} -r .../hello* .",
|
|
|
|
progress_flag
|
2020-04-06 13:28:56 +02:00
|
|
|
);
|
|
|
|
|
2020-04-19 01:05:24 +02:00
|
|
|
let expected = dirs.test().join("foo/bar");
|
2020-04-06 13:28:56 +02:00
|
|
|
|
2020-04-19 01:05:24 +02:00
|
|
|
assert!(files_exist_at(vec!["hello_there", "hello_again"], expected));
|
2020-04-06 13:28:56 +02:00
|
|
|
})
|
|
|
|
}
|
2022-05-20 23:49:29 +02:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn copy_to_non_existing_dir() {
|
2023-02-22 20:57:38 +01:00
|
|
|
copy_to_non_existing_dir_impl(false);
|
|
|
|
copy_to_non_existing_dir_impl(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn copy_to_non_existing_dir_impl(progress: bool) {
|
2022-05-20 23:49:29 +02:00
|
|
|
Playground::setup("cp_test_11", |_dirs, sandbox| {
|
|
|
|
sandbox.with_files(vec![EmptyFile("empty_file")]);
|
|
|
|
|
2023-02-22 20:57:38 +01:00
|
|
|
let progress_flag = if progress { "-p" } else { "" };
|
|
|
|
|
2022-05-20 23:49:29 +02:00
|
|
|
let actual = nu!(
|
|
|
|
cwd: sandbox.cwd(),
|
2023-02-22 20:57:38 +01:00
|
|
|
"cp {} empty_file ~/not_a_dir/",
|
|
|
|
progress_flag
|
2022-05-20 23:49:29 +02:00
|
|
|
);
|
|
|
|
assert!(actual.err.contains("directory not found"));
|
|
|
|
assert!(actual.err.contains("destination directory does not exist"));
|
|
|
|
});
|
|
|
|
}
|
2022-05-26 17:42:52 +02:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn copy_dir_contains_symlink_ignored() {
|
2023-02-22 20:57:38 +01:00
|
|
|
copy_dir_contains_symlink_ignored_impl(false);
|
|
|
|
copy_dir_contains_symlink_ignored_impl(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn copy_dir_contains_symlink_ignored_impl(progress: bool) {
|
2022-05-26 17:42:52 +02:00
|
|
|
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");
|
|
|
|
|
2023-02-22 20:57:38 +01:00
|
|
|
let progress_flag = if progress { "-p" } else { "" };
|
|
|
|
|
2022-05-26 17:42:52 +02:00
|
|
|
// make symbolic link and copy.
|
|
|
|
nu!(
|
|
|
|
cwd: sandbox.cwd(),
|
2023-02-22 20:57:38 +01:00
|
|
|
"rm {} tmp_dir/good_bye; cp -r tmp_dir tmp_dir_2",
|
|
|
|
progress_flag
|
2022-05-26 17:42:52 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
// 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() {
|
2023-02-22 20:57:38 +01:00
|
|
|
copy_dir_contains_symlink_impl(false);
|
|
|
|
copy_dir_contains_symlink_impl(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn copy_dir_contains_symlink_impl(progress: bool) {
|
2022-05-26 17:42:52 +02:00
|
|
|
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");
|
|
|
|
|
2023-02-22 20:57:38 +01:00
|
|
|
let progress_flag = if progress { "-p" } else { "" };
|
|
|
|
|
2022-05-26 17:42:52 +02:00
|
|
|
// make symbolic link and copy.
|
|
|
|
nu!(
|
|
|
|
cwd: sandbox.cwd(),
|
2023-02-22 20:57:38 +01:00
|
|
|
"rm tmp_dir/good_bye; cp {} -r -n tmp_dir tmp_dir_2",
|
|
|
|
progress_flag
|
2022-05-26 17:42:52 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
// 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() {
|
2023-02-22 20:57:38 +01: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) {
|
2022-05-26 17:42:52 +02:00
|
|
|
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");
|
|
|
|
|
2023-02-22 20:57:38 +01:00
|
|
|
let progress_flag = if progress { "-p" } else { "" };
|
|
|
|
|
2022-05-26 17:42:52 +02:00
|
|
|
// make symbolic link and copy.
|
|
|
|
nu!(
|
|
|
|
cwd: sandbox.cwd(),
|
2023-02-22 20:57:38 +01: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,
|
2022-05-26 17:42:52 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
// 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-06-01 01:24:33 +02:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn copy_identical_file() {
|
2023-02-22 20:57:38 +01:00
|
|
|
copy_identical_file_impl(false);
|
|
|
|
copy_identical_file_impl(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn copy_identical_file_impl(progress: bool) {
|
2022-06-01 01:24:33 +02:00
|
|
|
Playground::setup("cp_test_15", |_dirs, sandbox| {
|
|
|
|
sandbox.with_files(vec![EmptyFile("same.txt")]);
|
|
|
|
|
2023-02-22 20:57:38 +01:00
|
|
|
let progress_flag = if progress { "-p" } else { "" };
|
|
|
|
|
2022-06-01 01:24:33 +02:00
|
|
|
let actual = nu!(
|
|
|
|
cwd: sandbox.cwd(),
|
2023-02-22 20:57:38 +01:00
|
|
|
"cp {} same.txt same.txt",
|
|
|
|
progress_flag,
|
2022-06-01 01:24:33 +02:00
|
|
|
);
|
|
|
|
assert!(actual.err.contains("Copy aborted"));
|
|
|
|
});
|
|
|
|
}
|
2022-08-04 13:59:20 +02:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn copy_ignores_ansi() {
|
2023-02-22 20:57:38 +01:00
|
|
|
copy_ignores_ansi_impl(false);
|
|
|
|
copy_ignores_ansi_impl(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn copy_ignores_ansi_impl(progress: bool) {
|
2022-08-04 13:59:20 +02:00
|
|
|
Playground::setup("cp_test_16", |_dirs, sandbox| {
|
|
|
|
sandbox.with_files(vec![EmptyFile("test.txt")]);
|
|
|
|
|
2023-02-22 20:57:38 +01:00
|
|
|
let progress_flag = if progress { "-p" } else { "" };
|
|
|
|
|
2022-08-04 13:59:20 +02:00
|
|
|
let actual = nu!(
|
|
|
|
cwd: sandbox.cwd(),
|
2023-02-22 20:57:38 +01:00
|
|
|
"ls | find test | get name | cp {} $in.0 success.txt; ls | find success | get name | ansi strip | get 0",
|
|
|
|
progress_flag,
|
2022-08-04 13:59:20 +02:00
|
|
|
);
|
|
|
|
assert_eq!(actual.out, "success.txt");
|
|
|
|
});
|
|
|
|
}
|
2023-02-01 21:48:21 +01:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn copy_file_not_exists_dst() {
|
2023-02-22 20:57:38 +01:00
|
|
|
copy_file_not_exists_dst_impl(false);
|
|
|
|
copy_file_not_exists_dst_impl(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn copy_file_not_exists_dst_impl(progress: bool) {
|
2023-02-01 21:48:21 +01:00
|
|
|
Playground::setup("cp_test_17", |_dirs, sandbox| {
|
|
|
|
sandbox.with_files(vec![EmptyFile("valid.txt")]);
|
|
|
|
|
2023-02-22 20:57:38 +01:00
|
|
|
let progress_flag = if progress { "-p" } else { "" };
|
|
|
|
|
2023-02-01 21:48:21 +01:00
|
|
|
let actual = nu!(
|
|
|
|
cwd: sandbox.cwd(),
|
2023-02-22 20:57:38 +01:00
|
|
|
"cp {} valid.txt ~/invalid_dir/invalid_dir1",
|
|
|
|
progress_flag,
|
2023-02-01 21:48:21 +01:00
|
|
|
);
|
|
|
|
assert!(
|
|
|
|
actual.err.contains("invalid_dir1") && actual.err.contains("copying to destination")
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn copy_file_with_read_permission() {
|
2023-02-22 20:57:38 +01:00
|
|
|
copy_file_with_read_permission_impl(false);
|
|
|
|
copy_file_with_read_permission_impl(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn copy_file_with_read_permission_impl(progress: bool) {
|
2023-02-01 21:48:21 +01:00
|
|
|
Playground::setup("cp_test_18", |_dirs, sandbox| {
|
|
|
|
sandbox.with_files(vec![
|
|
|
|
EmptyFile("valid.txt"),
|
|
|
|
FileWithPermission("invalid_prem.txt", false),
|
|
|
|
]);
|
|
|
|
|
2023-02-22 20:57:38 +01:00
|
|
|
let progress_flag = if progress { "-p" } else { "" };
|
|
|
|
|
2023-02-01 21:48:21 +01:00
|
|
|
let actual = nu!(
|
|
|
|
cwd: sandbox.cwd(),
|
2023-02-22 20:57:38 +01:00
|
|
|
"cp {} valid.txt invalid_prem.txt",
|
|
|
|
progress_flag,
|
2023-02-01 21:48:21 +01:00
|
|
|
);
|
|
|
|
assert!(
|
|
|
|
actual.err.contains("invalid_prem.txt")
|
|
|
|
&& actual.err.contains("copying to destination")
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|