Readability improvement.

This commit is contained in:
Andrés N. Robalino
2019-08-29 01:31:56 -05:00
parent fcc41af899
commit 9810df25b4
15 changed files with 312 additions and 239 deletions

View File

@@ -1,19 +1,20 @@
mod helpers;
use helpers::{in_directory as cwd, dir_exists_at, file_exists_at, files_exist_at, Playground, Stub::*};
use nu::AbsoluteFile;
use std::path::{Path, PathBuf};
use helpers::{files_exist_at, Playground, Stub::*};
use std::path::Path;
#[test]
fn copies_a_file() {
Playground::setup("cp_test_1", |dirs, _| {
nu!(
cwd(dirs.root()),
cwd: dirs.root(),
"cp {} cp_test_1/sample.ini",
dirs.formats().join("sample.ini")
);
assert!(file_exists_at(dirs.test().join("sample.ini")));
assert!(dirs.test().join("sample.ini").exists());
});
}
@@ -23,19 +24,22 @@ fn copies_the_file_inside_directory_if_path_to_copy_is_directory() {
let expected_file = AbsoluteFile::new(dirs.test().join("sample.ini"));
nu!(
cwd(dirs.formats()),
cwd: dirs.formats(),
"cp ../formats/sample.ini {}",
expected_file.dir()
);
assert!(file_exists_at(dirs.test().join("sample.ini")));
assert!(dirs.test().join("sample.ini").exists());
})
}
#[test]
fn error_if_attempting_to_copy_a_directory_to_another_directory() {
Playground::setup("cp_test_3", |dirs, _| {
let actual = nu_error!(dirs.formats(), "cp ../formats {}", dirs.test());
let actual = nu_error!(
cwd: dirs.formats(),
"cp ../formats {}", dirs.test()
);
assert!(actual.contains("../formats"));
assert!(actual.contains("is a directory (not copied)"));
@@ -56,40 +60,25 @@ fn copies_the_directory_inside_directory_if_path_to_copy_is_directory_and_with_r
let expected_dir = dirs.test().join("expected").join("originals");
nu!(cwd(dirs.test()), "cp originals expected --recursive");
nu!(
cwd: dirs.test(),
"cp originals expected --recursive"
);
assert!(dir_exists_at(PathBuf::from(&expected_dir)));
assert!(expected_dir.exists());
assert!(files_exist_at(
vec![
Path::new("yehuda.txt"),
Path::new("jonathan.txt"),
Path::new("andres.txt")
],
PathBuf::from(&expected_dir)
expected_dir
));
})
}
#[test]
fn deep_copies_with_recursive_flag() {
r#"
Given these files and directories
originals
originals/manifest.txt
originals/contributors
originals/contributors/yehuda.txt
originals/contributors/jonathan.txt
originals/contributors/andres.txt
originals/contributors/jonathan
originals/contributors/jonathan/errors.txt
originals/contributors/jonathan/multishells.txt
originals/contributors/andres
originals/contributors/andres/coverage.txt
originals/contributors/andres/commands.txt
originals/contributors/yehuda
originals/contributors/yehuda/defer-evaluation.txt
"#;
Playground::setup("cp_test_5", |dirs, sandbox| {
sandbox
.within("originals")
@@ -114,20 +103,23 @@ fn deep_copies_with_recursive_flag() {
let andres_expected_copied_dir = expected_dir.join("contributors").join("andres");
let yehudas_expected_copied_dir = expected_dir.join("contributors").join("yehuda");
nu!(cwd(dirs.test()), "cp originals expected --recursive");
nu!(
cwd: dirs.test(),
"cp originals expected --recursive"
);
assert!(dir_exists_at(PathBuf::from(&expected_dir)));
assert!(expected_dir.exists());
assert!(files_exist_at(
vec![Path::new("errors.txt"), Path::new("multishells.txt")],
PathBuf::from(&jonathans_expected_copied_dir)
jonathans_expected_copied_dir
));
assert!(files_exist_at(
vec![Path::new("coverage.txt"), Path::new("commands.txt")],
PathBuf::from(&andres_expected_copied_dir)
andres_expected_copied_dir
));
assert!(files_exist_at(
vec![Path::new("defer-evaluation.txt")],
PathBuf::from(&yehudas_expected_copied_dir)
yehudas_expected_copied_dir
));
})
}
@@ -135,7 +127,10 @@ fn deep_copies_with_recursive_flag() {
#[test]
fn copies_using_path_with_wildcard() {
Playground::setup("cp_test_6", |dirs, _| {
nu!(cwd(dirs.formats()), "cp ../formats/* {}", dirs.test());
nu!(
cwd: dirs.formats(),
"cp ../formats/* {}", dirs.test()
);
assert!(files_exist_at(
vec![
@@ -154,7 +149,10 @@ fn copies_using_path_with_wildcard() {
#[test]
fn copies_using_a_glob() {
Playground::setup("cp_test_7", |dirs, _| {
nu!(cwd(dirs.formats()), "cp * {}", dirs.test());
nu!(
cwd: dirs.formats(),
"cp * {}", dirs.test()
);
assert!(files_exist_at(
vec![