mirror of
https://github.com/nushell/nushell.git
synced 2025-07-01 15:11:52 +02:00
Path migration part 2: nu-test-support
(#13329)
# Description Part 2 of replacing `std::path` types with `nu_path` types added in #13115. This PR targets `nu-test-support`.
This commit is contained in:
@ -580,7 +580,7 @@ mod test {
|
||||
Playground::setup("test_expand_glob", |dirs, play| {
|
||||
play.with_files(&[Stub::EmptyFile("a.txt"), Stub::EmptyFile("b.txt")]);
|
||||
|
||||
let cwd = dirs.test();
|
||||
let cwd = dirs.test().as_std_path();
|
||||
|
||||
let actual = expand_glob("*.txt", cwd, Span::unknown(), &Signals::empty()).unwrap();
|
||||
let expected = &["a.txt", "b.txt"];
|
||||
|
@ -465,7 +465,7 @@ fn make_sqlite_db(dirs: &Dirs, nu_table: &str) -> PathBuf {
|
||||
);
|
||||
|
||||
assert!(nucmd.status.success());
|
||||
testdb_path
|
||||
testdb_path.into()
|
||||
}
|
||||
|
||||
fn insert_test_rows(dirs: &Dirs, nu_table: &str, sql_query: Option<&str>, expected: Vec<TestRow>) {
|
||||
|
@ -1,3 +1,4 @@
|
||||
use nu_path::AbsolutePath;
|
||||
use nu_test_support::fs::{files_exist_at, Stub::EmptyFile};
|
||||
use nu_test_support::nu;
|
||||
use nu_test_support::playground::Playground;
|
||||
@ -405,10 +406,10 @@ fn removes_file_after_cd() {
|
||||
}
|
||||
|
||||
struct Cleanup<'a> {
|
||||
dir_to_clean: &'a Path,
|
||||
dir_to_clean: &'a AbsolutePath,
|
||||
}
|
||||
|
||||
fn set_dir_read_only(directory: &Path, read_only: bool) {
|
||||
fn set_dir_read_only(directory: &AbsolutePath, read_only: bool) {
|
||||
let mut permissions = fs::metadata(directory).unwrap().permissions();
|
||||
permissions.set_readonly(read_only);
|
||||
fs::set_permissions(directory, permissions).expect("failed to set directory permissions");
|
||||
|
@ -1,4 +1,3 @@
|
||||
use nu_test_support::fs::AbsolutePath;
|
||||
use nu_test_support::fs::Stub::{FileWithContent, FileWithContentToBeTrimmed};
|
||||
use nu_test_support::nu;
|
||||
use nu_test_support::pipeline;
|
||||
@ -8,17 +7,18 @@ use nu_test_support::playground::Playground;
|
||||
#[test]
|
||||
fn sources_also_files_under_custom_lib_dirs_path() {
|
||||
Playground::setup("source_test_1", |dirs, nu| {
|
||||
let file = AbsolutePath::new(dirs.test().join("config.toml"));
|
||||
let library_path = AbsolutePath::new(dirs.test().join("lib"));
|
||||
let file = dirs.test().join("config.toml");
|
||||
let library_path = dirs.test().join("lib");
|
||||
|
||||
nu.with_config(&file);
|
||||
nu.with_config(file);
|
||||
nu.with_files(&[FileWithContent(
|
||||
"config.toml",
|
||||
&format!(
|
||||
r#"
|
||||
lib_dirs = ["{library_path}"]
|
||||
lib_dirs = ["{}"]
|
||||
skip_welcome_message = true
|
||||
"#
|
||||
"#,
|
||||
library_path.as_os_str().to_str().unwrap(),
|
||||
),
|
||||
)]);
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
use nu_test_support::fs::file_contents;
|
||||
use nu_test_support::fs::{
|
||||
files_exist_at, AbsoluteFile,
|
||||
files_exist_at,
|
||||
Stub::{EmptyFile, FileWithContent, FileWithPermission},
|
||||
};
|
||||
use nu_test_support::nu;
|
||||
@ -55,7 +55,7 @@ fn copies_the_file_inside_directory_if_path_to_copy_is_directory() {
|
||||
|
||||
fn copies_the_file_inside_directory_if_path_to_copy_is_directory_impl(progress: bool) {
|
||||
Playground::setup("ucp_test_2", |dirs, _| {
|
||||
let expected_file = AbsoluteFile::new(dirs.test().join("sample.ini"));
|
||||
let expected_file = dirs.test().join("sample.ini");
|
||||
let progress_flag = if progress { "-p" } else { "" };
|
||||
|
||||
// Get the hash of the file content to check integrity after copy.
|
||||
@ -64,13 +64,13 @@ fn copies_the_file_inside_directory_if_path_to_copy_is_directory_impl(progress:
|
||||
cwd: dirs.formats(),
|
||||
"cp {} ../formats/sample.ini {}",
|
||||
progress_flag,
|
||||
expected_file.dir()
|
||||
expected_file.parent().unwrap().as_os_str().to_str().unwrap(),
|
||||
);
|
||||
|
||||
assert!(dirs.test().join("sample.ini").exists());
|
||||
|
||||
// Check the integrity of the file.
|
||||
let after_cp_hash = get_file_hash(expected_file);
|
||||
let after_cp_hash = get_file_hash(expected_file.display());
|
||||
assert_eq!(first_hash, after_cp_hash);
|
||||
})
|
||||
}
|
||||
|
@ -1,4 +1,3 @@
|
||||
use nu_test_support::fs::AbsolutePath;
|
||||
use nu_test_support::fs::Stub::{FileWithContent, FileWithContentToBeTrimmed};
|
||||
use nu_test_support::nu;
|
||||
use nu_test_support::pipeline;
|
||||
@ -7,10 +6,10 @@ use nu_test_support::playground::Playground;
|
||||
#[test]
|
||||
fn use_module_file_within_block() {
|
||||
Playground::setup("use_test_1", |dirs, nu| {
|
||||
let file = AbsolutePath::new(dirs.test().join("spam.nu"));
|
||||
let file = dirs.test().join("spam.nu");
|
||||
|
||||
nu.with_files(&[FileWithContent(
|
||||
&file.to_string(),
|
||||
file.as_os_str().to_str().unwrap(),
|
||||
r#"
|
||||
export def foo [] {
|
||||
echo "hello world"
|
||||
@ -37,10 +36,10 @@ fn use_module_file_within_block() {
|
||||
#[test]
|
||||
fn use_keeps_doc_comments() {
|
||||
Playground::setup("use_doc_comments", |dirs, nu| {
|
||||
let file = AbsolutePath::new(dirs.test().join("spam.nu"));
|
||||
let file = dirs.test().join("spam.nu");
|
||||
|
||||
nu.with_files(&[FileWithContent(
|
||||
&file.to_string(),
|
||||
file.as_os_str().to_str().unwrap(),
|
||||
r#"
|
||||
# this is my foo command
|
||||
export def foo [
|
||||
|
Reference in New Issue
Block a user