mirror of
https://github.com/nushell/nushell
synced 2024-12-27 05:23:11 +00:00
Readability improvement.
This commit is contained in:
parent
fcc41af899
commit
9810df25b4
15 changed files with 312 additions and 239 deletions
|
@ -1,10 +1,11 @@
|
||||||
mod helpers;
|
mod helpers;
|
||||||
|
|
||||||
use helpers::in_directory as cwd;
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn cd_directory_not_found() {
|
fn cd_directory_not_found() {
|
||||||
let actual = nu_error!(cwd("tests/fixtures"), "cd dir_that_does_not_exist");
|
let actual = nu_error!(
|
||||||
|
cwd: "tests/fixtures",
|
||||||
|
"cd dir_that_does_not_exist"
|
||||||
|
);
|
||||||
|
|
||||||
assert!(actual.contains("dir_that_does_not_exist"));
|
assert!(actual.contains("dir_that_does_not_exist"));
|
||||||
assert!(actual.contains("directory not found"));
|
assert!(actual.contains("directory not found"));
|
||||||
|
|
|
@ -1,19 +1,20 @@
|
||||||
mod helpers;
|
mod helpers;
|
||||||
|
|
||||||
use helpers::{in_directory as cwd, dir_exists_at, file_exists_at, files_exist_at, Playground, Stub::*};
|
|
||||||
use nu::AbsoluteFile;
|
use nu::AbsoluteFile;
|
||||||
use std::path::{Path, PathBuf};
|
|
||||||
|
use helpers::{files_exist_at, Playground, Stub::*};
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn copies_a_file() {
|
fn copies_a_file() {
|
||||||
Playground::setup("cp_test_1", |dirs, _| {
|
Playground::setup("cp_test_1", |dirs, _| {
|
||||||
nu!(
|
nu!(
|
||||||
cwd(dirs.root()),
|
cwd: dirs.root(),
|
||||||
"cp {} cp_test_1/sample.ini",
|
"cp {} cp_test_1/sample.ini",
|
||||||
dirs.formats().join("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"));
|
let expected_file = AbsoluteFile::new(dirs.test().join("sample.ini"));
|
||||||
|
|
||||||
nu!(
|
nu!(
|
||||||
cwd(dirs.formats()),
|
cwd: dirs.formats(),
|
||||||
"cp ../formats/sample.ini {}",
|
"cp ../formats/sample.ini {}",
|
||||||
expected_file.dir()
|
expected_file.dir()
|
||||||
);
|
);
|
||||||
|
|
||||||
assert!(file_exists_at(dirs.test().join("sample.ini")));
|
assert!(dirs.test().join("sample.ini").exists());
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn error_if_attempting_to_copy_a_directory_to_another_directory() {
|
fn error_if_attempting_to_copy_a_directory_to_another_directory() {
|
||||||
Playground::setup("cp_test_3", |dirs, _| {
|
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("../formats"));
|
||||||
assert!(actual.contains("is a directory (not copied)"));
|
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");
|
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(
|
assert!(files_exist_at(
|
||||||
vec![
|
vec![
|
||||||
Path::new("yehuda.txt"),
|
Path::new("yehuda.txt"),
|
||||||
Path::new("jonathan.txt"),
|
Path::new("jonathan.txt"),
|
||||||
Path::new("andres.txt")
|
Path::new("andres.txt")
|
||||||
],
|
],
|
||||||
PathBuf::from(&expected_dir)
|
expected_dir
|
||||||
));
|
));
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn deep_copies_with_recursive_flag() {
|
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| {
|
Playground::setup("cp_test_5", |dirs, sandbox| {
|
||||||
sandbox
|
sandbox
|
||||||
.within("originals")
|
.within("originals")
|
||||||
|
@ -114,20 +103,23 @@ fn deep_copies_with_recursive_flag() {
|
||||||
let andres_expected_copied_dir = expected_dir.join("contributors").join("andres");
|
let andres_expected_copied_dir = expected_dir.join("contributors").join("andres");
|
||||||
let yehudas_expected_copied_dir = expected_dir.join("contributors").join("yehuda");
|
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(
|
assert!(files_exist_at(
|
||||||
vec![Path::new("errors.txt"), Path::new("multishells.txt")],
|
vec![Path::new("errors.txt"), Path::new("multishells.txt")],
|
||||||
PathBuf::from(&jonathans_expected_copied_dir)
|
jonathans_expected_copied_dir
|
||||||
));
|
));
|
||||||
assert!(files_exist_at(
|
assert!(files_exist_at(
|
||||||
vec![Path::new("coverage.txt"), Path::new("commands.txt")],
|
vec![Path::new("coverage.txt"), Path::new("commands.txt")],
|
||||||
PathBuf::from(&andres_expected_copied_dir)
|
andres_expected_copied_dir
|
||||||
));
|
));
|
||||||
assert!(files_exist_at(
|
assert!(files_exist_at(
|
||||||
vec![Path::new("defer-evaluation.txt")],
|
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]
|
#[test]
|
||||||
fn copies_using_path_with_wildcard() {
|
fn copies_using_path_with_wildcard() {
|
||||||
Playground::setup("cp_test_6", |dirs, _| {
|
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(
|
assert!(files_exist_at(
|
||||||
vec![
|
vec![
|
||||||
|
@ -154,7 +149,10 @@ fn copies_using_path_with_wildcard() {
|
||||||
#[test]
|
#[test]
|
||||||
fn copies_using_a_glob() {
|
fn copies_using_a_glob() {
|
||||||
Playground::setup("cp_test_7", |dirs, _| {
|
Playground::setup("cp_test_7", |dirs, _| {
|
||||||
nu!(cwd(dirs.formats()), "cp * {}", dirs.test());
|
nu!(
|
||||||
|
cwd: dirs.formats(),
|
||||||
|
"cp * {}", dirs.test()
|
||||||
|
);
|
||||||
|
|
||||||
assert!(files_exist_at(
|
assert!(files_exist_at(
|
||||||
vec![
|
vec![
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
mod helpers;
|
mod helpers;
|
||||||
|
|
||||||
use h::{in_directory as cwd, Playground, Stub::*};
|
|
||||||
use helpers as h;
|
use helpers as h;
|
||||||
use std::path::{Path, PathBuf};
|
use helpers::{Playground, Stub::*};
|
||||||
|
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn knows_the_filesystems_entered() {
|
fn knows_the_filesystems_entered() {
|
||||||
|
@ -28,7 +29,7 @@ fn knows_the_filesystems_entered() {
|
||||||
let expected_recycled = expected.join("recycled");
|
let expected_recycled = expected.join("recycled");
|
||||||
|
|
||||||
nu!(
|
nu!(
|
||||||
cwd(dirs.test()),
|
cwd: dirs.test(),
|
||||||
r#"
|
r#"
|
||||||
enter expected
|
enter expected
|
||||||
mkdir recycled
|
mkdir recycled
|
||||||
|
@ -51,24 +52,24 @@ fn knows_the_filesystems_entered() {
|
||||||
"#
|
"#
|
||||||
);
|
);
|
||||||
|
|
||||||
assert!(!h::dir_exists_at(PathBuf::from(red_pill_dir)));
|
assert!(!red_pill_dir.exists());
|
||||||
assert!(h::files_exist_at(
|
assert!(h::files_exist_at(
|
||||||
vec![
|
vec![
|
||||||
Path::new("andres.nu"),
|
Path::new("andres.nu"),
|
||||||
Path::new("jonathan.nu"),
|
Path::new("jonathan.nu"),
|
||||||
Path::new("yehuda.nu"),
|
Path::new("yehuda.nu"),
|
||||||
],
|
],
|
||||||
PathBuf::from(&expected)
|
expected
|
||||||
));
|
));
|
||||||
|
|
||||||
assert!(!h::dir_exists_at(PathBuf::from(blue_pill_dir)));
|
assert!(!blue_pill_dir.exists());
|
||||||
assert!(h::files_exist_at(
|
assert!(h::files_exist_at(
|
||||||
vec![
|
vec![
|
||||||
Path::new("bash.nxt"),
|
Path::new("bash.nxt"),
|
||||||
Path::new("korn.nxt"),
|
Path::new("korn.nxt"),
|
||||||
Path::new("powedsh.nxt"),
|
Path::new("powedsh.nxt"),
|
||||||
],
|
],
|
||||||
PathBuf::from(&expected_recycled)
|
expected_recycled
|
||||||
));
|
));
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
mod helpers;
|
mod helpers;
|
||||||
|
|
||||||
use h::{in_directory as cwd, Playground, Stub::*};
|
|
||||||
use helpers as h;
|
use helpers as h;
|
||||||
|
use helpers::{Playground, Stub::*};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn ls_lists_regular_files() {
|
fn ls_lists_regular_files() {
|
||||||
|
@ -14,7 +14,7 @@ fn ls_lists_regular_files() {
|
||||||
]);
|
]);
|
||||||
|
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd(dirs.test()), h::pipeline(
|
cwd: dirs.test(), h::pipeline(
|
||||||
r#"
|
r#"
|
||||||
ls
|
ls
|
||||||
| get name
|
| get name
|
||||||
|
@ -43,7 +43,7 @@ fn ls_lists_regular_files_using_asterisk_wildcard() {
|
||||||
]);
|
]);
|
||||||
|
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd(dirs.test()), h::pipeline(
|
cwd: dirs.test(), h::pipeline(
|
||||||
r#"
|
r#"
|
||||||
ls *.txt
|
ls *.txt
|
||||||
| get name
|
| get name
|
||||||
|
@ -72,7 +72,7 @@ fn ls_lists_regular_files_using_question_mark_wildcard() {
|
||||||
]);
|
]);
|
||||||
|
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd(dirs.test()), h::pipeline(
|
cwd: dirs.test(), h::pipeline(
|
||||||
r#"
|
r#"
|
||||||
ls *.??.txt
|
ls *.??.txt
|
||||||
| get name
|
| get name
|
||||||
|
|
|
@ -1,24 +1,31 @@
|
||||||
mod helpers;
|
mod helpers;
|
||||||
|
|
||||||
use h::{in_directory as cwd, Playground};
|
|
||||||
use helpers as h;
|
use helpers as h;
|
||||||
use std::path::{Path, PathBuf};
|
use helpers::Playground;
|
||||||
|
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn creates_directory() {
|
fn creates_directory() {
|
||||||
Playground::setup("mkdir_test_1", |dirs, _| {
|
Playground::setup("mkdir_test_1", |dirs, _| {
|
||||||
nu!(cwd(dirs.test()), "mkdir my_new_directory");
|
nu!(
|
||||||
|
cwd: dirs.test(),
|
||||||
|
"mkdir my_new_directory"
|
||||||
|
);
|
||||||
|
|
||||||
let expected = dirs.test().join("my_new_directory");
|
let expected = dirs.test().join("my_new_directory");
|
||||||
|
|
||||||
assert!(h::dir_exists_at(expected));
|
assert!(expected.exists());
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn accepts_and_creates_directories() {
|
fn accepts_and_creates_directories() {
|
||||||
Playground::setup("mkdir_test_2", |dirs, _| {
|
Playground::setup("mkdir_test_2", |dirs, _| {
|
||||||
nu!(cwd(dirs.test()), "mkdir dir_1 dir_2 dir_3");
|
nu!(
|
||||||
|
cwd: dirs.test(),
|
||||||
|
"mkdir dir_1 dir_2 dir_3"
|
||||||
|
);
|
||||||
|
|
||||||
assert!(h::files_exist_at(
|
assert!(h::files_exist_at(
|
||||||
vec![Path::new("dir_1"), Path::new("dir_2"), Path::new("dir_3")],
|
vec![Path::new("dir_1"), Path::new("dir_2"), Path::new("dir_3")],
|
||||||
|
@ -30,11 +37,13 @@ fn accepts_and_creates_directories() {
|
||||||
#[test]
|
#[test]
|
||||||
fn creates_intermediary_directories() {
|
fn creates_intermediary_directories() {
|
||||||
Playground::setup("mkdir_test_3", |dirs, _| {
|
Playground::setup("mkdir_test_3", |dirs, _| {
|
||||||
nu!(cwd(dirs.test()), "mkdir some_folder/another/deeper_one");
|
nu!(
|
||||||
|
cwd: dirs.test(),
|
||||||
|
"mkdir some_folder/another/deeper_one"
|
||||||
|
);
|
||||||
|
|
||||||
let mut expected = PathBuf::from(dirs.test());
|
let expected = dirs.test().join("some_folder/another/deeper_one");
|
||||||
expected.push("some_folder/another/deeper_one");
|
|
||||||
|
|
||||||
assert!(h::dir_exists_at(expected));
|
assert!(expected.exists());
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
mod helpers;
|
mod helpers;
|
||||||
|
|
||||||
use h::{in_directory as cwd, Playground, Stub::*};
|
|
||||||
use helpers as h;
|
use helpers as h;
|
||||||
|
use helpers::{Playground, Stub::*};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn moves_a_file() {
|
fn moves_a_file() {
|
||||||
|
@ -13,10 +13,13 @@ fn moves_a_file() {
|
||||||
let original = dirs.test().join("andres.txt");
|
let original = dirs.test().join("andres.txt");
|
||||||
let expected = dirs.test().join("expected/yehuda.txt");
|
let expected = dirs.test().join("expected/yehuda.txt");
|
||||||
|
|
||||||
nu!(cwd(dirs.test()), "mv andres.txt expected/yehuda.txt");
|
nu!(
|
||||||
|
cwd: dirs.test(),
|
||||||
|
"mv andres.txt expected/yehuda.txt"
|
||||||
|
);
|
||||||
|
|
||||||
assert!(!h::file_exists_at(original));
|
assert!(!original.exists());
|
||||||
assert!(h::file_exists_at(expected));
|
assert!(expected.exists());
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,10 +35,13 @@ fn overwrites_if_moving_to_existing_file() {
|
||||||
let original = dirs.test().join("andres.txt");
|
let original = dirs.test().join("andres.txt");
|
||||||
let expected = dirs.test().join("jonathan.txt");
|
let expected = dirs.test().join("jonathan.txt");
|
||||||
|
|
||||||
nu!(cwd(dirs.test()), "mv andres.txt jonathan.txt");
|
nu!(
|
||||||
|
cwd: dirs.test(),
|
||||||
|
"mv andres.txt jonathan.txt"
|
||||||
|
);
|
||||||
|
|
||||||
assert!(!h::file_exists_at(original));
|
assert!(!original.exists());
|
||||||
assert!(h::file_exists_at(expected));
|
assert!(expected.exists());
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,10 +53,13 @@ fn moves_a_directory() {
|
||||||
let original_dir = dirs.test().join("empty_dir");
|
let original_dir = dirs.test().join("empty_dir");
|
||||||
let expected = dirs.test().join("renamed_dir");
|
let expected = dirs.test().join("renamed_dir");
|
||||||
|
|
||||||
nu!(cwd(dirs.test()), "mv empty_dir renamed_dir");
|
nu!(
|
||||||
|
cwd: dirs.test(),
|
||||||
|
"mv empty_dir renamed_dir"
|
||||||
|
);
|
||||||
|
|
||||||
assert!(!h::dir_exists_at(original_dir));
|
assert!(!original_dir.exists());
|
||||||
assert!(h::dir_exists_at(expected));
|
assert!(expected.exists());
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,10 +73,13 @@ fn moves_the_file_inside_directory_if_path_to_move_is_existing_directory() {
|
||||||
let original_dir = dirs.test().join("jonathan.txt");
|
let original_dir = dirs.test().join("jonathan.txt");
|
||||||
let expected = dirs.test().join("expected/jonathan.txt");
|
let expected = dirs.test().join("expected/jonathan.txt");
|
||||||
|
|
||||||
nu!(dirs.test(), "mv jonathan.txt expected");
|
nu!(
|
||||||
|
cwd: dirs.test(),
|
||||||
|
"mv jonathan.txt expected"
|
||||||
|
);
|
||||||
|
|
||||||
assert!(!h::file_exists_at(original_dir));
|
assert!(!original_dir.exists());
|
||||||
assert!(h::file_exists_at(expected));
|
assert!(expected.exists());
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,10 +94,13 @@ fn moves_the_directory_inside_directory_if_path_to_move_is_existing_directory()
|
||||||
let original_dir = dirs.test().join("contributors");
|
let original_dir = dirs.test().join("contributors");
|
||||||
let expected = dirs.test().join("expected/contributors");
|
let expected = dirs.test().join("expected/contributors");
|
||||||
|
|
||||||
nu!(dirs.test(), "mv contributors expected");
|
nu!(
|
||||||
|
cwd: dirs.test(),
|
||||||
|
"mv contributors expected"
|
||||||
|
);
|
||||||
|
|
||||||
assert!(!h::dir_exists_at(original_dir));
|
assert!(!original_dir.exists());
|
||||||
assert!(h::file_exists_at(expected));
|
assert!(expected.exists());
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,7 +115,7 @@ fn moves_the_directory_inside_directory_if_path_to_move_is_nonexistent_directory
|
||||||
let original_dir = dirs.test().join("contributors");
|
let original_dir = dirs.test().join("contributors");
|
||||||
|
|
||||||
nu!(
|
nu!(
|
||||||
cwd(dirs.test()),
|
cwd: dirs.test(),
|
||||||
"mv contributors expected/this_dir_exists_now/los_tres_amigos"
|
"mv contributors expected/this_dir_exists_now/los_tres_amigos"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -108,8 +123,8 @@ fn moves_the_directory_inside_directory_if_path_to_move_is_nonexistent_directory
|
||||||
.test()
|
.test()
|
||||||
.join("expected/this_dir_exists_now/los_tres_amigos");
|
.join("expected/this_dir_exists_now/los_tres_amigos");
|
||||||
|
|
||||||
assert!(!h::dir_exists_at(original_dir));
|
assert!(!original_dir.exists());
|
||||||
assert!(h::file_exists_at(expected));
|
assert!(expected.exists());
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,7 +150,10 @@ fn moves_using_path_with_wildcard() {
|
||||||
let work_dir = dirs.test().join("work_dir");
|
let work_dir = dirs.test().join("work_dir");
|
||||||
let expected = dirs.test().join("expected");
|
let expected = dirs.test().join("expected");
|
||||||
|
|
||||||
nu!(cwd(work_dir), "mv ../originals/*.ini ../expected");
|
nu!(
|
||||||
|
cwd: work_dir,
|
||||||
|
"mv ../originals/*.ini ../expected"
|
||||||
|
);
|
||||||
|
|
||||||
assert!(h::files_exist_at(
|
assert!(h::files_exist_at(
|
||||||
vec!["yehuda.ini", "jonathan.ini", "sample.ini", "andres.ini",],
|
vec!["yehuda.ini", "jonathan.ini", "sample.ini", "andres.ini",],
|
||||||
|
@ -161,9 +179,12 @@ fn moves_using_a_glob() {
|
||||||
let work_dir = dirs.test().join("work_dir");
|
let work_dir = dirs.test().join("work_dir");
|
||||||
let expected = dirs.test().join("expected");
|
let expected = dirs.test().join("expected");
|
||||||
|
|
||||||
nu!(cwd(work_dir), "mv ../meals/* ../expected");
|
nu!(
|
||||||
|
cwd: work_dir,
|
||||||
|
"mv ../meals/* ../expected"
|
||||||
|
);
|
||||||
|
|
||||||
assert!(h::dir_exists_at(meal_dir));
|
assert!(meal_dir.exists());
|
||||||
assert!(h::files_exist_at(
|
assert!(h::files_exist_at(
|
||||||
vec!["arepa.txt", "empanada.txt", "taquiza.txt",],
|
vec!["arepa.txt", "empanada.txt", "taquiza.txt",],
|
||||||
expected
|
expected
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
mod helpers;
|
mod helpers;
|
||||||
|
|
||||||
use helpers::{in_directory as cwd, Playground, Stub::*};
|
|
||||||
use helpers as h;
|
use helpers as h;
|
||||||
|
use helpers::{Playground, Stub::*};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn recognizes_csv() {
|
fn recognizes_csv() {
|
||||||
|
@ -18,7 +18,7 @@ fn recognizes_csv() {
|
||||||
)]);
|
)]);
|
||||||
|
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd(dirs.test()), h::pipeline(
|
cwd: dirs.test(), h::pipeline(
|
||||||
r#"
|
r#"
|
||||||
open nu.zion.csv
|
open nu.zion.csv
|
||||||
| where author == "Andres N. Robalino"
|
| where author == "Andres N. Robalino"
|
||||||
|
@ -34,7 +34,7 @@ fn recognizes_csv() {
|
||||||
#[test]
|
#[test]
|
||||||
fn open_can_parse_bson_1() {
|
fn open_can_parse_bson_1() {
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd("tests/fixtures/formats"),
|
cwd: "tests/fixtures/formats",
|
||||||
"open sample.bson | get root | nth 0 | get b | echo $it"
|
"open sample.bson | get root | nth 0 | get b | echo $it"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ fn open_can_parse_bson_1() {
|
||||||
#[test]
|
#[test]
|
||||||
fn open_can_parse_bson_2() {
|
fn open_can_parse_bson_2() {
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd("tests/fixtures/formats"), h::pipeline(
|
cwd: "tests/fixtures/formats", h::pipeline(
|
||||||
r#"
|
r#"
|
||||||
open sample.bson
|
open sample.bson
|
||||||
| get root
|
| get root
|
||||||
|
@ -61,7 +61,7 @@ fn open_can_parse_bson_2() {
|
||||||
#[test]
|
#[test]
|
||||||
fn open_can_parse_toml() {
|
fn open_can_parse_toml() {
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd("tests/fixtures/formats"),
|
cwd: "tests/fixtures/formats",
|
||||||
"open cargo_sample.toml | get package.edition | echo $it"
|
"open cargo_sample.toml | get package.edition | echo $it"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ fn open_can_parse_toml() {
|
||||||
#[test]
|
#[test]
|
||||||
fn open_can_parse_json() {
|
fn open_can_parse_json() {
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd("tests/fixtures/formats"), h::pipeline(
|
cwd: "tests/fixtures/formats", h::pipeline(
|
||||||
r#"
|
r#"
|
||||||
open sgml_description.json
|
open sgml_description.json
|
||||||
| get glossary.GlossDiv.GlossList.GlossEntry.GlossSee
|
| get glossary.GlossDiv.GlossList.GlossEntry.GlossSee
|
||||||
|
@ -85,7 +85,7 @@ fn open_can_parse_json() {
|
||||||
#[test]
|
#[test]
|
||||||
fn open_can_parse_xml() {
|
fn open_can_parse_xml() {
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd("tests/fixtures/formats"),
|
cwd: "tests/fixtures/formats",
|
||||||
"open jonathan.xml | get rss.channel.item.link | echo $it"
|
"open jonathan.xml | get rss.channel.item.link | echo $it"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -98,7 +98,7 @@ fn open_can_parse_xml() {
|
||||||
#[test]
|
#[test]
|
||||||
fn open_can_parse_ini() {
|
fn open_can_parse_ini() {
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd("tests/fixtures/formats"),
|
cwd: "tests/fixtures/formats",
|
||||||
"open sample.ini | get SectionOne.integer | echo $it"
|
"open sample.ini | get SectionOne.integer | echo $it"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -108,7 +108,7 @@ fn open_can_parse_ini() {
|
||||||
#[test]
|
#[test]
|
||||||
fn open_can_parse_utf16_ini() {
|
fn open_can_parse_utf16_ini() {
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd("tests/fixtures/formats"),
|
cwd: "tests/fixtures/formats",
|
||||||
"open utf16.ini | get .ShellClassInfo | get IconIndex | echo $it"
|
"open utf16.ini | get .ShellClassInfo | get IconIndex | echo $it"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -118,7 +118,7 @@ fn open_can_parse_utf16_ini() {
|
||||||
#[test]
|
#[test]
|
||||||
fn errors_if_file_not_found() {
|
fn errors_if_file_not_found() {
|
||||||
let actual = nu_error!(
|
let actual = nu_error!(
|
||||||
cwd("tests/fixtures/formats"),
|
cwd: "tests/fixtures/formats",
|
||||||
"open i_dont_exist.txt | echo $it"
|
"open i_dont_exist.txt | echo $it"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
mod helpers;
|
mod helpers;
|
||||||
|
|
||||||
use h::{in_directory as cwd, Playground, Stub::*};
|
|
||||||
use helpers as h;
|
use helpers as h;
|
||||||
|
use helpers::{Playground, Stub::*};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn rm_removes_a_file() {
|
fn rm_removes_a_file() {
|
||||||
|
@ -10,11 +10,14 @@ fn rm_removes_a_file() {
|
||||||
.with_files(vec![EmptyFile("i_will_be_deleted.txt")
|
.with_files(vec![EmptyFile("i_will_be_deleted.txt")
|
||||||
]);
|
]);
|
||||||
|
|
||||||
nu!(cwd(dirs.root()), "rm rm_test_1/i_will_be_deleted.txt");
|
nu!(
|
||||||
|
cwd: dirs.root(),
|
||||||
|
"rm rm_test_1/i_will_be_deleted.txt"
|
||||||
|
);
|
||||||
|
|
||||||
let path = dirs.test().join("i_will_be_deleted.txt");
|
let path = dirs.test().join("i_will_be_deleted.txt");
|
||||||
|
|
||||||
assert!(!h::file_exists_at(path));
|
assert!(!path.exists());
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,7 +41,10 @@ fn rm_removes_files_with_wildcard() {
|
||||||
EmptyFile("baseline_parse_tokens.rs")
|
EmptyFile("baseline_parse_tokens.rs")
|
||||||
]);
|
]);
|
||||||
|
|
||||||
nu!(cwd(dirs.test()), r#"rm "src/*/*/*.rs""#);
|
nu!(
|
||||||
|
cwd: dirs.test(),
|
||||||
|
r#"rm "src/*/*/*.rs""#
|
||||||
|
);
|
||||||
|
|
||||||
assert!(!h::files_exist_at(
|
assert!(!h::files_exist_at(
|
||||||
vec![
|
vec![
|
||||||
|
@ -76,7 +82,10 @@ fn rm_removes_deeply_nested_directories_with_wildcard_and_recursive_flag() {
|
||||||
EmptyFile("baseline_parse_tokens.rs")
|
EmptyFile("baseline_parse_tokens.rs")
|
||||||
]);
|
]);
|
||||||
|
|
||||||
nu!(cwd(dirs.test()), "rm src/* --recursive");
|
nu!(
|
||||||
|
cwd: dirs.test(),
|
||||||
|
"rm src/* --recursive"
|
||||||
|
);
|
||||||
|
|
||||||
assert!(!h::files_exist_at(
|
assert!(!h::files_exist_at(
|
||||||
vec!["src/parser/parse", "src/parser/hir"],
|
vec!["src/parser/parse", "src/parser/hir"],
|
||||||
|
@ -88,9 +97,12 @@ fn rm_removes_deeply_nested_directories_with_wildcard_and_recursive_flag() {
|
||||||
#[test]
|
#[test]
|
||||||
fn rm_removes_directory_contents_without_recursive_flag_if_empty() {
|
fn rm_removes_directory_contents_without_recursive_flag_if_empty() {
|
||||||
Playground::setup("rm_test_4", |dirs, _| {
|
Playground::setup("rm_test_4", |dirs, _| {
|
||||||
nu!(cwd(dirs.root()), "rm rm_test_4");
|
nu!(
|
||||||
|
cwd: dirs.root(),
|
||||||
|
"rm rm_test_4"
|
||||||
|
);
|
||||||
|
|
||||||
assert!(!h::file_exists_at(dirs.test()));
|
assert!(!dirs.test().exists());
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,9 +116,12 @@ fn rm_removes_directory_contents_with_recursive_flag() {
|
||||||
EmptyFile("andres.txt")
|
EmptyFile("andres.txt")
|
||||||
]);
|
]);
|
||||||
|
|
||||||
nu!(cwd(dirs.root()), "rm rm_test_5 --recursive");
|
nu!(
|
||||||
|
cwd: dirs.root(),
|
||||||
|
"rm rm_test_5 --recursive"
|
||||||
|
);
|
||||||
|
|
||||||
assert!(!h::file_exists_at(dirs.test()));
|
assert!(!dirs.test().exists());
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,11 +133,11 @@ fn rm_errors_if_attempting_to_delete_a_directory_with_content_without_recursive_
|
||||||
]);
|
]);
|
||||||
|
|
||||||
let actual = nu_error!(
|
let actual = nu_error!(
|
||||||
cwd(dirs.root()),
|
cwd: dirs.root(),
|
||||||
"rm rm_test_6"
|
"rm rm_test_6"
|
||||||
);
|
);
|
||||||
|
|
||||||
assert!(h::file_exists_at(dirs.test()));
|
assert!(dirs.test().exists());
|
||||||
assert!(actual.contains("is a directory"));
|
assert!(actual.contains("is a directory"));
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -130,7 +145,10 @@ fn rm_errors_if_attempting_to_delete_a_directory_with_content_without_recursive_
|
||||||
#[test]
|
#[test]
|
||||||
fn rm_errors_if_attempting_to_delete_single_dot_as_argument() {
|
fn rm_errors_if_attempting_to_delete_single_dot_as_argument() {
|
||||||
Playground::setup("rm_test_7", |dirs, _| {
|
Playground::setup("rm_test_7", |dirs, _| {
|
||||||
let actual = nu_error!(cwd(dirs.root()), "rm .");
|
let actual = nu_error!(
|
||||||
|
cwd: dirs.root(),
|
||||||
|
"rm ."
|
||||||
|
);
|
||||||
|
|
||||||
assert!(actual.contains("may not be removed"));
|
assert!(actual.contains("may not be removed"));
|
||||||
})
|
})
|
||||||
|
@ -139,7 +157,10 @@ fn rm_errors_if_attempting_to_delete_single_dot_as_argument() {
|
||||||
#[test]
|
#[test]
|
||||||
fn rm_errors_if_attempting_to_delete_two_dot_as_argument() {
|
fn rm_errors_if_attempting_to_delete_two_dot_as_argument() {
|
||||||
Playground::setup("rm_test_8", |dirs, _| {
|
Playground::setup("rm_test_8", |dirs, _| {
|
||||||
let actual = nu_error!(cwd(dirs.root()), "rm ..");
|
let actual = nu_error!(
|
||||||
|
cwd: dirs.root(),
|
||||||
|
"rm .."
|
||||||
|
);
|
||||||
|
|
||||||
assert!(actual.contains("may not be removed"));
|
assert!(actual.contains("may not be removed"));
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,14 +1,24 @@
|
||||||
mod helpers;
|
mod helpers;
|
||||||
|
|
||||||
use h::{in_directory as cwd, Playground, Stub::*};
|
|
||||||
use helpers as h;
|
use helpers as h;
|
||||||
|
use helpers::{Playground, Stub::*};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn lines() {
|
fn lines() {
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd("tests/fixtures/formats"),
|
cwd: "tests/fixtures/formats", h::pipeline(
|
||||||
r#"open cargo_sample.toml --raw | lines | skip-while $it != "[dependencies]" | skip 1 | first 1 | split-column "=" | get Column1 | trim | echo $it"#
|
r#"
|
||||||
);
|
open cargo_sample.toml --raw
|
||||||
|
| lines
|
||||||
|
| skip-while $it != "[dependencies]"
|
||||||
|
| skip 1
|
||||||
|
| first 1
|
||||||
|
| split-column "="
|
||||||
|
| get Column1
|
||||||
|
| trim
|
||||||
|
| echo $it
|
||||||
|
"#
|
||||||
|
));
|
||||||
|
|
||||||
assert_eq!(actual, "rustyline");
|
assert_eq!(actual, "rustyline");
|
||||||
}
|
}
|
||||||
|
@ -32,7 +42,7 @@ fn save_figures_out_intelligently_where_to_write_out_with_metadata() {
|
||||||
let subject_file = dirs.test().join("cargo_sample.toml");
|
let subject_file = dirs.test().join("cargo_sample.toml");
|
||||||
|
|
||||||
nu!(
|
nu!(
|
||||||
cwd(dirs.root()),
|
cwd: dirs.root(),
|
||||||
"open save_test_1/cargo_sample.toml | inc package.version --minor | save"
|
"open save_test_1/cargo_sample.toml | inc package.version --minor | save"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -47,7 +57,7 @@ fn save_can_write_out_csv() {
|
||||||
let expected_file = dirs.test().join("cargo_sample.csv");
|
let expected_file = dirs.test().join("cargo_sample.csv");
|
||||||
|
|
||||||
nu!(
|
nu!(
|
||||||
dirs.root(),
|
cwd: dirs.root(),
|
||||||
"open {}/cargo_sample.toml | inc package.version --minor | get package | save save_test_2/cargo_sample.csv",
|
"open {}/cargo_sample.toml | inc package.version --minor | get package | save save_test_2/cargo_sample.csv",
|
||||||
dirs.formats()
|
dirs.formats()
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
mod helpers;
|
mod helpers;
|
||||||
|
|
||||||
use helpers::in_directory as cwd;
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn external_command() {
|
fn external_command() {
|
||||||
let actual = nu!(cwd("tests/fixtures"), "echo 1");
|
let actual = nu!(
|
||||||
|
cwd: "tests/fixtures",
|
||||||
|
"echo 1"
|
||||||
|
);
|
||||||
|
|
||||||
assert!(actual.contains("1"));
|
assert!(actual.contains("1"));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
mod helpers;
|
mod helpers;
|
||||||
|
|
||||||
use h::{in_directory as cwd, Playground, Stub::*};
|
use helpers::{Playground, Stub::*};
|
||||||
use helpers as h;
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn can_only_apply_one() {
|
fn can_only_apply_one() {
|
||||||
let actual = nu_error!(
|
let actual = nu_error!(
|
||||||
cwd("tests/fixtures/formats"),
|
cwd: "tests/fixtures/formats",
|
||||||
"open cargo_sample.toml | first 1 | inc package.version --major --minor"
|
"open cargo_sample.toml | first 1 | inc package.version --major --minor"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -26,7 +25,7 @@ fn by_one_with_field_passed() {
|
||||||
)]);
|
)]);
|
||||||
|
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd(dirs.test()),
|
cwd: dirs.test(),
|
||||||
"open sample.toml | inc package.edition | get package.edition | echo $it"
|
"open sample.toml | inc package.edition | get package.edition | echo $it"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -47,7 +46,7 @@ fn by_one_with_no_field_passed() {
|
||||||
)]);
|
)]);
|
||||||
|
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd(dirs.test()),
|
cwd: dirs.test(),
|
||||||
"open sample.toml | get package.contributors | inc | echo $it"
|
"open sample.toml | get package.contributors | inc | echo $it"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -68,7 +67,7 @@ fn semversion_major_inc() {
|
||||||
)]);
|
)]);
|
||||||
|
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd(dirs.test()),
|
cwd: dirs.test(),
|
||||||
"open sample.toml | inc package.version --major | get package.version | echo $it"
|
"open sample.toml | inc package.version --major | get package.version | echo $it"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -89,7 +88,7 @@ fn semversion_minor_inc() {
|
||||||
)]);
|
)]);
|
||||||
|
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd(dirs.test()),
|
cwd: dirs.test(),
|
||||||
"open sample.toml | inc package.version --minor | get package.version | echo $it"
|
"open sample.toml | inc package.version --minor | get package.version | echo $it"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -110,7 +109,7 @@ fn semversion_patch_inc() {
|
||||||
)]);
|
)]);
|
||||||
|
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd(dirs.test()),
|
cwd: dirs.test(),
|
||||||
"open sample.toml | inc package.version --patch | get package.version | echo $it"
|
"open sample.toml | inc package.version --patch | get package.version | echo $it"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -131,7 +130,7 @@ fn semversion_without_passing_field() {
|
||||||
)]);
|
)]);
|
||||||
|
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd(dirs.test()),
|
cwd: dirs.test(),
|
||||||
"open sample.toml | get package.version | inc --patch | echo $it"
|
"open sample.toml | get package.version | inc --patch | echo $it"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
mod helpers;
|
mod helpers;
|
||||||
|
|
||||||
use h::{in_directory as cwd, Playground, Stub::*};
|
|
||||||
use helpers as h;
|
use helpers as h;
|
||||||
|
use h::{Playground, Stub::*};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn can_only_apply_one() {
|
fn can_only_apply_one() {
|
||||||
let actual = nu_error!(
|
let actual = nu_error!(
|
||||||
cwd("tests/fixtures/formats"),
|
cwd: "tests/fixtures/formats",
|
||||||
"open caco3_plastics.csv | first 1 | str origin --downcase --upcase"
|
"open caco3_plastics.csv | first 1 | str origin --downcase --upcase"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ fn acts_without_passing_field() {
|
||||||
)]);
|
)]);
|
||||||
|
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd(dirs.test()),
|
cwd: dirs.test(),
|
||||||
"open sample.yml | get environment.global.PROJECT_NAME | str --upcase | echo $it"
|
"open sample.yml | get environment.global.PROJECT_NAME | str --upcase | echo $it"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ fn downcases() {
|
||||||
)]);
|
)]);
|
||||||
|
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd(dirs.test()),
|
cwd: dirs.test(),
|
||||||
"open sample.toml | str dependency.name --downcase | get dependency.name | echo $it"
|
"open sample.toml | str dependency.name --downcase | get dependency.name | echo $it"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ fn upcases() {
|
||||||
)]);
|
)]);
|
||||||
|
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd(dirs.test()),
|
cwd: dirs.test(),
|
||||||
"open sample.toml | str package.name --upcase | get package.name | echo $it"
|
"open sample.toml | str package.name --upcase | get package.name | echo $it"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ fn upcases() {
|
||||||
#[test]
|
#[test]
|
||||||
fn converts_to_int() {
|
fn converts_to_int() {
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd("tests/fixtures/formats"), h::pipeline(
|
cwd: "tests/fixtures/formats", h::pipeline(
|
||||||
r#"
|
r#"
|
||||||
open caco3_plastics.csv
|
open caco3_plastics.csv
|
||||||
| first 1
|
| first 1
|
||||||
|
@ -108,7 +108,7 @@ fn replaces() {
|
||||||
)]);
|
)]);
|
||||||
|
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd(dirs.test()), h::pipeline(
|
cwd: dirs.test(), h::pipeline(
|
||||||
r#"
|
r#"
|
||||||
open sample.toml
|
open sample.toml
|
||||||
| str package.name --replace wykittenshell
|
| str package.name --replace wykittenshell
|
||||||
|
@ -134,7 +134,7 @@ fn find_and_replaces() {
|
||||||
)]);
|
)]);
|
||||||
|
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd(dirs.test()), h::pipeline(
|
cwd: dirs.test(), h::pipeline(
|
||||||
r#"
|
r#"
|
||||||
open sample.toml
|
open sample.toml
|
||||||
| str fortune.teller.phone --find-replace KATZ "5289"
|
| str fortune.teller.phone --find-replace KATZ "5289"
|
||||||
|
@ -160,7 +160,7 @@ fn find_and_replaces_without_passing_field() {
|
||||||
)]);
|
)]);
|
||||||
|
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd(dirs.test()), h::pipeline(
|
cwd: dirs.test(), h::pipeline(
|
||||||
r#"
|
r#"
|
||||||
open sample.toml
|
open sample.toml
|
||||||
| get fortune.teller.phone
|
| get fortune.teller.phone
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
mod helpers;
|
mod helpers;
|
||||||
|
|
||||||
use helpers::{in_directory as cwd, Playground, Stub::*};
|
|
||||||
use helpers as h;
|
use helpers as h;
|
||||||
|
use helpers::{Playground, Stub::*};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn can_convert_table_to_csv_text_and_from_csv_text_back_into_table() {
|
fn can_convert_table_to_csv_text_and_from_csv_text_back_into_table() {
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd("tests/fixtures/formats"),
|
cwd: "tests/fixtures/formats",
|
||||||
"open caco3_plastics.csv | to-csv | from-csv | first 1 | get origin | echo $it"
|
"open caco3_plastics.csv | to-csv | from-csv | first 1 | get origin | echo $it"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ fn converts_structured_table_to_csv_text() {
|
||||||
)]);
|
)]);
|
||||||
|
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd(dirs.test()), h::pipeline(
|
cwd: dirs.test(), h::pipeline(
|
||||||
r#"
|
r#"
|
||||||
open csv_text_sample.txt
|
open csv_text_sample.txt
|
||||||
| lines
|
| lines
|
||||||
|
@ -58,7 +58,7 @@ fn converts_structured_table_to_csv_text_skipping_headers_after_conversion() {
|
||||||
)]);
|
)]);
|
||||||
|
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd(dirs.test()), h::pipeline(
|
cwd: dirs.test(), h::pipeline(
|
||||||
r#"
|
r#"
|
||||||
open csv_text_sample.txt
|
open csv_text_sample.txt
|
||||||
| lines
|
| lines
|
||||||
|
@ -88,7 +88,7 @@ fn converts_from_csv_text_to_structured_table() {
|
||||||
)]);
|
)]);
|
||||||
|
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd(dirs.test()), h::pipeline(
|
cwd: dirs.test(), h::pipeline(
|
||||||
r#"
|
r#"
|
||||||
open los_tres_amigos.txt
|
open los_tres_amigos.txt
|
||||||
| from-csv
|
| from-csv
|
||||||
|
@ -118,7 +118,7 @@ fn converts_from_csv_text_skipping_headers_to_structured_table() {
|
||||||
)]);
|
)]);
|
||||||
|
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd(dirs.test()), h::pipeline(
|
cwd: dirs.test(), h::pipeline(
|
||||||
r#"
|
r#"
|
||||||
open los_tres_amigos.txt
|
open los_tres_amigos.txt
|
||||||
| from-csv --headerless
|
| from-csv --headerless
|
||||||
|
@ -136,7 +136,7 @@ fn converts_from_csv_text_skipping_headers_to_structured_table() {
|
||||||
#[test]
|
#[test]
|
||||||
fn can_convert_table_to_json_text_and_from_json_text_back_into_table() {
|
fn can_convert_table_to_json_text_and_from_json_text_back_into_table() {
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd("tests/fixtures/formats"), h::pipeline(
|
cwd: "tests/fixtures/formats", h::pipeline(
|
||||||
r#"
|
r#"
|
||||||
open sgml_description.json
|
open sgml_description.json
|
||||||
| to-json
|
| to-json
|
||||||
|
@ -168,7 +168,7 @@ fn converts_from_json_text_to_structured_table() {
|
||||||
)]);
|
)]);
|
||||||
|
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd(dirs.test()),
|
cwd: dirs.test(),
|
||||||
"open katz.txt | from-json | get katz | get rusty_luck | sum | echo $it"
|
"open katz.txt | from-json | get katz | get rusty_luck | sum | echo $it"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -192,7 +192,7 @@ fn converts_from_json_text_recognizing_objects_independendtly_to_structured_tabl
|
||||||
)]);
|
)]);
|
||||||
|
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd(dirs.test()), h::pipeline(
|
cwd: dirs.test(), h::pipeline(
|
||||||
r#"
|
r#"
|
||||||
open katz.txt
|
open katz.txt
|
||||||
| from-json --objects
|
| from-json --objects
|
||||||
|
@ -219,7 +219,7 @@ fn converts_structured_table_to_json_text() {
|
||||||
)]);
|
)]);
|
||||||
|
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd(dirs.test()), h::pipeline(
|
cwd: dirs.test(), h::pipeline(
|
||||||
r#"
|
r#"
|
||||||
open sample.txt
|
open sample.txt
|
||||||
| lines
|
| lines
|
||||||
|
@ -240,7 +240,7 @@ fn converts_structured_table_to_json_text() {
|
||||||
#[test]
|
#[test]
|
||||||
fn can_convert_json_text_to_bson_and_back_into_table() {
|
fn can_convert_json_text_to_bson_and_back_into_table() {
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd("tests/fixtures/formats"),
|
cwd: "tests/fixtures/formats",
|
||||||
"open sample.bson | to-bson | from-bson | get root | nth 1 | get b | echo $it"
|
"open sample.bson | to-bson | from-bson | get root | nth 1 | get b | echo $it"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -250,7 +250,7 @@ fn can_convert_json_text_to_bson_and_back_into_table() {
|
||||||
#[test]
|
#[test]
|
||||||
fn can_convert_table_to_toml_text_and_from_toml_text_back_into_table() {
|
fn can_convert_table_to_toml_text_and_from_toml_text_back_into_table() {
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd("tests/fixtures/formats"),
|
cwd: "tests/fixtures/formats",
|
||||||
"open cargo_sample.toml | to-toml | from-toml | get package.name | echo $it"
|
"open cargo_sample.toml | to-toml | from-toml | get package.name | echo $it"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -260,7 +260,7 @@ fn can_convert_table_to_toml_text_and_from_toml_text_back_into_table() {
|
||||||
#[test]
|
#[test]
|
||||||
fn can_convert_table_to_yaml_text_and_from_yaml_text_back_into_table() {
|
fn can_convert_table_to_yaml_text_and_from_yaml_text_back_into_table() {
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd("tests/fixtures/formats"), h::pipeline(
|
cwd: "tests/fixtures/formats", h::pipeline(
|
||||||
r#"
|
r#"
|
||||||
open appveyor.yml
|
open appveyor.yml
|
||||||
| to-yaml
|
| to-yaml
|
||||||
|
@ -276,7 +276,7 @@ fn can_convert_table_to_yaml_text_and_from_yaml_text_back_into_table() {
|
||||||
#[test]
|
#[test]
|
||||||
fn can_sort_by_column() {
|
fn can_sort_by_column() {
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd("tests/fixtures/formats"), h::pipeline(
|
cwd: "tests/fixtures/formats", h::pipeline(
|
||||||
r#"
|
r#"
|
||||||
open cargo_sample.toml --raw
|
open cargo_sample.toml --raw
|
||||||
| lines
|
| lines
|
||||||
|
@ -298,7 +298,7 @@ fn can_sort_by_column() {
|
||||||
#[test]
|
#[test]
|
||||||
fn can_split_by_column() {
|
fn can_split_by_column() {
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd("tests/fixtures/formats"), h::pipeline(
|
cwd: "tests/fixtures/formats", h::pipeline(
|
||||||
r#"
|
r#"
|
||||||
open cargo_sample.toml --raw
|
open cargo_sample.toml --raw
|
||||||
| lines
|
| lines
|
||||||
|
@ -317,7 +317,7 @@ fn can_split_by_column() {
|
||||||
#[test]
|
#[test]
|
||||||
fn can_sum() {
|
fn can_sum() {
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd("tests/fixtures/formats"), h::pipeline(
|
cwd: "tests/fixtures/formats", h::pipeline(
|
||||||
r#"
|
r#"
|
||||||
open sgml_description.json
|
open sgml_description.json
|
||||||
| get glossary.GlossDiv.GlossList.GlossEntry.Sections
|
| get glossary.GlossDiv.GlossList.GlossEntry.Sections
|
||||||
|
@ -332,7 +332,7 @@ fn can_sum() {
|
||||||
#[test]
|
#[test]
|
||||||
fn can_filter_by_unit_size_comparison() {
|
fn can_filter_by_unit_size_comparison() {
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd("tests/fixtures/formats"),
|
cwd: "tests/fixtures/formats",
|
||||||
"ls | where size > 1kb | sort-by size | get name | skip 1 | trim | echo $it"
|
"ls | where size > 1kb | sort-by size | get name | skip 1 | trim | echo $it"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -342,7 +342,7 @@ fn can_filter_by_unit_size_comparison() {
|
||||||
#[test]
|
#[test]
|
||||||
fn can_get_last() {
|
fn can_get_last() {
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd("tests/fixtures/formats"),
|
cwd: "tests/fixtures/formats",
|
||||||
"ls | sort-by name | last 1 | get name | trim | echo $it"
|
"ls | sort-by name | last 1 | get name | trim | echo $it"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -352,7 +352,7 @@ fn can_get_last() {
|
||||||
#[test]
|
#[test]
|
||||||
fn can_get_reverse_first() {
|
fn can_get_reverse_first() {
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd("tests/fixtures/formats"),
|
cwd: "tests/fixtures/formats",
|
||||||
"ls | sort-by name | reverse | first 1 | get name | trim | echo $it"
|
"ls | sort-by name | reverse | first 1 | get name | trim | echo $it"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -50,7 +50,7 @@ impl DisplayPath for nu::AbsolutePath {
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! nu {
|
macro_rules! nu {
|
||||||
($cwd:expr, $path:expr, $($part:expr),*) => {{
|
(cwd: $cwd:expr, $path:expr, $($part:expr),*) => {{
|
||||||
use $crate::helpers::DisplayPath;
|
use $crate::helpers::DisplayPath;
|
||||||
|
|
||||||
let path = format!($path, $(
|
let path = format!($path, $(
|
||||||
|
@ -60,6 +60,10 @@ macro_rules! nu {
|
||||||
nu!($cwd, &path)
|
nu!($cwd, &path)
|
||||||
}};
|
}};
|
||||||
|
|
||||||
|
(cwd: $cwd:expr, $path:expr) => {{
|
||||||
|
nu!($cwd, $path)
|
||||||
|
}};
|
||||||
|
|
||||||
($cwd:expr, $path:expr) => {{
|
($cwd:expr, $path:expr) => {{
|
||||||
pub use std::error::Error;
|
pub use std::error::Error;
|
||||||
pub use std::io::prelude::*;
|
pub use std::io::prelude::*;
|
||||||
|
@ -101,7 +105,7 @@ macro_rules! nu {
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! nu_error {
|
macro_rules! nu_error {
|
||||||
($cwd:expr, $path:expr, $($part:expr),*) => {{
|
(cwd: $cwd:expr, $path:expr, $($part:expr),*) => {{
|
||||||
use $crate::helpers::DisplayPath;
|
use $crate::helpers::DisplayPath;
|
||||||
|
|
||||||
let path = format!($path, $(
|
let path = format!($path, $(
|
||||||
|
@ -111,17 +115,22 @@ macro_rules! nu_error {
|
||||||
nu_error!($cwd, &path)
|
nu_error!($cwd, &path)
|
||||||
}};
|
}};
|
||||||
|
|
||||||
|
(cwd: $cwd:expr, $path:expr) => {{
|
||||||
|
nu_error!($cwd, $path)
|
||||||
|
}};
|
||||||
|
|
||||||
($cwd:expr, $commands:expr) => {{
|
($cwd:expr, $path:expr) => {{
|
||||||
use std::io::prelude::*;
|
pub use std::error::Error;
|
||||||
use std::process::{Command, Stdio};
|
pub use std::io::prelude::*;
|
||||||
|
pub use std::process::{Command, Stdio};
|
||||||
|
|
||||||
let commands = &*format!(
|
let commands = &*format!(
|
||||||
"
|
"
|
||||||
cd {}
|
cd {}
|
||||||
{}
|
{}
|
||||||
exit",
|
exit",
|
||||||
$crate::helpers::in_directory($cwd), $commands
|
$crate::helpers::in_directory($cwd),
|
||||||
|
$crate::helpers::DisplayPath::display_path(&$path)
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut process = Command::new(helpers::executable_path())
|
let mut process = Command::new(helpers::executable_path())
|
||||||
|
@ -140,7 +149,6 @@ macro_rules! nu_error {
|
||||||
.expect("couldn't read from stderr");
|
.expect("couldn't read from stderr");
|
||||||
|
|
||||||
let out = String::from_utf8_lossy(&output.stderr);
|
let out = String::from_utf8_lossy(&output.stderr);
|
||||||
|
|
||||||
out.into_owned()
|
out.into_owned()
|
||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
|
@ -345,14 +353,6 @@ pub fn files_exist_at(files: Vec<impl AsRef<Path>>, path: impl AsRef<Path>) -> b
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn file_exists_at(path: impl AsRef<Path>) -> bool {
|
|
||||||
path.as_ref().exists()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn dir_exists_at(path: impl AsRef<Path>) -> bool {
|
|
||||||
path.as_ref().exists()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn delete_directory_at(full_path: &str) {
|
pub fn delete_directory_at(full_path: &str) {
|
||||||
std::fs::remove_dir_all(PathBuf::from(full_path)).expect("can not remove directory");
|
std::fs::remove_dir_all(PathBuf::from(full_path)).expect("can not remove directory");
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
mod helpers;
|
mod helpers;
|
||||||
|
|
||||||
use helpers::{in_directory as cwd};
|
|
||||||
use helpers as h;
|
use helpers as h;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -21,7 +20,7 @@ fn pipeline_helper() {
|
||||||
#[test]
|
#[test]
|
||||||
fn external_num() {
|
fn external_num() {
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd("tests/fixtures/formats"),
|
cwd: "tests/fixtures/formats",
|
||||||
"open sgml_description.json | get glossary.GlossDiv.GlossList.GlossEntry.Height | echo $it"
|
"open sgml_description.json | get glossary.GlossDiv.GlossList.GlossEntry.Height | echo $it"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -30,7 +29,10 @@ fn external_num() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn external_has_correct_quotes() {
|
fn external_has_correct_quotes() {
|
||||||
let actual = nu!(cwd("."), r#"echo "hello world""#);
|
let actual = nu!(
|
||||||
|
cwd: ".",
|
||||||
|
r#"echo "hello world""#
|
||||||
|
);
|
||||||
|
|
||||||
let actual = h::normalize_string(&actual);
|
let actual = h::normalize_string(&actual);
|
||||||
|
|
||||||
|
@ -40,9 +42,14 @@ fn external_has_correct_quotes() {
|
||||||
#[test]
|
#[test]
|
||||||
fn add_plugin() {
|
fn add_plugin() {
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd("tests/fixtures/formats"),
|
cwd: "tests/fixtures/formats", h::pipeline(
|
||||||
r#"open cargo_sample.toml | add dev-dependencies.newdep "1" | get dev-dependencies.newdep | echo $it"#
|
r#"
|
||||||
);
|
open cargo_sample.toml
|
||||||
|
| add dev-dependencies.newdep "1"
|
||||||
|
| get dev-dependencies.newdep
|
||||||
|
| echo $it
|
||||||
|
"#
|
||||||
|
));
|
||||||
|
|
||||||
assert_eq!(actual, "1");
|
assert_eq!(actual, "1");
|
||||||
}
|
}
|
||||||
|
@ -50,9 +57,14 @@ fn add_plugin() {
|
||||||
#[test]
|
#[test]
|
||||||
fn edit_plugin() {
|
fn edit_plugin() {
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd("tests/fixtures/formats"),
|
cwd: "tests/fixtures/formats", h::pipeline(
|
||||||
r#"open cargo_sample.toml | edit dev-dependencies.pretty_assertions "7" | get dev-dependencies.pretty_assertions | echo $it"#
|
r#"
|
||||||
);
|
open cargo_sample.toml
|
||||||
|
| edit dev-dependencies.pretty_assertions "7"
|
||||||
|
| get dev-dependencies.pretty_assertions
|
||||||
|
| echo $it
|
||||||
|
"#
|
||||||
|
));
|
||||||
|
|
||||||
assert_eq!(actual, "7");
|
assert_eq!(actual, "7");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue