mirror of
https://github.com/nushell/nushell.git
synced 2024-11-22 08:23:24 +01:00
8fc8fc89aa
Improvements overall to Nu. Also among the changes here, we can also be more confident towards incorporating `3041`. End to end tests for checking envs properly exported to externals is not added here (since it's in the other PR) A few things added in this PR (probably forgetting some too) * no writes happen to history during test runs. * environment syncing end to end coverage added. * clean up / refactorings few areas. * testing API for finer control (can write tests passing more than one pipeline) * can pass environment variables in tests that nu will inherit when running. * No longer needed. * no longer under a module. No need to use super.
114 lines
3.3 KiB
Rust
114 lines
3.3 KiB
Rust
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; echo $nothing")
|
|
.and_then("echo $nu.env.USER"),
|
|
says().to_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 $nu.env.USER"), says().to_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 $nu.env.SHELL"),
|
|
says().to_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("PATH", &PathBuf::from("/path/to/be/added").display_path());
|
|
|
|
assert_that!(
|
|
nu.pipeline("echo $nu.path | str collect '-'"),
|
|
says().to_stdout(&expected_paths)
|
|
);
|
|
});
|
|
}
|