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

@ -6,7 +6,6 @@ use nu_test_support::playground::Playground;
use rstest::rstest;
#[cfg(not(windows))]
use std::fs;
use std::path::Path;
#[test]
fn removes_a_file() {
@ -50,7 +49,7 @@ fn removes_files_with_wildcard() {
);
assert!(!files_exist_at(
vec![
&[
"src/parser/parse/token_tree.rs",
"src/parser/hir/baseline_parse.rs",
"src/parser/hir/baseline_parse_tokens.rs"
@ -91,7 +90,7 @@ fn removes_deeply_nested_directories_with_wildcard_and_recursive_flag() {
);
assert!(!files_exist_at(
vec!["src/parser/parse", "src/parser/hir"],
&["src/parser/parse", "src/parser/hir"],
dirs.test()
));
})
@ -277,7 +276,7 @@ fn remove_files_from_two_parents_up_using_multiple_dots_and_glob() {
);
assert!(!files_exist_at(
vec!["yehuda.txt", "jttxt", "kevin.txt"],
&["yehuda.txt", "jttxt", "kevin.txt"],
dirs.test()
));
})
@ -305,8 +304,8 @@ fn rm_wildcard_keeps_dotfiles() {
r#"rm *"#
);
assert!(!files_exist_at(vec!["foo"], dirs.test()));
assert!(files_exist_at(vec![".bar"], dirs.test()));
assert!(!files_exist_at(&["foo"], dirs.test()));
assert!(files_exist_at(&[".bar"], dirs.test()));
})
}
@ -320,8 +319,8 @@ fn rm_wildcard_leading_dot_deletes_dotfiles() {
"rm .*"
);
assert!(files_exist_at(vec!["foo"], dirs.test()));
assert!(!files_exist_at(vec![".bar"], dirs.test()));
assert!(files_exist_at(&["foo"], dirs.test()));
assert!(!files_exist_at(&[".bar"], dirs.test()));
})
}
@ -453,7 +452,7 @@ fn rm_prints_filenames_on_error() {
// This rm is expected to fail, and stderr output indicating so is also expected.
let actual = nu!(cwd: test_dir, "rm test*.txt");
assert!(files_exist_at(file_names.clone(), test_dir));
assert!(files_exist_at(&file_names, test_dir));
for file_name in file_names {
let path = test_dir.join(file_name);
let substr = format!("Could not delete {}", path.to_string_lossy());
@ -482,7 +481,7 @@ fn rm_files_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)
));
});
@ -556,22 +555,16 @@ fn rm_with_tilde() {
let actual = nu!(cwd: dirs.test(), "rm '~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(&["f1.txt"], dirs.test().join("~tilde")));
// pass variable
let actual = nu!(cwd: dirs.test(), "let f = '~tilde/f2.txt'; rm $f");
assert!(actual.err.is_empty());
assert!(!files_exist_at(
vec![Path::new("f2.txt")],
dirs.test().join("~tilde")
));
assert!(!files_exist_at(&["f2.txt"], dirs.test().join("~tilde")));
// remove directory
let actual = nu!(cwd: dirs.test(), "let f = '~tilde'; rm -r $f");
assert!(actual.err.is_empty());
assert!(!files_exist_at(vec![Path::new("~tilde")], dirs.test()));
assert!(!files_exist_at(&["~tilde"], dirs.test()));
})
}