Command tests (#922)

* WIP command tests

* Finish marking todo tests

* update

* update

* Windows cd test ignoring
This commit is contained in:
JT
2022-02-03 21:01:45 -05:00
committed by GitHub
parent ac0b331f00
commit a008f1aa80
139 changed files with 10298 additions and 348 deletions

View File

@@ -1,142 +0,0 @@
use nu_test_support::fs::{file_contents, Stub::FileWithContent};
use nu_test_support::fs::{AbsolutePath, DisplayPath};
use nu_test_support::pipeline as input;
use nu_test_support::playground::{says, Executable, Playground};
use hamcrest2::assert_that;
use hamcrest2::prelude::*;
#[test]
fn clears_the_configuration() {
Playground::setup("config_clear_test", |dirs, nu| {
let file = AbsolutePath::new(dirs.test().join("config.toml"));
nu.with_config(&file);
nu.with_files(vec![FileWithContent(
"config.toml",
r#"
skip_welcome_message = true
pivot_mode = "arepas"
"#,
)]);
assert!(nu.pipeline("config clear").execute().is_ok());
assert!(file_contents(&file).is_empty());
});
}
#[test]
fn retrieves_config_values() {
Playground::setup("config_get_test", |dirs, nu| {
let file = AbsolutePath::new(dirs.test().join("config.toml"));
nu.with_config(&file);
nu.with_files(vec![FileWithContent(
"config.toml",
r#"
skip_welcome_message = true
[arepa]
colors = ["yellow", "white"]
"#,
)]);
assert_that!(
nu.pipeline("config get arepa.colors.0"),
says().stdout("yellow")
);
})
}
#[test]
fn sets_a_config_value() {
Playground::setup("config_set_test", |dirs, nu| {
let file = AbsolutePath::new(dirs.test().join("config.toml"));
nu.with_config(&file);
nu.with_files(vec![FileWithContent(
"config.toml",
r#"
skip_welcome_message = true
[nu]
meal = "taco"
"#,
)]);
assert!(nu.pipeline("config set nu.meal 'arepa'").execute().is_ok());
assert_that!(nu.pipeline("config get nu.meal"), says().stdout("arepa"));
})
}
#[test]
fn sets_config_values_into_one_property() {
Playground::setup("config_set_into_test", |dirs, nu| {
let file = AbsolutePath::new(dirs.test().join("config.toml"));
nu.with_config(&file);
nu.with_files(vec![FileWithContent(
"config.toml",
r#"
skip_welcome_message = true
"#,
)]);
assert!(nu
.pipeline(&input(
r#"
echo ["amarillo", "blanco"]
| config set_into arepa_colors
"#,
))
.execute()
.is_ok());
assert_that!(
nu.pipeline("config get arepa_colors.1"),
says().stdout("blanco")
);
})
}
#[test]
fn config_path() {
Playground::setup("config_path_test", |dirs, nu| {
let file = AbsolutePath::new(dirs.test().join("config.toml"));
nu.with_config(&file);
nu.with_files(vec![FileWithContent(
"config.toml",
r#"
skip_welcome_message = true
"#,
)]);
assert_that!(
nu.pipeline("config path"),
says().stdout(&file.display_path())
);
})
}
#[test]
fn removes_config_values() {
Playground::setup("config_remove_test", |dirs, nu| {
let file = AbsolutePath::new(dirs.test().join("config.toml"));
nu.with_config(&file);
nu.with_files(vec![FileWithContent(
"config.toml",
r#"
skip_welcome_message = true
"#,
)]);
assert!(nu
.pipeline("config remove skip_welcome_message")
.execute()
.is_ok());
assert!(file_contents(&file).is_empty());
})
}

View File

@@ -1,116 +0,0 @@
use nu_test_support::fs::Stub::FileWithContent;
use nu_test_support::fs::{AbsolutePath, DisplayPath};
use nu_test_support::playground::{says, Playground};
use std::path::PathBuf;
use hamcrest2::assert_that;
use hamcrest2::prelude::*;
#[test]
fn setting_environment_value_to_configuration_should_pick_up_into_in_memory_environment_on_runtime()
{
Playground::setup("environment_syncing_test_1", |dirs, nu| {
let file = AbsolutePath::new(dirs.test().join("config.toml"));
nu.with_config(&file);
nu.with_files(vec![FileWithContent(
"config.toml",
r#"
skip_welcome_message = true
[env]
SHELL = "/local/nu"
"#,
)]);
assert_that!(
nu.pipeline("config set env.USER NUNO | ignore")
.and_then("echo $env.USER"),
says().stdout("NUNO")
);
});
}
#[test]
fn inherited_environment_values_not_present_in_configuration_should_pick_up_into_in_memory_environment(
) {
Playground::setup("environment_syncing_test_2", |dirs, nu| {
let file = AbsolutePath::new(dirs.test().join("config.toml"));
nu.with_files(vec![FileWithContent(
"config.toml",
r#"
skip_welcome_message = true
[env]
SHELL = "/local/nu"
"#,
)])
.with_config(&file)
.with_env("USER", "NUNO");
assert_that!(nu.pipeline("echo $env.USER"), says().stdout("NUNO"));
});
}
#[test]
fn environment_values_present_in_configuration_overwrites_inherited_environment_values() {
Playground::setup("environment_syncing_test_3", |dirs, nu| {
let file = AbsolutePath::new(dirs.test().join("config.toml"));
nu.with_files(vec![FileWithContent(
"config.toml",
r#"
skip_welcome_message = true
[env]
SHELL = "/usr/bin/you_already_made_the_nu_choice"
"#,
)])
.with_config(&file)
.with_env("SHELL", "/usr/bin/sh");
assert_that!(
nu.pipeline("echo $env.SHELL"),
says().stdout("/usr/bin/you_already_made_the_nu_choice")
);
});
}
#[test]
fn inherited_environment_path_values_not_present_in_configuration_should_pick_up_into_in_memory_environment(
) {
Playground::setup("environment_syncing_test_4", |dirs, nu| {
let file = AbsolutePath::new(dirs.test().join("config.toml"));
let expected_paths = vec![
PathBuf::from("/Users/andresrobalino/.volta/bin"),
PathBuf::from("/Users/mosqueteros/bin"),
PathBuf::from("/path/to/be/added"),
]
.iter()
.map(|p| p.display_path())
.collect::<Vec<_>>()
.join("-");
nu.with_files(vec![FileWithContent(
"config.toml",
r#"
skip_welcome_message = true
path = ["/Users/andresrobalino/.volta/bin", "/Users/mosqueteros/bin"]
"#,
)])
.with_config(&file)
.with_env(
nu_test_support::NATIVE_PATH_ENV_VAR,
&PathBuf::from("/path/to/be/added").display_path(),
);
assert_that!(
nu.pipeline("echo $nu.path | str collect '-'"),
says().stdout(&expected_paths)
);
});
}

View File

@@ -1,6 +1,4 @@
mod configuration;
mod env;
mod in_sync;
mod nu_env;
pub mod support {

View File

@@ -1,28 +1,10 @@
use nu_test_support::fs::AbsolutePath;
use nu_test_support::playground::{says, Playground};
use nu_test_support::{nu, pipeline};
use hamcrest2::assert_that;
use hamcrest2::prelude::*;
#[cfg(feature = "which-support")]
mod environment;
mod pipeline;
//FIXME: jt: this approach may no longer be right for running from startup scripts, needs investigation
#[ignore]
#[test]
fn runs_configuration_startup_commands() {
Playground::setup("init_config_startup_commands_test", |dirs, nu| {
let file = AbsolutePath::new(dirs.config_fixtures().join("startup.toml"));
nu.with_config(&file);
assert_that!(nu.pipeline("hello-world"), says().stdout("Nu World"));
});
}
//FIXME: jt: we need to focus some fixes on wix as the plugins will differ
#[ignore]
#[test]