More descriptive test playground names for commands other than the basic ones.

This commit is contained in:
Andrés N. Robalino 2019-08-14 15:07:08 -05:00
parent bd71773b5b
commit dfcbaed1c6
5 changed files with 27 additions and 50 deletions

View file

@ -1,15 +1,10 @@
mod helpers; mod helpers;
use helpers::in_directory as cwd; use helpers::in_directory as cwd;
use helpers::Playground;
#[test] #[test]
fn cd_directory_not_found() { fn cd_directory_not_found() {
let sandbox = Playground::setup_for("cd_directory_not_found_test").test_dir_name(); nu_error!(output, cwd("tests/fixtures"), "cd dir_that_does_not_exist");
let full_path = format!("{}/{}", Playground::root(), sandbox);
nu_error!(output, cwd(&full_path), "cd dir_that_does_not_exist");
assert!(output.contains("dir_that_does_not_exist")); assert!(output.contains("dir_that_does_not_exist"));
assert!(output.contains("directory not found")); assert!(output.contains("directory not found"));

View file

@ -6,7 +6,7 @@ use std::path::PathBuf;
#[test] #[test]
fn creates_directory() { fn creates_directory() {
let sandbox = Playground::setup_for("mkdir_test").test_dir_name(); let sandbox = Playground::setup_for("mkdir_test_1").test_dir_name();
let full_path = format!("{}/{}", Playground::root(), sandbox); let full_path = format!("{}/{}", Playground::root(), sandbox);

View file

@ -125,7 +125,7 @@ fn save_figures_out_intelligently_where_to_write_out_with_metadata() {
#[test] #[test]
fn save_can_write_out_csv() { fn save_can_write_out_csv() {
let sandbox = Playground::setup_for("save_test").test_dir_name(); let sandbox = Playground::setup_for("save_writes_out_csv_test").test_dir_name();
let full_path = format!("{}/{}", Playground::root(), sandbox); let full_path = format!("{}/{}", Playground::root(), sandbox);
let expected_file = format!("{}/{}", full_path, "cargo_sample.csv"); let expected_file = format!("{}/{}", full_path, "cargo_sample.csv");
@ -133,7 +133,7 @@ fn save_can_write_out_csv() {
nu!( nu!(
_output, _output,
cwd(&Playground::root()), cwd(&Playground::root()),
"open ../formats/cargo_sample.toml | inc package.version --minor | get package | save save_test/cargo_sample.csv" "open ../formats/cargo_sample.toml | inc package.version --minor | get package | save save_writes_out_csv_test/cargo_sample.csv"
); );
let actual = h::file_contents(&expected_file); let actual = h::file_contents(&expected_file);
@ -142,14 +142,14 @@ fn save_can_write_out_csv() {
#[test] #[test]
fn rm_removes_a_file() { fn rm_removes_a_file() {
let sandbox = Playground::setup_for("rm_test") let sandbox = Playground::setup_for("rm_regular_file_test")
.with_files(vec![EmptyFile("i_will_be_deleted.txt")]) .with_files(vec![EmptyFile("i_will_be_deleted.txt")])
.test_dir_name(); .test_dir_name();
nu!( nu!(
_output, _output,
cwd(&Playground::root()), cwd(&Playground::root()),
"rm rm_test/i_will_be_deleted.txt" "rm rm_regular_file_test/i_will_be_deleted.txt"
); );
let path = &format!( let path = &format!(
@ -180,7 +180,7 @@ fn rm_removes_files_with_wildcard() {
src/parser/hir/baseline_parse_tokens.rs src/parser/hir/baseline_parse_tokens.rs
"#; "#;
let sandbox = Playground::setup_for("rm_test_wildcard") let sandbox = Playground::setup_for("rm_wildcard_test")
.within("src") .within("src")
.with_files(vec![ .with_files(vec![
EmptyFile("cli.rs"), EmptyFile("cli.rs"),
@ -210,7 +210,7 @@ fn rm_removes_files_with_wildcard() {
nu!( nu!(
_output, _output,
cwd("tests/fixtures/nuplayground/rm_test_wildcard"), cwd("tests/fixtures/nuplayground/rm_wildcard_test"),
"rm \"src/*/*/*.rs\"" "rm \"src/*/*/*.rs\""
); );
@ -231,7 +231,7 @@ fn rm_removes_files_with_wildcard() {
#[test] #[test]
fn rm_removes_directory_contents_with_recursive_flag() { fn rm_removes_directory_contents_with_recursive_flag() {
let sandbox = Playground::setup_for("rm_test_recursive") let sandbox = Playground::setup_for("rm_directory_removal_recursively_test")
.with_files(vec![ .with_files(vec![
EmptyFile("yehuda.txt"), EmptyFile("yehuda.txt"),
EmptyFile("jonathan.txt"), EmptyFile("jonathan.txt"),
@ -242,7 +242,7 @@ fn rm_removes_directory_contents_with_recursive_flag() {
nu!( nu!(
_output, _output,
cwd("tests/fixtures/nuplayground"), cwd("tests/fixtures/nuplayground"),
"rm rm_test_recursive --recursive" "rm rm_directory_removal_recursively_test --recursive"
); );
let expected = format!("{}/{}", Playground::root(), sandbox); let expected = format!("{}/{}", Playground::root(), sandbox);
@ -252,10 +252,10 @@ fn rm_removes_directory_contents_with_recursive_flag() {
#[test] #[test]
fn rm_errors_if_attempting_to_delete_a_directory_without_recursive_flag() { fn rm_errors_if_attempting_to_delete_a_directory_without_recursive_flag() {
let sandbox = Playground::setup_for("rm_test_2").test_dir_name(); let sandbox = Playground::setup_for("rm_prevent_directory_removal_without_flag_test").test_dir_name();
let full_path = format!("{}/{}", Playground::root(), sandbox); let full_path = format!("{}/{}", Playground::root(), sandbox);
nu_error!(output, cwd(&Playground::root()), "rm rm_test_2"); nu_error!(output, cwd(&Playground::root()), "rm rm_prevent_directory_removal_without_flag_test");
assert!(h::file_exists_at(PathBuf::from(full_path))); assert!(h::file_exists_at(PathBuf::from(full_path)));
assert!(output.contains("is a directory")); assert!(output.contains("is a directory"));

View file

@ -16,7 +16,7 @@ fn can_only_apply_one() {
#[test] #[test]
fn regular_field_by_one() { fn regular_field_by_one() {
Playground::setup_for("plugin_inc_test_1") Playground::setup_for("plugin_inc_by_one_test")
.with_files(vec![FileWithContent( .with_files(vec![FileWithContent(
"sample.toml", "sample.toml",
r#" r#"
@ -27,37 +27,16 @@ fn regular_field_by_one() {
nu!( nu!(
output, output,
cwd("tests/fixtures/nuplayground/plugin_inc_test_1"), cwd("tests/fixtures/nuplayground/plugin_inc_by_one_test"),
"open sample.toml | inc package.edition | get package.edition | echo $it" "open sample.toml | inc package.edition | get package.edition | echo $it"
); );
assert_eq!(output, "2019"); assert_eq!(output, "2019");
} }
#[test]
fn by_one_without_passing_field() {
Playground::setup_for("plugin_inc_test_2")
.with_files(vec![FileWithContent(
"sample.toml",
r#"
[package]
contributors = "2"
"#,
)]);
nu!(
output,
cwd("tests/fixtures/nuplayground/plugin_inc_test_2"),
"open sample.toml | get package.contributors | inc | echo $it"
);
assert_eq!(output, "3");
}
#[test] #[test]
fn semversion_major_inc() { fn semversion_major_inc() {
Playground::setup_for("plugin_inc_test_3") Playground::setup_for("plugin_inc_major_semversion_test")
.with_files(vec![FileWithContent( .with_files(vec![FileWithContent(
"sample.toml", "sample.toml",
r#" r#"
@ -68,7 +47,7 @@ fn semversion_major_inc() {
nu!( nu!(
output, output,
cwd("tests/fixtures/nuplayground/plugin_inc_test_3"), cwd("tests/fixtures/nuplayground/plugin_inc_major_semversion_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"
); );
@ -77,7 +56,7 @@ fn semversion_major_inc() {
#[test] #[test]
fn semversion_minor_inc() { fn semversion_minor_inc() {
Playground::setup_for("plugin_inc_test_4") Playground::setup_for("plugin_inc_minor_semversion_test")
.with_files(vec![FileWithContent( .with_files(vec![FileWithContent(
"sample.toml", "sample.toml",
r#" r#"
@ -88,7 +67,7 @@ fn semversion_minor_inc() {
nu!( nu!(
output, output,
cwd("tests/fixtures/nuplayground/plugin_inc_test_4"), cwd("tests/fixtures/nuplayground/plugin_inc_minor_semversion_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"
); );
@ -97,7 +76,7 @@ fn semversion_minor_inc() {
#[test] #[test]
fn semversion_patch_inc() { fn semversion_patch_inc() {
Playground::setup_for("plugin_inc_test_5") Playground::setup_for("plugin_inc_patch_semversion_test")
.with_files(vec![FileWithContent( .with_files(vec![FileWithContent(
"sample.toml", "sample.toml",
r#" r#"
@ -108,7 +87,7 @@ fn semversion_patch_inc() {
nu!( nu!(
output, output,
cwd("tests/fixtures/nuplayground/plugin_inc_test_5"), cwd("tests/fixtures/nuplayground/plugin_inc_patch_semversion_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"
); );
@ -117,7 +96,7 @@ fn semversion_patch_inc() {
#[test] #[test]
fn semversion_without_passing_field() { fn semversion_without_passing_field() {
Playground::setup_for("plugin_inc_test_6") Playground::setup_for("plugin_inc_semversion_without_passing_field_test")
.with_files(vec![FileWithContent( .with_files(vec![FileWithContent(
"sample.toml", "sample.toml",
r#" r#"
@ -128,7 +107,7 @@ fn semversion_without_passing_field() {
nu!( nu!(
output, output,
cwd("tests/fixtures/nuplayground/plugin_inc_test_6"), cwd("tests/fixtures/nuplayground/plugin_inc_semversion_without_passing_field_test"),
"open sample.toml | get package.version | inc --patch | echo $it" "open sample.toml | get package.version | inc --patch | echo $it"
); );

View file

@ -116,8 +116,10 @@ impl Playground {
} }
} }
pub fn cd(&mut self, path: &str) -> &mut Self { pub fn mkdir(&mut self, directory: &str) -> &mut Self {
self.cwd.push(path); self.cwd.push(directory);
std::fs::create_dir_all(&self.cwd).expect("can not create directory");
self.back_to_playground();
self self
} }
@ -148,6 +150,7 @@ impl Playground {
self self
} }
pub fn glob_vec(pattern: &str) -> Vec<PathBuf> { pub fn glob_vec(pattern: &str) -> Vec<PathBuf> {
glob(pattern).unwrap().map(|r| r.unwrap()).collect() glob(pattern).unwrap().map(|r| r.unwrap()).collect()
} }