Path migration part 4: various tests (#13373)

# Description
Part 4 of replacing std::path types with nu_path types added in
https://github.com/nushell/nushell/pull/13115. This PR migrates various
tests throughout the code base.
This commit is contained in:
Ian Manske
2024-08-03 08:09:13 +00:00
committed by GitHub
parent 85b06b22d9
commit f4c0d9d45b
13 changed files with 213 additions and 212 deletions

View File

@ -7,7 +7,6 @@ use nu_test_support::nu;
use nu_test_support::playground::Playground;
use rstest::rstest;
use std::path::Path;
#[cfg(not(target_os = "windows"))]
const PATH_SEPARATOR: &str = "/";
@ -131,11 +130,7 @@ fn copies_the_directory_inside_directory_if_path_to_copy_is_directory_and_with_r
assert!(expected_dir.exists());
assert!(files_exist_at(
vec![
Path::new("yehuda.txt"),
Path::new("jttxt"),
Path::new("andres.txt")
],
&["yehuda.txt", "jttxt", "andres.txt"],
&expected_dir
));
})
@ -181,15 +176,15 @@ fn deep_copies_with_recursive_flag_impl(progress: bool) {
assert!(expected_dir.exists());
assert!(files_exist_at(
vec![Path::new("errors.txt"), Path::new("multishells.txt")],
&["errors.txt", "multishells.txt"],
jts_expected_copied_dir
));
assert!(files_exist_at(
vec![Path::new("coverage.txt"), Path::new("commands.txt")],
&["coverage.txt", "commands.txt"],
andres_expected_copied_dir
));
assert!(files_exist_at(
vec![Path::new("defer-evaluation.txt")],
&["defer-evaluation.txt"],
yehudas_expected_copied_dir
));
})
@ -220,13 +215,13 @@ fn copies_using_path_with_wildcard_impl(progress: bool) {
);
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"),
&[
"caco3_plastics.csv",
"cargo_sample.toml",
"jt.xml",
"sample.ini",
"sgml_description.json",
"utf16.ini",
],
dirs.test()
));
@ -265,13 +260,13 @@ fn copies_using_a_glob_impl(progress: bool) {
);
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"),
&[
"caco3_plastics.csv",
"cargo_sample.toml",
"jt.xml",
"sample.ini",
"sgml_description.json",
"utf16.ini",
],
dirs.test()
));
@ -341,7 +336,7 @@ fn copy_files_using_glob_two_parents_up_using_multiple_dots_imp(progress: bool)
);
assert!(files_exist_at(
vec![
&[
"yehuda.yaml",
"jtjson",
"andres.xml",
@ -377,7 +372,7 @@ fn copy_file_and_dir_from_two_parents_up_using_multiple_dots_to_current_dir_recu
let expected = dirs.test().join("foo/bar");
assert!(files_exist_at(vec!["hello_there", "hello_again"], expected));
assert!(files_exist_at(&["hello_there", "hello_again"], expected));
})
}
@ -428,7 +423,7 @@ fn copy_dir_contains_symlink_ignored_impl(progress: bool) {
// 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));
assert!(files_exist_at(&["hello_there"], expected));
// GNU cp will copy the broken symlink, so following their behavior
// thus commenting out below
// let path = expected.join("dangle_symlink");
@ -461,7 +456,7 @@ fn copy_dir_contains_symlink_impl(progress: bool) {
// 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()));
assert!(files_exist_at(&["hello_there"], expected.clone()));
let path = expected.join("dangle_symlink");
assert!(path.is_symlink());
});
@ -1151,10 +1146,10 @@ fn test_cp_inside_glob_metachars_dir() {
assert!(actual.err.is_empty());
assert!(files_exist_at(
vec!["test_file.txt"],
&["test_file.txt"],
dirs.test().join(sub_dir)
));
assert!(files_exist_at(vec!["test_file.txt"], dirs.test()));
assert!(files_exist_at(&["test_file.txt"], dirs.test()));
});
}
@ -1167,10 +1162,7 @@ fn test_cp_to_customized_home_directory() {
let actual = nu!(cwd: dirs.test(), "mkdir test; cp test_file.txt ~/test/");
assert!(actual.err.is_empty());
assert!(files_exist_at(
vec!["test_file.txt"],
dirs.test().join("test")
));
assert!(files_exist_at(&["test_file.txt"], dirs.test().join("test")));
})
}
@ -1193,20 +1185,14 @@ fn cp_with_tilde() {
// cp file
let actual = nu!(cwd: dirs.test(), "cp '~tilde/f1.txt' ./");
assert!(actual.err.is_empty());
assert!(files_exist_at(
vec![Path::new("f1.txt")],
dirs.test().join("~tilde")
));
assert!(files_exist_at(vec![Path::new("f1.txt")], dirs.test()));
assert!(files_exist_at(&["f1.txt"], dirs.test().join("~tilde")));
assert!(files_exist_at(&["f1.txt"], dirs.test()));
// pass variable
let actual = nu!(cwd: dirs.test(), "let f = '~tilde/f2.txt'; cp $f ./");
assert!(actual.err.is_empty());
assert!(files_exist_at(
vec![Path::new("f2.txt")],
dirs.test().join("~tilde")
));
assert!(files_exist_at(vec![Path::new("f1.txt")], dirs.test()));
assert!(files_exist_at(&["f2.txt"], dirs.test().join("~tilde")));
assert!(files_exist_at(&["f1.txt"], dirs.test()));
})
}