Merge pull request #522 from androbtech/readability

Readability improvement.
This commit is contained in:
Andrés N. Robalino 2019-08-29 01:56:39 -05:00 committed by GitHub
commit f050908084
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 312 additions and 239 deletions

View File

@ -1,10 +1,11 @@
mod helpers;
use helpers::in_directory as cwd;
#[test]
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("directory not found"));

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![

View File

@ -1,8 +1,9 @@
mod helpers;
use h::{in_directory as cwd, Playground, Stub::*};
use helpers as h;
use std::path::{Path, PathBuf};
use helpers::{Playground, Stub::*};
use std::path::Path;
#[test]
fn knows_the_filesystems_entered() {
@ -28,47 +29,47 @@ fn knows_the_filesystems_entered() {
let expected_recycled = expected.join("recycled");
nu!(
cwd(dirs.test()),
cwd: dirs.test(),
r#"
enter expected
mkdir recycled
enter ../red_pill
mv jonathan.nu ../expected
enter ../blue_pill
cp *.nxt ../expected/recycled
p
p
mv ../red_pill/yehuda.nu .
n
mv andres.nu ../expected/andres.nu
exit
cd ..
rm red_pill --recursive
exit
n
rm blue_pill --recursive
exit
"#
enter expected
mkdir recycled
enter ../red_pill
mv jonathan.nu ../expected
enter ../blue_pill
cp *.nxt ../expected/recycled
p
p
mv ../red_pill/yehuda.nu .
n
mv andres.nu ../expected/andres.nu
exit
cd ..
rm red_pill --recursive
exit
n
rm blue_pill --recursive
exit
"#
);
assert!(!h::dir_exists_at(PathBuf::from(red_pill_dir)));
assert!(!red_pill_dir.exists());
assert!(h::files_exist_at(
vec![
Path::new("andres.nu"),
Path::new("jonathan.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(
vec![
Path::new("bash.nxt"),
Path::new("korn.nxt"),
Path::new("powedsh.nxt"),
],
PathBuf::from(&expected_recycled)
expected_recycled
));
})
}

View File

@ -1,7 +1,7 @@
mod helpers;
use h::{in_directory as cwd, Playground, Stub::*};
use helpers as h;
use helpers::{Playground, Stub::*};
#[test]
fn ls_lists_regular_files() {
@ -14,17 +14,17 @@ fn ls_lists_regular_files() {
]);
let actual = nu!(
cwd(dirs.test()), h::pipeline(
r#"
ls
| get name
| lines
| split-column "."
| get Column2
| str --to-int
| sum
| echo $it
"#
cwd: dirs.test(), h::pipeline(
r#"
ls
| get name
| lines
| split-column "."
| get Column2
| str --to-int
| sum
| echo $it
"#
));
assert_eq!(actual, "30");
@ -43,17 +43,17 @@ fn ls_lists_regular_files_using_asterisk_wildcard() {
]);
let actual = nu!(
cwd(dirs.test()), h::pipeline(
r#"
ls *.txt
| get name
| lines
| split-column "."
| get Column2
| str --to-int
| sum
| echo $it
"#
cwd: dirs.test(), h::pipeline(
r#"
ls *.txt
| get name
| lines
| split-column "."
| get Column2
| str --to-int
| sum
| echo $it
"#
));
assert_eq!(actual, "3");
@ -72,17 +72,17 @@ fn ls_lists_regular_files_using_question_mark_wildcard() {
]);
let actual = nu!(
cwd(dirs.test()), h::pipeline(
r#"
ls *.??.txt
| get name
| lines
| split-column "."
| get Column2
| str --to-int
| sum
| echo $it
"#
cwd: dirs.test(), h::pipeline(
r#"
ls *.??.txt
| get name
| lines
| split-column "."
| get Column2
| str --to-int
| sum
| echo $it
"#
));
assert_eq!(actual, "30");

View File

@ -1,24 +1,31 @@
mod helpers;
use h::{in_directory as cwd, Playground};
use helpers as h;
use std::path::{Path, PathBuf};
use helpers::Playground;
use std::path::Path;
#[test]
fn creates_directory() {
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");
assert!(h::dir_exists_at(expected));
assert!(expected.exists());
})
}
#[test]
fn accepts_and_creates_directories() {
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(
vec![Path::new("dir_1"), Path::new("dir_2"), Path::new("dir_3")],
@ -30,11 +37,13 @@ fn accepts_and_creates_directories() {
#[test]
fn creates_intermediary_directories() {
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());
expected.push("some_folder/another/deeper_one");
let expected = dirs.test().join("some_folder/another/deeper_one");
assert!(h::dir_exists_at(expected));
assert!(expected.exists());
})
}

View File

@ -1,7 +1,7 @@
mod helpers;
use h::{in_directory as cwd, Playground, Stub::*};
use helpers as h;
use helpers::{Playground, Stub::*};
#[test]
fn moves_a_file() {
@ -13,10 +13,13 @@ fn moves_a_file() {
let original = dirs.test().join("andres.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!(h::file_exists_at(expected));
assert!(!original.exists());
assert!(expected.exists());
})
}
@ -32,10 +35,13 @@ fn overwrites_if_moving_to_existing_file() {
let original = dirs.test().join("andres.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!(h::file_exists_at(expected));
assert!(!original.exists());
assert!(expected.exists());
})
}
@ -47,10 +53,13 @@ fn moves_a_directory() {
let original_dir = dirs.test().join("empty_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!(h::dir_exists_at(expected));
assert!(!original_dir.exists());
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 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!(h::file_exists_at(expected));
assert!(!original_dir.exists());
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 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!(h::file_exists_at(expected));
assert!(!original_dir.exists());
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");
nu!(
cwd(dirs.test()),
cwd: dirs.test(),
"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()
.join("expected/this_dir_exists_now/los_tres_amigos");
assert!(!h::dir_exists_at(original_dir));
assert!(h::file_exists_at(expected));
assert!(!original_dir.exists());
assert!(expected.exists());
})
}
@ -135,7 +150,10 @@ fn moves_using_path_with_wildcard() {
let work_dir = dirs.test().join("work_dir");
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(
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 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(
vec!["arepa.txt", "empanada.txt", "taquiza.txt",],
expected

View File

@ -1,7 +1,7 @@
mod helpers;
use helpers::{in_directory as cwd, Playground, Stub::*};
use helpers as h;
use helpers::{Playground, Stub::*};
#[test]
fn recognizes_csv() {
@ -18,7 +18,7 @@ fn recognizes_csv() {
)]);
let actual = nu!(
cwd(dirs.test()), h::pipeline(
cwd: dirs.test(), h::pipeline(
r#"
open nu.zion.csv
| where author == "Andres N. Robalino"
@ -34,7 +34,7 @@ fn recognizes_csv() {
#[test]
fn open_can_parse_bson_1() {
let actual = nu!(
cwd("tests/fixtures/formats"),
cwd: "tests/fixtures/formats",
"open sample.bson | get root | nth 0 | get b | echo $it"
);
@ -44,16 +44,16 @@ fn open_can_parse_bson_1() {
#[test]
fn open_can_parse_bson_2() {
let actual = nu!(
cwd("tests/fixtures/formats"), h::pipeline(
r#"
open sample.bson
| get root
| nth 6
| get b
| get '$binary_subtype'
| echo $it
"#
));
cwd: "tests/fixtures/formats", h::pipeline(
r#"
open sample.bson
| get root
| nth 6
| get b
| get '$binary_subtype'
| echo $it
"#
));
assert_eq!(actual, "function");
}
@ -61,7 +61,7 @@ fn open_can_parse_bson_2() {
#[test]
fn open_can_parse_toml() {
let actual = nu!(
cwd("tests/fixtures/formats"),
cwd: "tests/fixtures/formats",
"open cargo_sample.toml | get package.edition | echo $it"
);
@ -71,7 +71,7 @@ fn open_can_parse_toml() {
#[test]
fn open_can_parse_json() {
let actual = nu!(
cwd("tests/fixtures/formats"), h::pipeline(
cwd: "tests/fixtures/formats", h::pipeline(
r#"
open sgml_description.json
| get glossary.GlossDiv.GlossList.GlossEntry.GlossSee
@ -85,7 +85,7 @@ fn open_can_parse_json() {
#[test]
fn open_can_parse_xml() {
let actual = nu!(
cwd("tests/fixtures/formats"),
cwd: "tests/fixtures/formats",
"open jonathan.xml | get rss.channel.item.link | echo $it"
);
@ -98,7 +98,7 @@ fn open_can_parse_xml() {
#[test]
fn open_can_parse_ini() {
let actual = nu!(
cwd("tests/fixtures/formats"),
cwd: "tests/fixtures/formats",
"open sample.ini | get SectionOne.integer | echo $it"
);
@ -108,7 +108,7 @@ fn open_can_parse_ini() {
#[test]
fn open_can_parse_utf16_ini() {
let actual = nu!(
cwd("tests/fixtures/formats"),
cwd: "tests/fixtures/formats",
"open utf16.ini | get .ShellClassInfo | get IconIndex | echo $it"
);
@ -118,7 +118,7 @@ fn open_can_parse_utf16_ini() {
#[test]
fn errors_if_file_not_found() {
let actual = nu_error!(
cwd("tests/fixtures/formats"),
cwd: "tests/fixtures/formats",
"open i_dont_exist.txt | echo $it"
);

View File

@ -1,7 +1,7 @@
mod helpers;
use h::{in_directory as cwd, Playground, Stub::*};
use helpers as h;
use helpers::{Playground, Stub::*};
#[test]
fn rm_removes_a_file() {
@ -10,11 +10,14 @@ fn rm_removes_a_file() {
.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");
assert!(!h::file_exists_at(path));
assert!(!path.exists());
})
}
@ -38,7 +41,10 @@ fn rm_removes_files_with_wildcard() {
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(
vec![
@ -76,7 +82,10 @@ fn rm_removes_deeply_nested_directories_with_wildcard_and_recursive_flag() {
EmptyFile("baseline_parse_tokens.rs")
]);
nu!(cwd(dirs.test()), "rm src/* --recursive");
nu!(
cwd: dirs.test(),
"rm src/* --recursive"
);
assert!(!h::files_exist_at(
vec!["src/parser/parse", "src/parser/hir"],
@ -88,9 +97,12 @@ fn rm_removes_deeply_nested_directories_with_wildcard_and_recursive_flag() {
#[test]
fn rm_removes_directory_contents_without_recursive_flag_if_empty() {
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")
]);
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!(
cwd(dirs.root()),
cwd: dirs.root(),
"rm rm_test_6"
);
assert!(h::file_exists_at(dirs.test()));
assert!(dirs.test().exists());
assert!(actual.contains("is a directory"));
})
}
@ -130,7 +145,10 @@ fn rm_errors_if_attempting_to_delete_a_directory_with_content_without_recursive_
#[test]
fn rm_errors_if_attempting_to_delete_single_dot_as_argument() {
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"));
})
@ -139,7 +157,10 @@ fn rm_errors_if_attempting_to_delete_single_dot_as_argument() {
#[test]
fn rm_errors_if_attempting_to_delete_two_dot_as_argument() {
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"));
})

View File

@ -1,14 +1,24 @@
mod helpers;
use h::{in_directory as cwd, Playground, Stub::*};
use helpers as h;
use helpers::{Playground, Stub::*};
#[test]
fn lines() {
let actual = nu!(
cwd("tests/fixtures/formats"),
r#"open cargo_sample.toml --raw | lines | skip-while $it != "[dependencies]" | skip 1 | first 1 | split-column "=" | get Column1 | trim | echo $it"#
);
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
"#
));
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");
nu!(
cwd(dirs.root()),
cwd: dirs.root(),
"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");
nu!(
dirs.root(),
cwd: dirs.root(),
"open {}/cargo_sample.toml | inc package.version --minor | get package | save save_test_2/cargo_sample.csv",
dirs.formats()
);

View File

@ -1,10 +1,11 @@
mod helpers;
use helpers::in_directory as cwd;
#[test]
fn external_command() {
let actual = nu!(cwd("tests/fixtures"), "echo 1");
let actual = nu!(
cwd: "tests/fixtures",
"echo 1"
);
assert!(actual.contains("1"));
}

View File

@ -1,12 +1,11 @@
mod helpers;
use h::{in_directory as cwd, Playground, Stub::*};
use helpers as h;
use helpers::{Playground, Stub::*};
#[test]
fn can_only_apply_one() {
let actual = nu_error!(
cwd("tests/fixtures/formats"),
cwd: "tests/fixtures/formats",
"open cargo_sample.toml | first 1 | inc package.version --major --minor"
);
@ -26,7 +25,7 @@ fn by_one_with_field_passed() {
)]);
let actual = nu!(
cwd(dirs.test()),
cwd: dirs.test(),
"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!(
cwd(dirs.test()),
cwd: dirs.test(),
"open sample.toml | get package.contributors | inc | echo $it"
);
@ -68,7 +67,7 @@ fn semversion_major_inc() {
)]);
let actual = nu!(
cwd(dirs.test()),
cwd: dirs.test(),
"open sample.toml | inc package.version --major | get package.version | echo $it"
);
@ -89,7 +88,7 @@ fn semversion_minor_inc() {
)]);
let actual = nu!(
cwd(dirs.test()),
cwd: dirs.test(),
"open sample.toml | inc package.version --minor | get package.version | echo $it"
);
@ -110,7 +109,7 @@ fn semversion_patch_inc() {
)]);
let actual = nu!(
cwd(dirs.test()),
cwd: dirs.test(),
"open sample.toml | inc package.version --patch | get package.version | echo $it"
);
@ -131,7 +130,7 @@ fn semversion_without_passing_field() {
)]);
let actual = nu!(
cwd(dirs.test()),
cwd: dirs.test(),
"open sample.toml | get package.version | inc --patch | echo $it"
);

View File

@ -1,12 +1,12 @@
mod helpers;
use h::{in_directory as cwd, Playground, Stub::*};
use helpers as h;
use h::{Playground, Stub::*};
#[test]
fn can_only_apply_one() {
let actual = nu_error!(
cwd("tests/fixtures/formats"),
cwd: "tests/fixtures/formats",
"open caco3_plastics.csv | first 1 | str origin --downcase --upcase"
);
@ -28,7 +28,7 @@ fn acts_without_passing_field() {
)]);
let actual = nu!(
cwd(dirs.test()),
cwd: dirs.test(),
"open sample.yml | get environment.global.PROJECT_NAME | str --upcase | echo $it"
);
@ -49,7 +49,7 @@ fn downcases() {
)]);
let actual = nu!(
cwd(dirs.test()),
cwd: dirs.test(),
"open sample.toml | str dependency.name --downcase | get dependency.name | echo $it"
);
@ -70,7 +70,7 @@ fn upcases() {
)]);
let actual = nu!(
cwd(dirs.test()),
cwd: dirs.test(),
"open sample.toml | str package.name --upcase | get package.name | echo $it"
);
@ -81,15 +81,15 @@ fn upcases() {
#[test]
fn converts_to_int() {
let actual = nu!(
cwd("tests/fixtures/formats"), h::pipeline(
r#"
open caco3_plastics.csv
| first 1
| str tariff_item --to-int
| where tariff_item == 2509000000
| get tariff_item
| echo $it
"#
cwd: "tests/fixtures/formats", h::pipeline(
r#"
open caco3_plastics.csv
| first 1
| str tariff_item --to-int
| where tariff_item == 2509000000
| get tariff_item
| echo $it
"#
));
assert_eq!(actual, "2509000000");
@ -108,7 +108,7 @@ fn replaces() {
)]);
let actual = nu!(
cwd(dirs.test()), h::pipeline(
cwd: dirs.test(), h::pipeline(
r#"
open sample.toml
| str package.name --replace wykittenshell
@ -134,7 +134,7 @@ fn find_and_replaces() {
)]);
let actual = nu!(
cwd(dirs.test()), h::pipeline(
cwd: dirs.test(), h::pipeline(
r#"
open sample.toml
| str fortune.teller.phone --find-replace KATZ "5289"
@ -160,7 +160,7 @@ fn find_and_replaces_without_passing_field() {
)]);
let actual = nu!(
cwd(dirs.test()), h::pipeline(
cwd: dirs.test(), h::pipeline(
r#"
open sample.toml
| get fortune.teller.phone

View File

@ -1,12 +1,12 @@
mod helpers;
use helpers::{in_directory as cwd, Playground, Stub::*};
use helpers as h;
use helpers::{Playground, Stub::*};
#[test]
fn can_convert_table_to_csv_text_and_from_csv_text_back_into_table() {
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"
);
@ -27,7 +27,7 @@ fn converts_structured_table_to_csv_text() {
)]);
let actual = nu!(
cwd(dirs.test()), h::pipeline(
cwd: dirs.test(), h::pipeline(
r#"
open csv_text_sample.txt
| lines
@ -58,7 +58,7 @@ fn converts_structured_table_to_csv_text_skipping_headers_after_conversion() {
)]);
let actual = nu!(
cwd(dirs.test()), h::pipeline(
cwd: dirs.test(), h::pipeline(
r#"
open csv_text_sample.txt
| lines
@ -88,7 +88,7 @@ fn converts_from_csv_text_to_structured_table() {
)]);
let actual = nu!(
cwd(dirs.test()), h::pipeline(
cwd: dirs.test(), h::pipeline(
r#"
open los_tres_amigos.txt
| from-csv
@ -118,7 +118,7 @@ fn converts_from_csv_text_skipping_headers_to_structured_table() {
)]);
let actual = nu!(
cwd(dirs.test()), h::pipeline(
cwd: dirs.test(), h::pipeline(
r#"
open los_tres_amigos.txt
| from-csv --headerless
@ -136,7 +136,7 @@ fn converts_from_csv_text_skipping_headers_to_structured_table() {
#[test]
fn can_convert_table_to_json_text_and_from_json_text_back_into_table() {
let actual = nu!(
cwd("tests/fixtures/formats"), h::pipeline(
cwd: "tests/fixtures/formats", h::pipeline(
r#"
open sgml_description.json
| to-json
@ -168,7 +168,7 @@ fn converts_from_json_text_to_structured_table() {
)]);
let actual = nu!(
cwd(dirs.test()),
cwd: dirs.test(),
"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!(
cwd(dirs.test()), h::pipeline(
cwd: dirs.test(), h::pipeline(
r#"
open katz.txt
| from-json --objects
@ -219,7 +219,7 @@ fn converts_structured_table_to_json_text() {
)]);
let actual = nu!(
cwd(dirs.test()), h::pipeline(
cwd: dirs.test(), h::pipeline(
r#"
open sample.txt
| lines
@ -240,7 +240,7 @@ fn converts_structured_table_to_json_text() {
#[test]
fn can_convert_json_text_to_bson_and_back_into_table() {
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"
);
@ -250,7 +250,7 @@ fn can_convert_json_text_to_bson_and_back_into_table() {
#[test]
fn can_convert_table_to_toml_text_and_from_toml_text_back_into_table() {
let actual = nu!(
cwd("tests/fixtures/formats"),
cwd: "tests/fixtures/formats",
"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]
fn can_convert_table_to_yaml_text_and_from_yaml_text_back_into_table() {
let actual = nu!(
cwd("tests/fixtures/formats"), h::pipeline(
cwd: "tests/fixtures/formats", h::pipeline(
r#"
open appveyor.yml
| to-yaml
@ -276,7 +276,7 @@ fn can_convert_table_to_yaml_text_and_from_yaml_text_back_into_table() {
#[test]
fn can_sort_by_column() {
let actual = nu!(
cwd("tests/fixtures/formats"), h::pipeline(
cwd: "tests/fixtures/formats", h::pipeline(
r#"
open cargo_sample.toml --raw
| lines
@ -298,7 +298,7 @@ fn can_sort_by_column() {
#[test]
fn can_split_by_column() {
let actual = nu!(
cwd("tests/fixtures/formats"), h::pipeline(
cwd: "tests/fixtures/formats", h::pipeline(
r#"
open cargo_sample.toml --raw
| lines
@ -317,7 +317,7 @@ fn can_split_by_column() {
#[test]
fn can_sum() {
let actual = nu!(
cwd("tests/fixtures/formats"), h::pipeline(
cwd: "tests/fixtures/formats", h::pipeline(
r#"
open sgml_description.json
| get glossary.GlossDiv.GlossList.GlossEntry.Sections
@ -332,7 +332,7 @@ fn can_sum() {
#[test]
fn can_filter_by_unit_size_comparison() {
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"
);
@ -342,7 +342,7 @@ fn can_filter_by_unit_size_comparison() {
#[test]
fn can_get_last() {
let actual = nu!(
cwd("tests/fixtures/formats"),
cwd: "tests/fixtures/formats",
"ls | sort-by name | last 1 | get name | trim | echo $it"
);
@ -352,7 +352,7 @@ fn can_get_last() {
#[test]
fn can_get_reverse_first() {
let actual = nu!(
cwd("tests/fixtures/formats"),
cwd: "tests/fixtures/formats",
"ls | sort-by name | reverse | first 1 | get name | trim | echo $it"
);

View File

@ -50,7 +50,7 @@ impl DisplayPath for nu::AbsolutePath {
#[macro_export]
macro_rules! nu {
($cwd:expr, $path:expr, $($part:expr),*) => {{
(cwd: $cwd:expr, $path:expr, $($part:expr),*) => {{
use $crate::helpers::DisplayPath;
let path = format!($path, $(
@ -60,6 +60,10 @@ macro_rules! nu {
nu!($cwd, &path)
}};
(cwd: $cwd:expr, $path:expr) => {{
nu!($cwd, $path)
}};
($cwd:expr, $path:expr) => {{
pub use std::error::Error;
pub use std::io::prelude::*;
@ -101,7 +105,7 @@ macro_rules! nu {
#[macro_export]
macro_rules! nu_error {
($cwd:expr, $path:expr, $($part:expr),*) => {{
(cwd: $cwd:expr, $path:expr, $($part:expr),*) => {{
use $crate::helpers::DisplayPath;
let path = format!($path, $(
@ -111,17 +115,22 @@ macro_rules! nu_error {
nu_error!($cwd, &path)
}};
(cwd: $cwd:expr, $path:expr) => {{
nu_error!($cwd, $path)
}};
($cwd:expr, $commands:expr) => {{
use std::io::prelude::*;
use std::process::{Command, Stdio};
($cwd:expr, $path:expr) => {{
pub use std::error::Error;
pub use std::io::prelude::*;
pub use std::process::{Command, Stdio};
let commands = &*format!(
"
cd {}
{}
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())
@ -140,7 +149,6 @@ macro_rules! nu_error {
.expect("couldn't read from stderr");
let out = String::from_utf8_lossy(&output.stderr);
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) {
std::fs::remove_dir_all(PathBuf::from(full_path)).expect("can not remove directory");
}

View File

@ -1,6 +1,5 @@
mod helpers;
use helpers::{in_directory as cwd};
use helpers as h;
#[test]
@ -21,7 +20,7 @@ fn pipeline_helper() {
#[test]
fn external_num() {
let actual = nu!(
cwd("tests/fixtures/formats"),
cwd: "tests/fixtures/formats",
"open sgml_description.json | get glossary.GlossDiv.GlossList.GlossEntry.Height | echo $it"
);
@ -30,7 +29,10 @@ fn external_num() {
#[test]
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);
@ -40,9 +42,14 @@ fn external_has_correct_quotes() {
#[test]
fn add_plugin() {
let actual = nu!(
cwd("tests/fixtures/formats"),
r#"open cargo_sample.toml | add dev-dependencies.newdep "1" | get dev-dependencies.newdep | echo $it"#
);
cwd: "tests/fixtures/formats", h::pipeline(
r#"
open cargo_sample.toml
| add dev-dependencies.newdep "1"
| get dev-dependencies.newdep
| echo $it
"#
));
assert_eq!(actual, "1");
}
@ -50,9 +57,14 @@ fn add_plugin() {
#[test]
fn edit_plugin() {
let actual = nu!(
cwd("tests/fixtures/formats"),
r#"open cargo_sample.toml | edit dev-dependencies.pretty_assertions "7" | get dev-dependencies.pretty_assertions | echo $it"#
);
cwd: "tests/fixtures/formats", h::pipeline(
r#"
open cargo_sample.toml
| edit dev-dependencies.pretty_assertions "7"
| get dev-dependencies.pretty_assertions
| echo $it
"#
));
assert_eq!(actual, "7");
}