Compare commits

..

4 Commits

Author SHA1 Message Date
Andrés N. Robalino
7dc1d6a350 Extract .nu-env tests and more granularity (#3078)
The autoenv logic mutates environment variables in the running session as
it operates and decides what to do for trusted directories containing `.nu-env`
files. Few of the ways to interact with it were all in a single test function.

We separate out all the ways that were done in the single test function to document
 it better. This will greatly help once we start refactoring our way out from setting
 environment variables this way to just setting them to `Scope`.

This is part of an on-going effort to keep variables (`PATH` and `ENV`)
in our `Scope` and rely on it for everything related to variables.

We expect to move away from setting (`std::*`) envrironment variables in the current
running process. This is non-trivial since we need to handle cases from vars
coming in from the outside world, prioritize, and also compare to the ones
we have both stored in memory and in configuration files.

Also to send out our in-memory (in `Scope`) variables properly to external
programs once we no longer rely on `std::env` vars from the running process.
2021-02-18 20:24:27 -05:00
Jonathan Turner
deff1aa63b Bump to 0.27.1 (#3073) 2021-02-18 18:54:48 +13:00
Andrés N. Robalino
08e7d0dfb6 Keep the environment properly set. (#3072)
* Revert "fix prompts on startup (#3056)"

This reverts commit b202951c1d.

* Ensure environment variables synced with global internal Nu Scope.
2021-02-18 15:56:14 +13:00
rezural
892aae267d add height method to Host trait, and implementors (#3064) 2021-02-17 09:02:13 +13:00
50 changed files with 895 additions and 541 deletions

89
Cargo.lock generated
View File

@@ -2812,7 +2812,7 @@ dependencies = [
[[package]]
name = "nu"
version = "0.27.0"
version = "0.27.1"
dependencies = [
"clap",
"ctrlc",
@@ -2850,11 +2850,12 @@ dependencies = [
"nu_plugin_tree",
"nu_plugin_xpath",
"pretty_env_logger",
"serial_test",
]
[[package]]
name = "nu-cli"
version = "0.27.0"
version = "0.27.1"
dependencies = [
"Inflector",
"ansi_term 0.12.1",
@@ -2955,7 +2956,7 @@ dependencies = [
[[package]]
name = "nu-command"
version = "0.27.0"
version = "0.27.1"
dependencies = [
"Inflector",
"ansi_term 0.12.1",
@@ -3055,7 +3056,7 @@ dependencies = [
[[package]]
name = "nu-data"
version = "0.27.0"
version = "0.27.1"
dependencies = [
"ansi_term 0.12.1",
"bigdecimal",
@@ -3085,7 +3086,7 @@ dependencies = [
[[package]]
name = "nu-engine"
version = "0.27.0"
version = "0.27.1"
dependencies = [
"ansi_term 0.12.1",
"async-recursion",
@@ -3127,7 +3128,7 @@ dependencies = [
[[package]]
name = "nu-errors"
version = "0.27.0"
version = "0.27.1"
dependencies = [
"ansi_term 0.12.1",
"bigdecimal",
@@ -3146,7 +3147,7 @@ dependencies = [
[[package]]
name = "nu-json"
version = "0.27.0"
version = "0.27.1"
dependencies = [
"lazy_static 1.4.0",
"num-traits 0.2.14",
@@ -3156,7 +3157,7 @@ dependencies = [
[[package]]
name = "nu-parser"
version = "0.27.0"
version = "0.27.1"
dependencies = [
"bigdecimal",
"codespan-reporting",
@@ -3179,7 +3180,7 @@ dependencies = [
[[package]]
name = "nu-plugin"
version = "0.27.0"
version = "0.27.1"
dependencies = [
"bigdecimal",
"indexmap",
@@ -3195,7 +3196,7 @@ dependencies = [
[[package]]
name = "nu-protocol"
version = "0.27.0"
version = "0.27.1"
dependencies = [
"bigdecimal",
"byte-unit",
@@ -3218,7 +3219,7 @@ dependencies = [
[[package]]
name = "nu-source"
version = "0.27.0"
version = "0.27.1"
dependencies = [
"derive-new",
"getset",
@@ -3229,7 +3230,7 @@ dependencies = [
[[package]]
name = "nu-stream"
version = "0.27.0"
version = "0.27.1"
dependencies = [
"futures 0.3.12",
"nu-errors",
@@ -3239,7 +3240,7 @@ dependencies = [
[[package]]
name = "nu-table"
version = "0.27.0"
version = "0.27.1"
dependencies = [
"ansi_term 0.12.1",
"regex 1.4.3",
@@ -3248,7 +3249,7 @@ dependencies = [
[[package]]
name = "nu-test-support"
version = "0.27.0"
version = "0.27.1"
dependencies = [
"bigdecimal",
"chrono",
@@ -3266,7 +3267,7 @@ dependencies = [
[[package]]
name = "nu-value-ext"
version = "0.27.0"
version = "0.27.1"
dependencies = [
"indexmap",
"itertools",
@@ -3278,7 +3279,7 @@ dependencies = [
[[package]]
name = "nu_plugin_binaryview"
version = "0.27.0"
version = "0.27.1"
dependencies = [
"ansi_term 0.12.1",
"crossterm 0.19.0",
@@ -3294,7 +3295,7 @@ dependencies = [
[[package]]
name = "nu_plugin_chart"
version = "0.27.0"
version = "0.27.1"
dependencies = [
"crossterm 0.19.0",
"nu-cli",
@@ -3309,7 +3310,7 @@ dependencies = [
[[package]]
name = "nu_plugin_fetch"
version = "0.27.0"
version = "0.27.1"
dependencies = [
"base64 0.13.0",
"futures 0.3.12",
@@ -3323,7 +3324,7 @@ dependencies = [
[[package]]
name = "nu_plugin_from_bson"
version = "0.27.0"
version = "0.27.1"
dependencies = [
"bigdecimal",
"bson",
@@ -3337,7 +3338,7 @@ dependencies = [
[[package]]
name = "nu_plugin_from_sqlite"
version = "0.27.0"
version = "0.27.1"
dependencies = [
"bigdecimal",
"nu-errors",
@@ -3352,7 +3353,7 @@ dependencies = [
[[package]]
name = "nu_plugin_inc"
version = "0.27.0"
version = "0.27.1"
dependencies = [
"nu-errors",
"nu-plugin",
@@ -3365,7 +3366,7 @@ dependencies = [
[[package]]
name = "nu_plugin_match"
version = "0.27.0"
version = "0.27.1"
dependencies = [
"nu-errors",
"nu-plugin",
@@ -3376,7 +3377,7 @@ dependencies = [
[[package]]
name = "nu_plugin_post"
version = "0.27.0"
version = "0.27.1"
dependencies = [
"base64 0.13.0",
"futures 0.3.12",
@@ -3392,7 +3393,7 @@ dependencies = [
[[package]]
name = "nu_plugin_ps"
version = "0.27.0"
version = "0.27.1"
dependencies = [
"futures 0.3.12",
"futures-timer",
@@ -3406,7 +3407,7 @@ dependencies = [
[[package]]
name = "nu_plugin_s3"
version = "0.27.0"
version = "0.27.1"
dependencies = [
"futures 0.3.12",
"nu-errors",
@@ -3418,7 +3419,7 @@ dependencies = [
[[package]]
name = "nu_plugin_selector"
version = "0.27.0"
version = "0.27.1"
dependencies = [
"nipper",
"nu-errors",
@@ -3430,7 +3431,7 @@ dependencies = [
[[package]]
name = "nu_plugin_start"
version = "0.27.0"
version = "0.27.1"
dependencies = [
"glob",
"nu-errors",
@@ -3443,7 +3444,7 @@ dependencies = [
[[package]]
name = "nu_plugin_sys"
version = "0.27.0"
version = "0.27.1"
dependencies = [
"futures 0.3.12",
"futures-util",
@@ -3457,7 +3458,7 @@ dependencies = [
[[package]]
name = "nu_plugin_textview"
version = "0.27.0"
version = "0.27.1"
dependencies = [
"ansi_term 0.12.1",
"bat",
@@ -3472,7 +3473,7 @@ dependencies = [
[[package]]
name = "nu_plugin_to_bson"
version = "0.27.0"
version = "0.27.1"
dependencies = [
"bson",
"nu-errors",
@@ -3485,7 +3486,7 @@ dependencies = [
[[package]]
name = "nu_plugin_to_sqlite"
version = "0.27.0"
version = "0.27.1"
dependencies = [
"hex 0.4.2",
"nu-errors",
@@ -3500,7 +3501,7 @@ dependencies = [
[[package]]
name = "nu_plugin_tree"
version = "0.27.0"
version = "0.27.1"
dependencies = [
"derive-new",
"nu-errors",
@@ -3512,7 +3513,7 @@ dependencies = [
[[package]]
name = "nu_plugin_xpath"
version = "0.27.0"
version = "0.27.1"
dependencies = [
"bigdecimal",
"indexmap",
@@ -5012,6 +5013,28 @@ dependencies = [
"yaml-rust",
]
[[package]]
name = "serial_test"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e0bccbcf40c8938196944a3da0e133e031a33f4d6b72db3bda3cc556e361905d"
dependencies = [
"lazy_static 1.4.0",
"parking_lot 0.11.1",
"serial_test_derive",
]
[[package]]
name = "serial_test_derive"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b2acd6defeddb41eb60bb468f8825d0cfd0c2a76bc03bfd235b6a1dc4f6a1ad5"
dependencies = [
"proc-macro2",
"quote 1.0.8",
"syn 1.0.60",
]
[[package]]
name = "servo_arc"
version = "0.1.1"

View File

@@ -10,7 +10,7 @@ license = "MIT"
name = "nu"
readme = "README.md"
repository = "https://github.com/nushell/nushell"
version = "0.27.0"
version = "0.27.1"
[workspace]
members = ["crates/*/"]
@@ -18,35 +18,35 @@ members = ["crates/*/"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
nu-cli = { version = "0.27.0", path = "./crates/nu-cli", default-features = false }
nu-command = { version = "0.27.0", path = "./crates/nu-command" }
nu-data = { version = "0.27.0", path = "./crates/nu-data" }
nu-engine = { version = "0.27.0", path = "./crates/nu-engine" }
nu-errors = { version = "0.27.0", path = "./crates/nu-errors" }
nu-parser = { version = "0.27.0", path = "./crates/nu-parser" }
nu-plugin = { version = "0.27.0", path = "./crates/nu-plugin" }
nu-protocol = { version = "0.27.0", path = "./crates/nu-protocol" }
nu-source = { version = "0.27.0", path = "./crates/nu-source" }
nu-value-ext = { version = "0.27.0", path = "./crates/nu-value-ext" }
nu-cli = { version = "0.27.1", path = "./crates/nu-cli", default-features = false }
nu-command = { version = "0.27.1", path = "./crates/nu-command" }
nu-data = { version = "0.27.1", path = "./crates/nu-data" }
nu-engine = { version = "0.27.1", path = "./crates/nu-engine" }
nu-errors = { version = "0.27.1", path = "./crates/nu-errors" }
nu-parser = { version = "0.27.1", path = "./crates/nu-parser" }
nu-plugin = { version = "0.27.1", path = "./crates/nu-plugin" }
nu-protocol = { version = "0.27.1", path = "./crates/nu-protocol" }
nu-source = { version = "0.27.1", path = "./crates/nu-source" }
nu-value-ext = { version = "0.27.1", path = "./crates/nu-value-ext" }
nu_plugin_binaryview = { version = "0.27.0", path = "./crates/nu_plugin_binaryview", optional = true }
nu_plugin_chart = { version = "0.27.0", path = "./crates/nu_plugin_chart", optional = true }
nu_plugin_fetch = { version = "0.27.0", path = "./crates/nu_plugin_fetch", optional = true }
nu_plugin_from_bson = { version = "0.27.0", path = "./crates/nu_plugin_from_bson", optional = true }
nu_plugin_from_sqlite = { version = "0.27.0", path = "./crates/nu_plugin_from_sqlite", optional = true }
nu_plugin_inc = { version = "0.27.0", path = "./crates/nu_plugin_inc", optional = true }
nu_plugin_match = { version = "0.27.0", path = "./crates/nu_plugin_match", optional = true }
nu_plugin_post = { version = "0.27.0", path = "./crates/nu_plugin_post", optional = true }
nu_plugin_ps = { version = "0.27.0", path = "./crates/nu_plugin_ps", optional = true }
nu_plugin_s3 = { version = "0.27.0", path = "./crates/nu_plugin_s3", optional = true }
nu_plugin_selector = { version = "0.27.0", path = "./crates/nu_plugin_selector", optional = true }
nu_plugin_start = { version = "0.27.0", path = "./crates/nu_plugin_start", optional = true }
nu_plugin_sys = { version = "0.27.0", path = "./crates/nu_plugin_sys", optional = true }
nu_plugin_textview = { version = "0.27.0", path = "./crates/nu_plugin_textview", optional = true }
nu_plugin_to_bson = { version = "0.27.0", path = "./crates/nu_plugin_to_bson", optional = true }
nu_plugin_to_sqlite = { version = "0.27.0", path = "./crates/nu_plugin_to_sqlite", optional = true }
nu_plugin_tree = { version = "0.27.0", path = "./crates/nu_plugin_tree", optional = true }
nu_plugin_xpath = { version = "0.27.0", path = "./crates/nu_plugin_xpath", optional = true }
nu_plugin_binaryview = { version = "0.27.1", path = "./crates/nu_plugin_binaryview", optional = true }
nu_plugin_chart = { version = "0.27.1", path = "./crates/nu_plugin_chart", optional = true }
nu_plugin_fetch = { version = "0.27.1", path = "./crates/nu_plugin_fetch", optional = true }
nu_plugin_from_bson = { version = "0.27.1", path = "./crates/nu_plugin_from_bson", optional = true }
nu_plugin_from_sqlite = { version = "0.27.1", path = "./crates/nu_plugin_from_sqlite", optional = true }
nu_plugin_inc = { version = "0.27.1", path = "./crates/nu_plugin_inc", optional = true }
nu_plugin_match = { version = "0.27.1", path = "./crates/nu_plugin_match", optional = true }
nu_plugin_post = { version = "0.27.1", path = "./crates/nu_plugin_post", optional = true }
nu_plugin_ps = { version = "0.27.1", path = "./crates/nu_plugin_ps", optional = true }
nu_plugin_s3 = { version = "0.27.1", path = "./crates/nu_plugin_s3", optional = true }
nu_plugin_selector = { version = "0.27.1", path = "./crates/nu_plugin_selector", optional = true }
nu_plugin_start = { version = "0.27.1", path = "./crates/nu_plugin_start", optional = true }
nu_plugin_sys = { version = "0.27.1", path = "./crates/nu_plugin_sys", optional = true }
nu_plugin_textview = { version = "0.27.1", path = "./crates/nu_plugin_textview", optional = true }
nu_plugin_to_bson = { version = "0.27.1", path = "./crates/nu_plugin_to_bson", optional = true }
nu_plugin_to_sqlite = { version = "0.27.1", path = "./crates/nu_plugin_to_sqlite", optional = true }
nu_plugin_tree = { version = "0.27.1", path = "./crates/nu_plugin_tree", optional = true }
nu_plugin_xpath = { version = "0.27.1", path = "./crates/nu_plugin_xpath", optional = true }
# Required to bootstrap the main binary
clap = "2.33.3"
@@ -57,8 +57,10 @@ log = "0.4.14"
pretty_env_logger = "0.4.0"
[dev-dependencies]
nu-test-support = { version = "0.27.1", path = "./crates/nu-test-support" }
dunce = "1.0.1"
nu-test-support = { version = "0.27.0", path = "./crates/nu-test-support" }
serial_test = "0.5.1"
[build-dependencies]

View File

@@ -5,25 +5,25 @@ description = "CLI for nushell"
edition = "2018"
license = "MIT"
name = "nu-cli"
version = "0.27.0"
version = "0.27.1"
[lib]
doctest = false
[dependencies]
nu-command = { version = "0.27.0", path = "../nu-command" }
nu-data = { version = "0.27.0", path = "../nu-data" }
nu-engine = { version = "0.27.0", path = "../nu-engine" }
nu-errors = { version = "0.27.0", path = "../nu-errors" }
nu-json = { version = "0.27.0", path = "../nu-json" }
nu-parser = { version = "0.27.0", path = "../nu-parser" }
nu-plugin = { version = "0.27.0", path = "../nu-plugin" }
nu-protocol = { version = "0.27.0", path = "../nu-protocol" }
nu-source = { version = "0.27.0", path = "../nu-source" }
nu-stream = { version = "0.27.0", path = "../nu-stream" }
nu-table = { version = "0.27.0", path = "../nu-table" }
nu-test-support = { version = "0.27.0", path = "../nu-test-support" }
nu-value-ext = { version = "0.27.0", path = "../nu-value-ext" }
nu-command = { version = "0.27.1", path = "../nu-command" }
nu-data = { version = "0.27.1", path = "../nu-data" }
nu-engine = { version = "0.27.1", path = "../nu-engine" }
nu-errors = { version = "0.27.1", path = "../nu-errors" }
nu-json = { version = "0.27.1", path = "../nu-json" }
nu-parser = { version = "0.27.1", path = "../nu-parser" }
nu-plugin = { version = "0.27.1", path = "../nu-plugin" }
nu-protocol = { version = "0.27.1", path = "../nu-protocol" }
nu-source = { version = "0.27.1", path = "../nu-source" }
nu-stream = { version = "0.27.1", path = "../nu-stream" }
nu-table = { version = "0.27.1", path = "../nu-table" }
nu-test-support = { version = "0.27.1", path = "../nu-test-support" }
nu-value-ext = { version = "0.27.1", path = "../nu-value-ext" }
Inflector = "0.11"
ansi_term = "0.12.1"

View File

@@ -74,24 +74,34 @@ impl EnvironmentSyncer {
}
pub fn sync_env_vars(&mut self, ctx: &mut EvaluationContext) {
let nu_env_vars = ctx.scope.get_env_vars();
let mut environment = self.env.lock();
if environment.env().is_some() {
for (name, value) in ctx.with_host(|host| host.vars()) {
if name != "path" && name != "PATH" {
// account for new env vars present in the current session
// that aren't loaded from config.
environment.add_env(&name, &value);
// clear the env var from the session
// we are about to replace them
ctx.with_host(|host| host.env_rm(std::ffi::OsString::from(name)));
}
}
let environment = self.env.lock();
if let Some(variables) = environment.env() {
for var in variables.row_entries() {
if let Ok(string) = var.1.as_string() {
if var.0 != "path" && var.0 != "PATH" && !nu_env_vars.contains_key(var.0) {
ctx.scope.add_env_var(var.0, string);
}
}
}
}
ctx.with_host(|host| {
host.env_set(
std::ffi::OsString::from(var.0),
std::ffi::OsString::from(&string),
)
});
let nu_env_vars = ctx.scope.get_env_vars();
for (name, value) in ctx.with_host(|host| host.vars()) {
if name != "path" && name != "PATH" && !nu_env_vars.contains_key(&name) {
ctx.scope.add_env_var(name, value);
ctx.scope.add_env_var_to_base(var.0, string);
}
}
}
}
}
@@ -99,12 +109,15 @@ impl EnvironmentSyncer {
pub fn sync_path_vars(&mut self, ctx: &mut EvaluationContext) {
let mut environment = self.env.lock();
if environment.path().is_some() {
let native_paths = ctx.with_host(|host| host.env_get(std::ffi::OsString::from("PATH")));
if let Some(native_paths) = native_paths {
for path in std::env::split_paths(&native_paths) {
environment.add_path(path.as_os_str().to_os_string());
}
environment.add_path(native_paths);
ctx.with_host(|host| {
host.env_rm(std::ffi::OsString::from("PATH"));
});
}
if let Some(new_paths) = environment.path() {
@@ -116,8 +129,16 @@ impl EnvironmentSyncer {
);
if let Ok(paths_ready) = prepared {
ctx.with_host(|host| {
host.env_set(
std::ffi::OsString::from("PATH"),
std::ffi::OsString::from(&paths_ready),
);
});
ctx.scope
.add_env_var("PATH", paths_ready.to_string_lossy().to_string());
.add_env_var_to_base("PATH", paths_ready.to_string_lossy().to_string());
}
}
}
}
@@ -143,6 +164,7 @@ mod tests {
use indexmap::IndexMap;
use nu_data::config::tests::FakeConfig;
use nu_engine::basic_evaluation_context;
use nu_engine::Env;
use nu_errors::ShellError;
use nu_test_support::fs::Stub::FileWithContent;
use nu_test_support::playground::Playground;
@@ -200,6 +222,25 @@ mod tests {
actual.load_environment();
actual.sync_env_vars(&mut ctx);
{
let environment = actual.env.lock();
let mut vars = IndexMap::new();
environment
.env()
.expect("No variables in the environment.")
.row_entries()
.for_each(|(name, value)| {
vars.insert(
name.to_string(),
value.as_string().expect("Couldn't convert to string"),
);
});
for k in expected.keys() {
assert!(vars.contains_key(k));
}
}
assert!(!actual.did_config_change());
// Replacing the newer configuration file to the existing one.
@@ -213,12 +254,26 @@ mod tests {
actual.reload();
actual.sync_env_vars(&mut ctx);
let env_vars = ctx.scope.get_env_vars();
let result = env_vars.get("SHELL").unwrap();
assert_eq!(result, "/usr/bin/you_already_made_the_nu_choice");
expected.insert("USER".to_string(), "NUNO".to_string());
let result = env_vars.get("USER").unwrap();
assert_eq!(result, "NUNO");
{
let environment = actual.env.lock();
let mut vars = IndexMap::new();
environment
.env()
.expect("No variables in the environment.")
.row_entries()
.for_each(|(name, value)| {
vars.insert(
name.to_string(),
value.as_string().expect("Couldn't convert to string"),
);
});
for k in expected.keys() {
assert!(vars.contains_key(k));
}
}
});
Ok(())
@@ -278,12 +333,48 @@ mod tests {
// Nu sees the missing "USER" variable and accounts for it.
actual.sync_env_vars(&mut ctx);
let env_vars = ctx.scope.get_env_vars();
let result = env_vars.get("SHELL").unwrap();
assert_eq!(result, "/usr/bin/you_already_made_the_nu_choice");
// Confirms session environment variables are replaced from Nu configuration file
// including the newer one accounted for.
ctx.with_host(|test_host| {
let var_user = test_host
.env_get(std::ffi::OsString::from("USER"))
.expect("Couldn't get USER var from host.")
.into_string()
.expect("Couldn't convert to string.");
let result = env_vars.get("USER").unwrap();
assert_eq!(result, "NUNO");
let var_shell = test_host
.env_get(std::ffi::OsString::from("SHELL"))
.expect("Couldn't get SHELL var from host.")
.into_string()
.expect("Couldn't convert to string.");
let mut found = IndexMap::new();
found.insert("SHELL".to_string(), var_shell);
found.insert("USER".to_string(), var_user);
for k in found.keys() {
assert!(expected.contains_key(k));
}
});
// Now confirm in-memory environment variables synced appropriately
// including the newer one accounted for.
let environment = actual.env.lock();
let mut vars = IndexMap::new();
environment
.env()
.expect("No variables in the environment.")
.row_entries()
.for_each(|(name, value)| {
vars.insert(
name.to_string(),
value.as_string().expect("Couldn't convert to string"),
);
});
for k in expected.keys() {
assert!(vars.contains_key(k));
}
});
Ok(())
}
@@ -293,6 +384,12 @@ mod tests {
let mut ctx = basic_evaluation_context()?;
ctx.host = Arc::new(Mutex::new(Box::new(nu_engine::FakeHost::new())));
let mut expected = IndexMap::new();
expected.insert(
"SHELL".to_string(),
"/usr/bin/you_already_made_the_nu_choice".to_string(),
);
Playground::setup("syncs_env_test_2", |dirs, sandbox| {
sandbox.with_files(vec![FileWithContent(
"configuration.toml",
@@ -321,10 +418,37 @@ mod tests {
actual.load_environment();
actual.sync_env_vars(&mut ctx);
let env_vars = ctx.scope.get_env_vars();
let result = env_vars.get("SHELL").unwrap();
ctx.with_host(|test_host| {
let var_shell = test_host
.env_get(std::ffi::OsString::from("SHELL"))
.expect("Couldn't get SHELL var from host.")
.into_string()
.expect("Couldn't convert to string.");
assert_eq!(result, "/usr/bin/you_already_made_the_nu_choice");
let mut found = IndexMap::new();
found.insert("SHELL".to_string(), var_shell);
for k in found.keys() {
assert!(expected.contains_key(k));
}
});
let environment = actual.env.lock();
let mut vars = IndexMap::new();
environment
.env()
.expect("No variables in the environment.")
.row_entries()
.for_each(|(name, value)| {
vars.insert(
name.to_string(),
value.as_string().expect("couldn't convert to string"),
);
});
for k in expected.keys() {
assert!(vars.contains_key(k));
}
});
Ok(())
@@ -386,10 +510,32 @@ mod tests {
// Nu sees the missing "/path/to/be/added" and accounts for it.
actual.sync_path_vars(&mut ctx);
let env_vars = ctx.scope.get_env_vars();
let paths = env_vars.get("PATH").unwrap();
ctx.with_host(|test_host| {
let actual = test_host
.env_get(std::ffi::OsString::from("PATH"))
.expect("Couldn't get PATH var from host.")
.into_string()
.expect("Couldn't convert to string.");
assert_eq!(paths, &expected);
assert_eq!(actual, expected);
});
let environment = actual.env.lock();
let paths = std::env::join_paths(
&environment
.path()
.expect("No path variable in the environment.")
.table_entries()
.map(|value| value.as_string().expect("Couldn't convert to string"))
.map(PathBuf::from)
.collect::<Vec<_>>(),
)
.expect("Couldn't join paths.")
.into_string()
.expect("Couldn't convert to string.");
assert_eq!(paths, expected);
});
Ok(())
@@ -438,10 +584,32 @@ mod tests {
actual.load_environment();
actual.sync_path_vars(&mut ctx);
let env_vars = ctx.scope.get_env_vars();
let paths = env_vars.get("PATH").unwrap();
ctx.with_host(|test_host| {
let actual = test_host
.env_get(std::ffi::OsString::from("PATH"))
.expect("Couldn't get PATH var from host.")
.into_string()
.expect("Couldn't convert to string.");
assert_eq!(paths, &expected);
assert_eq!(actual, expected);
});
let environment = actual.env.lock();
let paths = std::env::join_paths(
&environment
.path()
.expect("No path variable in the environment.")
.table_entries()
.map(|value| value.as_string().expect("Couldn't convert to string"))
.map(PathBuf::from)
.collect::<Vec<_>>(),
)
.expect("Couldn't join paths.")
.into_string()
.expect("Couldn't convert to string.");
assert_eq!(paths, expected);
});
Ok(())

View File

@@ -5,24 +5,24 @@ description = "CLI for nushell"
edition = "2018"
license = "MIT"
name = "nu-command"
version = "0.27.0"
version = "0.27.1"
[lib]
doctest = false
[dependencies]
nu-data = { version = "0.27.0", path = "../nu-data" }
nu-engine = { version = "0.27.0", path = "../nu-engine" }
nu-errors = { version = "0.27.0", path = "../nu-errors" }
nu-json = { version = "0.27.0", path = "../nu-json" }
nu-parser = { version = "0.27.0", path = "../nu-parser" }
nu-plugin = { version = "0.27.0", path = "../nu-plugin" }
nu-protocol = { version = "0.27.0", path = "../nu-protocol" }
nu-source = { version = "0.27.0", path = "../nu-source" }
nu-stream = { version = "0.27.0", path = "../nu-stream" }
nu-table = { version = "0.27.0", path = "../nu-table" }
nu-test-support = { version = "0.27.0", path = "../nu-test-support" }
nu-value-ext = { version = "0.27.0", path = "../nu-value-ext" }
nu-data = { version = "0.27.1", path = "../nu-data" }
nu-engine = { version = "0.27.1", path = "../nu-engine" }
nu-errors = { version = "0.27.1", path = "../nu-errors" }
nu-json = { version = "0.27.1", path = "../nu-json" }
nu-parser = { version = "0.27.1", path = "../nu-parser" }
nu-plugin = { version = "0.27.1", path = "../nu-plugin" }
nu-protocol = { version = "0.27.1", path = "../nu-protocol" }
nu-source = { version = "0.27.1", path = "../nu-source" }
nu-stream = { version = "0.27.1", path = "../nu-stream" }
nu-table = { version = "0.27.1", path = "../nu-table" }
nu-test-support = { version = "0.27.1", path = "../nu-test-support" }
nu-value-ext = { version = "0.27.1", path = "../nu-value-ext" }
Inflector = "0.11"
ansi_term = "0.12.1"

View File

@@ -25,6 +25,7 @@ pub fn file_is_trusted(nu_env_file: &Path, content: &[u8]) -> Result<bool, Shell
let nufile = std::fs::canonicalize(nu_env_file)?;
let trusted = read_trusted()?;
Ok(trusted.files.get(&nufile.to_string_lossy().to_string()) == Some(&contentdigest))
}

View File

@@ -80,6 +80,7 @@ async fn with_env(raw_args: CommandArgs) -> Result<OutputStream, ShellError> {
) = raw_args.process().await?;
block.block.set_redirect(redirection);
let mut env = IndexMap::new();
match &variable.value {

View File

@@ -186,6 +186,7 @@ pub async fn process_script(
ctx.scope.add_env_to_base(env);
let result = run_block(&block, ctx, input_stream).await;
match result {
Ok(input) => {
// Running a pipeline gives us back a stream that we can then

View File

@@ -4,7 +4,7 @@ description = "CLI for nushell"
edition = "2018"
license = "MIT"
name = "nu-data"
version = "0.27.0"
version = "0.27.1"
[lib]
doctest = false
@@ -29,12 +29,12 @@ query_interface = "0.3.5"
serde = { version = "1.0.123", features = ["derive"] }
toml = "0.5.8"
nu-errors = { version = "0.27.0", path = "../nu-errors" }
nu-protocol = { version = "0.27.0", path = "../nu-protocol" }
nu-source = { version = "0.27.0", path = "../nu-source" }
nu-table = { version = "0.27.0", path = "../nu-table" }
nu-test-support = { version = "0.27.0", path = "../nu-test-support" }
nu-value-ext = { version = "0.27.0", path = "../nu-value-ext" }
nu-errors = { version = "0.27.1", path = "../nu-errors" }
nu-protocol = { version = "0.27.1", path = "../nu-protocol" }
nu-source = { version = "0.27.1", path = "../nu-source" }
nu-table = { version = "0.27.1", path = "../nu-table" }
nu-test-support = { version = "0.27.1", path = "../nu-test-support" }
nu-value-ext = { version = "0.27.1", path = "../nu-value-ext" }
[target.'cfg(unix)'.dependencies]
users = "0.11.0"

View File

@@ -127,6 +127,10 @@ impl NuConfig {
return Some(env_vars.clone());
}
if let Some(env_vars) = vars.get("PATH") {
return Some(env_vars.clone());
}
None
}
}

View File

@@ -4,17 +4,17 @@ description = "Core commands for nushell"
edition = "2018"
license = "MIT"
name = "nu-engine"
version = "0.27.0"
version = "0.27.1"
[dependencies]
nu-data = { version = "0.27.0", path = "../nu-data" }
nu-errors = { version = "0.27.0", path = "../nu-errors" }
nu-parser = { version = "0.27.0", path = "../nu-parser" }
nu-plugin = { version = "0.27.0", path = "../nu-plugin" }
nu-protocol = { version = "0.27.0", path = "../nu-protocol" }
nu-source = { version = "0.27.0", path = "../nu-source" }
nu-stream = { version = "0.27.0", path = "../nu-stream" }
nu-value-ext = { version = "0.27.0", path = "../nu-value-ext" }
nu-data = { version = "0.27.1", path = "../nu-data" }
nu-errors = { version = "0.27.1", path = "../nu-errors" }
nu-parser = { version = "0.27.1", path = "../nu-parser" }
nu-plugin = { version = "0.27.1", path = "../nu-plugin" }
nu-protocol = { version = "0.27.1", path = "../nu-protocol" }
nu-source = { version = "0.27.1", path = "../nu-source" }
nu-stream = { version = "0.27.1", path = "../nu-stream" }
nu-value-ext = { version = "0.27.1", path = "../nu-value-ext" }
ansi_term = "0.12.1"
async-recursion = "0.3.2"
@@ -47,7 +47,7 @@ umask = "1.0.0"
users = "0.11.0"
[dev-dependencies]
nu-test-support = { version = "0.27.0", path = "../nu-test-support" }
nu-test-support = { version = "0.27.1", path = "../nu-test-support" }
[features]
rustyline-support = []

View File

@@ -74,4 +74,9 @@ impl Host for BasicHost {
term_width -= 1;
term_width
}
fn height(&self) -> usize {
let (_, term_height) = term_size::dimensions().unwrap_or((80, 20));
term_height
}
}

View File

@@ -15,6 +15,7 @@ pub trait Host: Debug + Send {
fn env_rm(&mut self, k: OsString);
fn width(&self) -> usize;
fn height(&self) -> usize;
}
impl Host for Box<dyn Host> {
@@ -53,6 +54,10 @@ impl Host for Box<dyn Host> {
fn width(&self) -> usize {
(**self).width()
}
fn height(&self) -> usize {
(**self).height()
}
}
#[derive(Debug)]
@@ -124,4 +129,8 @@ impl Host for FakeHost {
fn width(&self) -> usize {
1
}
fn height(&self) -> usize {
1
}
}

View File

@@ -176,8 +176,7 @@ impl Scope {
pub fn add_env_var(&self, name: impl Into<String>, value: String) {
if let Some(frame) = self.frames.lock().last_mut() {
let name = name.into();
frame.env.insert(name, value);
frame.env.insert(name.into(), value);
}
}
@@ -192,6 +191,12 @@ impl Scope {
frame.env.extend(env_vars)
}
}
pub fn add_env_var_to_base(&self, name: impl Into<String>, value: String) {
if let Some(frame) = self.frames.lock().first_mut() {
frame.env.insert(name.into(), value);
}
}
}
impl ParserScope for Scope {

View File

@@ -21,12 +21,13 @@ pub fn nu(env: &IndexMap<String, String>, tag: impl Into<Tag>) -> Result<Value,
nu_dict.insert_value("config", UntaggedValue::row(config).into_value(&tag));
let mut table = vec![];
let path = std::env::var_os("PATH");
if let Some(paths) = path {
for path in std::env::split_paths(&paths) {
for v in env.iter() {
if v.0 == "PATH" || v.0 == "Path" {
for path in std::env::split_paths(&v.1) {
table.push(UntaggedValue::filepath(path).into_value(&tag));
}
}
}
nu_dict.insert_value("path", UntaggedValue::table(&table).into_value(&tag));
let path = std::env::current_dir()?;

View File

@@ -4,13 +4,13 @@ description = "Core error subsystem for Nushell"
edition = "2018"
license = "MIT"
name = "nu-errors"
version = "0.27.0"
version = "0.27.1"
[lib]
doctest = false
[dependencies]
nu-source = { path = "../nu-source", version = "0.27.0" }
nu-source = { path = "../nu-source", version = "0.27.1" }
ansi_term = "0.12.1"
bigdecimal = { version = "0.2.0", features = ["serde"] }

View File

@@ -4,7 +4,7 @@ description = "Fork of serde-hjson"
edition = "2018"
license = "MIT"
name = "nu-json"
version = "0.27.0"
version = "0.27.1"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View File

@@ -4,7 +4,7 @@ description = "Nushell parser"
edition = "2018"
license = "MIT"
name = "nu-parser"
version = "0.27.0"
version = "0.27.1"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@@ -23,10 +23,10 @@ itertools = "0.10.0"
smart-default = "0.6.0"
dunce = "1.0.1"
nu-errors = { version = "0.27.0", path = "../nu-errors" }
nu-protocol = { version = "0.27.0", path = "../nu-protocol" }
nu-source = { version = "0.27.0", path = "../nu-source" }
nu-test-support = { version = "0.27.0", path = "../nu-test-support" }
nu-errors = { version = "0.27.1", path = "../nu-errors" }
nu-protocol = { version = "0.27.1", path = "../nu-protocol" }
nu-source = { version = "0.27.1", path = "../nu-source" }
nu-test-support = { version = "0.27.1", path = "../nu-test-support" }
[features]
stable = []

View File

@@ -4,17 +4,17 @@ description = "Nushell Plugin"
edition = "2018"
license = "MIT"
name = "nu-plugin"
version = "0.27.0"
version = "0.27.1"
[lib]
doctest = false
[dependencies]
nu-errors = { path = "../nu-errors", version = "0.27.0" }
nu-protocol = { path = "../nu-protocol", version = "0.27.0" }
nu-source = { path = "../nu-source", version = "0.27.0" }
nu-test-support = { path = "../nu-test-support", version = "0.27.0" }
nu-value-ext = { path = "../nu-value-ext", version = "0.27.0" }
nu-errors = { path = "../nu-errors", version = "0.27.1" }
nu-protocol = { path = "../nu-protocol", version = "0.27.1" }
nu-source = { path = "../nu-source", version = "0.27.1" }
nu-test-support = { path = "../nu-test-support", version = "0.27.1" }
nu-value-ext = { path = "../nu-value-ext", version = "0.27.1" }
bigdecimal = { version = "0.2.0", features = ["serde"] }
indexmap = { version = "1.6.1", features = ["serde-1"] }

View File

@@ -4,7 +4,7 @@ description = "Core values and protocols for Nushell"
edition = "2018"
license = "MIT"
name = "nu-protocol"
version = "0.27.0"
version = "0.27.1"
[lib]
doctest = false
@@ -17,8 +17,8 @@ derive-new = "0.5.8"
getset = "0.1.1"
indexmap = { version = "1.6.1", features = ["serde-1"] }
log = "0.4.14"
nu-errors = { path = "../nu-errors", version = "0.27.0" }
nu-source = { path = "../nu-source", version = "0.27.0" }
nu-errors = { path = "../nu-errors", version = "0.27.1" }
nu-source = { path = "../nu-source", version = "0.27.1" }
num-bigint = { version = "0.3.1", features = ["serde"] }
num-integer = "0.1.44"
num-traits = "0.2.14"

View File

@@ -4,7 +4,7 @@ description = "A source string characterizer for Nushell"
edition = "2018"
license = "MIT"
name = "nu-source"
version = "0.27.0"
version = "0.27.1"
[lib]
doctest = false

View File

@@ -4,12 +4,12 @@ description = "Nushell stream"
edition = "2018"
license = "MIT"
name = "nu-stream"
version = "0.27.0"
version = "0.27.1"
[dependencies]
nu-errors = { version = "0.27.0", path = "../nu-errors" }
nu-protocol = { version = "0.27.0", path = "../nu-protocol" }
nu-source = { version = "0.27.0", path = "../nu-source" }
nu-errors = { version = "0.27.1", path = "../nu-errors" }
nu-protocol = { version = "0.27.1", path = "../nu-protocol" }
nu-source = { version = "0.27.1", path = "../nu-source" }
futures = { version = "0.3.12", features = ["compat", "io-compat"] }

View File

@@ -4,7 +4,7 @@ description = "Nushell table printing"
edition = "2018"
license = "MIT"
name = "nu-table"
version = "0.27.0"
version = "0.27.1"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[[bin]]

View File

@@ -4,16 +4,16 @@ description = "Support for writing Nushell tests"
edition = "2018"
license = "MIT"
name = "nu-test-support"
version = "0.27.0"
version = "0.27.1"
[lib]
doctest = false
[dependencies]
nu-errors = { version = "0.27.0", path = "../nu-errors" }
nu-protocol = { path = "../nu-protocol", version = "0.27.0" }
nu-source = { path = "../nu-source", version = "0.27.0" }
nu-value-ext = { version = "0.27.0", path = "../nu-value-ext" }
nu-errors = { version = "0.27.1", path = "../nu-errors" }
nu-protocol = { path = "../nu-protocol", version = "0.27.1" }
nu-source = { path = "../nu-source", version = "0.27.1" }
nu-value-ext = { version = "0.27.1", path = "../nu-value-ext" }
bigdecimal = { version = "0.2.0", features = ["serde"] }
chrono = "0.4.19"

View File

@@ -4,6 +4,17 @@ pub mod macros;
pub mod playground;
pub mod value;
pub struct Outcome {
pub out: String,
pub err: String,
}
impl Outcome {
pub fn new(out: String, err: String) -> Outcome {
Outcome { out, err }
}
}
pub fn pipeline(commands: &str) -> String {
commands
.lines()

View File

@@ -71,7 +71,7 @@ macro_rules! nu {
println!("=== stderr\n{}", err);
$crate::macros::Outcome::new(out,err.into_owned())
$crate::Outcome::new(out,err.into_owned())
}};
}
@@ -147,21 +147,10 @@ macro_rules! nu_with_plugins {
println!("=== stderr\n{}", err);
$crate::macros::Outcome::new(out,err.into_owned())
$crate::Outcome::new(out,err.into_owned())
}};
}
pub struct Outcome {
pub out: String,
pub err: String,
}
impl Outcome {
pub fn new(out: String, err: String) -> Outcome {
Outcome { out, err }
}
}
pub fn read_std(std: &[u8]) -> String {
let out = String::from_utf8_lossy(std);
let out = out.lines().skip(1).collect::<Vec<_>>().join("\n");

View File

@@ -4,15 +4,15 @@ description = "Extension traits for values in Nushell"
edition = "2018"
license = "MIT"
name = "nu-value-ext"
version = "0.27.0"
version = "0.27.1"
[lib]
doctest = false
[dependencies]
nu-errors = { path = "../nu-errors", version = "0.27.0" }
nu-protocol = { path = "../nu-protocol", version = "0.27.0" }
nu-source = { path = "../nu-source", version = "0.27.0" }
nu-errors = { path = "../nu-errors", version = "0.27.1" }
nu-protocol = { path = "../nu-protocol", version = "0.27.1" }
nu-source = { path = "../nu-source", version = "0.27.1" }
indexmap = { version = "1.6.1", features = ["serde-1"] }
itertools = "0.10.0"

View File

@@ -4,7 +4,7 @@ description = "A binary viewer plugin for Nushell"
edition = "2018"
license = "MIT"
name = "nu_plugin_binaryview"
version = "0.27.0"
version = "0.27.1"
[lib]
doctest = false
@@ -14,10 +14,10 @@ ansi_term = "0.12.1"
crossterm = "0.19"
image = { version = "0.22.4", default_features = false, features = ["png_codec", "jpeg"] }
neso = "0.5.0"
nu-errors = { path = "../nu-errors", version = "0.27.0" }
nu-plugin = { path = "../nu-plugin", version = "0.27.0" }
nu-protocol = { path = "../nu-protocol", version = "0.27.0" }
nu-source = { path = "../nu-source", version = "0.27.0" }
nu-errors = { path = "../nu-errors", version = "0.27.1" }
nu-plugin = { path = "../nu-plugin", version = "0.27.1" }
nu-protocol = { path = "../nu-protocol", version = "0.27.1" }
nu-source = { path = "../nu-source", version = "0.27.1" }
pretty-hex = "0.2.1"
rawkey = "0.1.3"

View File

@@ -4,19 +4,19 @@ description = "A plugin to display charts"
edition = "2018"
license = "MIT"
name = "nu_plugin_chart"
version = "0.27.0"
version = "0.27.1"
[lib]
doctest = false
[dependencies]
nu-cli = { path = "../nu-cli", version = "0.27.0" }
nu-data = { path = "../nu-data", version = "0.27.0" }
nu-errors = { path = "../nu-errors", version = "0.27.0" }
nu-plugin = { path = "../nu-plugin", version = "0.27.0" }
nu-protocol = { path = "../nu-protocol", version = "0.27.0" }
nu-source = { path = "../nu-source", version = "0.27.0" }
nu-value-ext = { path = "../nu-value-ext", version = "0.27.0" }
nu-cli = { path = "../nu-cli", version = "0.27.1" }
nu-data = { path = "../nu-data", version = "0.27.1" }
nu-errors = { path = "../nu-errors", version = "0.27.1" }
nu-plugin = { path = "../nu-plugin", version = "0.27.1" }
nu-protocol = { path = "../nu-protocol", version = "0.27.1" }
nu-source = { path = "../nu-source", version = "0.27.1" }
nu-value-ext = { path = "../nu-value-ext", version = "0.27.1" }
crossterm = "0.19.0"
tui = { version = "0.14.0", default-features = false, features = ["crossterm"] }

View File

@@ -4,7 +4,7 @@ description = "A URL fetch plugin for Nushell"
edition = "2018"
license = "MIT"
name = "nu_plugin_fetch"
version = "0.27.0"
version = "0.27.1"
[lib]
doctest = false
@@ -12,10 +12,10 @@ doctest = false
[dependencies]
base64 = "0.13.0"
futures = { version = "0.3.12", features = ["compat", "io-compat"] }
nu-errors = { path = "../nu-errors", version = "0.27.0" }
nu-plugin = { path = "../nu-plugin", version = "0.27.0" }
nu-protocol = { path = "../nu-protocol", version = "0.27.0" }
nu-source = { path = "../nu-source", version = "0.27.0" }
nu-errors = { path = "../nu-errors", version = "0.27.1" }
nu-plugin = { path = "../nu-plugin", version = "0.27.1" }
nu-protocol = { path = "../nu-protocol", version = "0.27.1" }
nu-source = { path = "../nu-source", version = "0.27.1" }
surf = "1.0.3"
url = "2.1.1"

View File

@@ -4,7 +4,7 @@ description = "A converter plugin to the bson format for Nushell"
edition = "2018"
license = "MIT"
name = "nu_plugin_from_bson"
version = "0.27.0"
version = "0.27.1"
[lib]
doctest = false
@@ -12,11 +12,11 @@ doctest = false
[dependencies]
bigdecimal = "0.2.0"
bson = { version = "0.14.1", features = ["decimal128"] }
nu-errors = { path = "../nu-errors", version = "0.27.0" }
nu-plugin = { path = "../nu-plugin", version = "0.27.0" }
nu-protocol = { path = "../nu-protocol", version = "0.27.0" }
nu-source = { path = "../nu-source", version = "0.27.0" }
nu-value-ext = { path = "../nu-value-ext", version = "0.27.0" }
nu-errors = { path = "../nu-errors", version = "0.27.1" }
nu-plugin = { path = "../nu-plugin", version = "0.27.1" }
nu-protocol = { path = "../nu-protocol", version = "0.27.1" }
nu-source = { path = "../nu-source", version = "0.27.1" }
nu-value-ext = { path = "../nu-value-ext", version = "0.27.1" }
num-traits = "0.2.14"
[build-dependencies]

View File

@@ -4,18 +4,18 @@ description = "A converter plugin to the bson format for Nushell"
edition = "2018"
license = "MIT"
name = "nu_plugin_from_sqlite"
version = "0.27.0"
version = "0.27.1"
[lib]
doctest = false
[dependencies]
bigdecimal = "0.2.0"
nu-errors = { path = "../nu-errors", version = "0.27.0" }
nu-plugin = { path = "../nu-plugin", version = "0.27.0" }
nu-protocol = { path = "../nu-protocol", version = "0.27.0" }
nu-source = { path = "../nu-source", version = "0.27.0" }
nu-value-ext = { path = "../nu-value-ext", version = "0.27.0" }
nu-errors = { path = "../nu-errors", version = "0.27.1" }
nu-plugin = { path = "../nu-plugin", version = "0.27.1" }
nu-protocol = { path = "../nu-protocol", version = "0.27.1" }
nu-source = { path = "../nu-source", version = "0.27.1" }
nu-value-ext = { path = "../nu-value-ext", version = "0.27.1" }
num-traits = "0.2.14"
tempfile = "3.2.0"

View File

@@ -4,18 +4,18 @@ description = "A version incrementer plugin for Nushell"
edition = "2018"
license = "MIT"
name = "nu_plugin_inc"
version = "0.27.0"
version = "0.27.1"
[lib]
doctest = false
[dependencies]
nu-errors = { path = "../nu-errors", version = "0.27.0" }
nu-plugin = { path = "../nu-plugin", version = "0.27.0" }
nu-protocol = { path = "../nu-protocol", version = "0.27.0" }
nu-source = { path = "../nu-source", version = "0.27.0" }
nu-test-support = { path = "../nu-test-support", version = "0.27.0" }
nu-value-ext = { path = "../nu-value-ext", version = "0.27.0" }
nu-errors = { path = "../nu-errors", version = "0.27.1" }
nu-plugin = { path = "../nu-plugin", version = "0.27.1" }
nu-protocol = { path = "../nu-protocol", version = "0.27.1" }
nu-source = { path = "../nu-source", version = "0.27.1" }
nu-test-support = { path = "../nu-test-support", version = "0.27.1" }
nu-value-ext = { path = "../nu-value-ext", version = "0.27.1" }
semver = "0.11.0"

View File

@@ -4,16 +4,16 @@ description = "A regex match plugin for Nushell"
edition = "2018"
license = "MIT"
name = "nu_plugin_match"
version = "0.27.0"
version = "0.27.1"
[lib]
doctest = false
[dependencies]
nu-errors = { path = "../nu-errors", version = "0.27.0" }
nu-plugin = { path = "../nu-plugin", version = "0.27.0" }
nu-protocol = { path = "../nu-protocol", version = "0.27.0" }
nu-source = { path = "../nu-source", version = "0.27.0" }
nu-errors = { path = "../nu-errors", version = "0.27.1" }
nu-plugin = { path = "../nu-plugin", version = "0.27.1" }
nu-protocol = { path = "../nu-protocol", version = "0.27.1" }
nu-source = { path = "../nu-source", version = "0.27.1" }
regex = "1.4.3"
[build-dependencies]

View File

@@ -4,7 +4,7 @@ description = "An HTTP post plugin for Nushell"
edition = "2018"
license = "MIT"
name = "nu_plugin_post"
version = "0.27.0"
version = "0.27.1"
[lib]
doctest = false
@@ -12,10 +12,10 @@ doctest = false
[dependencies]
base64 = "0.13.0"
futures = { version = "0.3.5", features = ["compat", "io-compat"] }
nu-errors = { path = "../nu-errors", version = "0.27.0" }
nu-plugin = { path = "../nu-plugin", version = "0.27.0" }
nu-protocol = { path = "../nu-protocol", version = "0.27.0" }
nu-source = { path = "../nu-source", version = "0.27.0" }
nu-errors = { path = "../nu-errors", version = "0.27.1" }
nu-plugin = { path = "../nu-plugin", version = "0.27.1" }
nu-protocol = { path = "../nu-protocol", version = "0.27.1" }
nu-source = { path = "../nu-source", version = "0.27.1" }
num-traits = "0.2.12"
serde_json = "1.0.57"
surf = "1.0.3"

View File

@@ -4,16 +4,16 @@ description = "A process list plugin for Nushell"
edition = "2018"
license = "MIT"
name = "nu_plugin_ps"
version = "0.27.0"
version = "0.27.1"
[lib]
doctest = false
[dependencies]
nu-errors = { path = "../nu-errors", version = "0.27.0" }
nu-plugin = { path = "../nu-plugin", version = "0.27.0" }
nu-protocol = { path = "../nu-protocol", version = "0.27.0" }
nu-source = { path = "../nu-source", version = "0.27.0" }
nu-errors = { path = "../nu-errors", version = "0.27.1" }
nu-plugin = { path = "../nu-plugin", version = "0.27.1" }
nu-protocol = { path = "../nu-protocol", version = "0.27.1" }
nu-source = { path = "../nu-source", version = "0.27.1" }
num-bigint = "0.3.1"

View File

@@ -4,17 +4,17 @@ description = "An S3 plugin for Nushell"
edition = "2018"
license = "MIT"
name = "nu_plugin_s3"
version = "0.27.0"
version = "0.27.1"
[lib]
doctest = false
[dependencies]
futures = { version = "0.3.12", features = ["compat", "io-compat"] }
nu-errors = { path = "../nu-errors", version = "0.27.0" }
nu-plugin = { path = "../nu-plugin", version = "0.27.0" }
nu-protocol = { path = "../nu-protocol", version = "0.27.0" }
nu-source = { path = "../nu-source", version = "0.27.0" }
nu-errors = { path = "../nu-errors", version = "0.27.1" }
nu-plugin = { path = "../nu-plugin", version = "0.27.1" }
nu-protocol = { path = "../nu-protocol", version = "0.27.1" }
nu-source = { path = "../nu-source", version = "0.27.1" }
s3handler = "0.6.3"
[build-dependencies]

View File

@@ -4,17 +4,17 @@ description = "web scraping using css selector"
edition = "2018"
license = "MIT"
name = "nu_plugin_selector"
version = "0.27.0"
version = "0.27.1"
[lib]
doctest = false
[dependencies]
nipper = "0.1.8"
nu-errors = { version = "0.27.0", path = "../nu-errors" }
nu-plugin = { version = "0.27.0", path = "../nu-plugin" }
nu-protocol = { version = "0.27.0", path = "../nu-protocol" }
nu-source = { version = "0.27.0", path = "../nu-source" }
nu-errors = { version = "0.27.1", path = "../nu-errors" }
nu-plugin = { version = "0.27.1", path = "../nu-plugin" }
nu-protocol = { version = "0.27.1", path = "../nu-protocol" }
nu-source = { version = "0.27.1", path = "../nu-source" }
[dev-dependencies]
nu-test-support = { path = "../nu-test-support", version = "0.27.0" }
nu-test-support = { path = "../nu-test-support", version = "0.27.1" }

View File

@@ -4,20 +4,20 @@ description = "A plugin to open files/URLs directly from Nushell"
edition = "2018"
license = "MIT"
name = "nu_plugin_start"
version = "0.27.0"
version = "0.27.1"
[lib]
doctest = false
[dependencies]
glob = "0.3.0"
nu-errors = { path = "../nu-errors", version = "0.27.0" }
nu-plugin = { path = "../nu-plugin", version = "0.27.0" }
nu-protocol = { path = "../nu-protocol", version = "0.27.0" }
nu-source = { path = "../nu-source", version = "0.27.0" }
nu-errors = { path = "../nu-errors", version = "0.27.1" }
nu-plugin = { path = "../nu-plugin", version = "0.27.1" }
nu-protocol = { path = "../nu-protocol", version = "0.27.1" }
nu-source = { path = "../nu-source", version = "0.27.1" }
open = "1.4.0"
url = "2.2.0"
[build-dependencies]
nu-errors = { version = "0.27.0", path = "../nu-errors" }
nu-source = { version = "0.27.0", path = "../nu-source" }
nu-errors = { version = "0.27.1", path = "../nu-errors" }
nu-source = { version = "0.27.1", path = "../nu-source" }

View File

@@ -4,16 +4,16 @@ description = "A system info plugin for Nushell"
edition = "2018"
license = "MIT"
name = "nu_plugin_sys"
version = "0.27.0"
version = "0.27.1"
[lib]
doctest = false
[dependencies]
nu-errors = { path = "../nu-errors", version = "0.27.0" }
nu-plugin = { path = "../nu-plugin", version = "0.27.0" }
nu-protocol = { path = "../nu-protocol", version = "0.27.0" }
nu-source = { path = "../nu-source", version = "0.27.0" }
nu-errors = { path = "../nu-errors", version = "0.27.1" }
nu-plugin = { path = "../nu-plugin", version = "0.27.1" }
nu-protocol = { path = "../nu-protocol", version = "0.27.1" }
nu-source = { path = "../nu-source", version = "0.27.1" }
futures = { version = "0.3.5", features = ["compat", "io-compat"] }
futures-util = "0.3.12"

View File

@@ -4,17 +4,17 @@ description = "Text viewer plugin for Nushell"
edition = "2018"
license = "MIT"
name = "nu_plugin_textview"
version = "0.27.0"
version = "0.27.1"
[lib]
doctest = false
[dependencies]
nu-data = { path = "../nu-data", version = "0.27.0" }
nu-errors = { path = "../nu-errors", version = "0.27.0" }
nu-plugin = { path = "../nu-plugin", version = "0.27.0" }
nu-protocol = { path = "../nu-protocol", version = "0.27.0" }
nu-source = { path = "../nu-source", version = "0.27.0" }
nu-data = { path = "../nu-data", version = "0.27.1" }
nu-errors = { path = "../nu-errors", version = "0.27.1" }
nu-plugin = { path = "../nu-plugin", version = "0.27.1" }
nu-protocol = { path = "../nu-protocol", version = "0.27.1" }
nu-source = { path = "../nu-source", version = "0.27.1" }
ansi_term = "0.12.1"
bat = { version = "0.17.1", features = ["regex-fancy", "paging"] }

View File

@@ -4,18 +4,18 @@ description = "A converter plugin to the bson format for Nushell"
edition = "2018"
license = "MIT"
name = "nu_plugin_to_bson"
version = "0.27.0"
version = "0.27.1"
[lib]
doctest = false
[dependencies]
bson = "0.14.1"
nu-errors = { path = "../nu-errors", version = "0.27.0" }
nu-plugin = { path = "../nu-plugin", version = "0.27.0" }
nu-protocol = { path = "../nu-protocol", version = "0.27.0" }
nu-source = { path = "../nu-source", version = "0.27.0" }
nu-value-ext = { path = "../nu-value-ext", version = "0.27.0" }
nu-errors = { path = "../nu-errors", version = "0.27.1" }
nu-plugin = { path = "../nu-plugin", version = "0.27.1" }
nu-protocol = { path = "../nu-protocol", version = "0.27.1" }
nu-source = { path = "../nu-source", version = "0.27.1" }
nu-value-ext = { path = "../nu-value-ext", version = "0.27.1" }
num-traits = "0.2.14"
[build-dependencies]

View File

@@ -4,18 +4,18 @@ description = "A converter plugin to the bson format for Nushell"
edition = "2018"
license = "MIT"
name = "nu_plugin_to_sqlite"
version = "0.27.0"
version = "0.27.1"
[lib]
doctest = false
[dependencies]
hex = "0.4.2"
nu-errors = { path = "../nu-errors", version = "0.27.0" }
nu-plugin = { path = "../nu-plugin", version = "0.27.0" }
nu-protocol = { path = "../nu-protocol", version = "0.27.0" }
nu-source = { path = "../nu-source", version = "0.27.0" }
nu-value-ext = { path = "../nu-value-ext", version = "0.27.0" }
nu-errors = { path = "../nu-errors", version = "0.27.1" }
nu-plugin = { path = "../nu-plugin", version = "0.27.1" }
nu-protocol = { path = "../nu-protocol", version = "0.27.1" }
nu-source = { path = "../nu-source", version = "0.27.1" }
nu-value-ext = { path = "../nu-value-ext", version = "0.27.1" }
num-traits = "0.2.14"
tempfile = "3.2.0"

View File

@@ -4,17 +4,17 @@ description = "Tree viewer plugin for Nushell"
edition = "2018"
license = "MIT"
name = "nu_plugin_tree"
version = "0.27.0"
version = "0.27.1"
[lib]
doctest = false
[dependencies]
derive-new = "0.5.8"
nu-errors = { path = "../nu-errors", version = "0.27.0" }
nu-plugin = { path = "../nu-plugin", version = "0.27.0" }
nu-protocol = { path = "../nu-protocol", version = "0.27.0" }
nu-source = { path = "../nu-source", version = "0.27.0" }
nu-errors = { path = "../nu-errors", version = "0.27.1" }
nu-plugin = { path = "../nu-plugin", version = "0.27.1" }
nu-protocol = { path = "../nu-protocol", version = "0.27.1" }
nu-source = { path = "../nu-source", version = "0.27.1" }
ptree = "0.3.1"
[build-dependencies]

View File

@@ -4,16 +4,16 @@ description = "Traverses xml"
edition = "2018"
license = "MIT"
name = "nu_plugin_xpath"
version = "0.27.0"
version = "0.27.1"
[lib]
doctest = false
[dependencies]
nu-errors = { version = "0.27.0", path = "../nu-errors" }
nu-plugin = { path = "../nu-plugin", version = "0.27.0" }
nu-protocol = { version = "0.27.0", path = "../nu-protocol" }
nu-source = { version = "0.27.0", path = "../nu-source" }
nu-errors = { version = "0.27.1", path = "../nu-errors" }
nu-plugin = { path = "../nu-plugin", version = "0.27.1" }
nu-protocol = { version = "0.27.1", path = "../nu-protocol" }
nu-source = { version = "0.27.1", path = "../nu-source" }
bigdecimal = { version = "0.2.0", features = ["serde"] }
indexmap = { version = "1.6.1", features = ["serde-1"] }
@@ -21,4 +21,4 @@ sxd-document = "0.3.2"
sxd-xpath = "0.4.2"
[dev-dependencies]
nu-test-support = { path = "../nu-test-support", version = "0.27.0" }
nu-test-support = { path = "../nu-test-support", version = "0.27.1" }

View File

@@ -87,7 +87,7 @@ version = "0.4.6"
[dependencies.cursive]
default-features = false
features = ["pancurses-backend"]
version = "0.27.0"
version = "0.27.1"
[dependencies.futures-preview]
features = ["compat", "io-compat"]

View File

@@ -0,0 +1,19 @@
mod nu_env;
pub mod support {
use nu_test_support::{nu, playground::*, Outcome};
pub struct Trusted;
impl Trusted {
pub fn in_path(dirs: &Dirs, block: impl FnOnce() -> Outcome) -> Outcome {
let for_env_manifest = dirs.test().to_string_lossy();
nu!(cwd: dirs.root(), format!("autoenv trust \"{}\"", for_env_manifest.to_string()));
let out = block();
nu!(cwd: dirs.root(), format!("autoenv untrust \"{}\"", for_env_manifest.to_string()));
out
}
}
}

View File

@@ -0,0 +1,342 @@
use super::support::Trusted;
use nu_test_support::fs::Stub::FileWithContent;
use nu_test_support::playground::Playground;
use nu_test_support::{nu, pipeline};
use serial_test::serial;
// Windows uses a different command to create an empty file
// so we need to have different content on windows.
const SCRIPTS: &str = if cfg!(target_os = "windows") {
r#"[scripts]
entryscripts = ["echo nul > hello.txt"]
exitscripts = ["echo nul > bye.txt"]"#
} else {
r#"[scripts]
entryscripts = ["touch hello.txt"]
exitscripts = ["touch bye.txt"]"#
};
#[test]
#[serial]
fn picks_up_env_keys_when_entering_trusted_directory() {
Playground::setup("autoenv_test_1", |dirs, sandbox| {
sandbox.with_files(vec![FileWithContent(
".nu-env",
&format!(
"{}\n{}",
r#"[env]
testkey = "testvalue"
[scriptvars]
myscript = "echo myval"
"#,
SCRIPTS
),
)]);
let expected = "testvalue";
let actual = Trusted::in_path(&dirs, || nu!(cwd: dirs.test(), "echo $nu.env.testkey"));
assert_eq!(actual.out, expected);
})
}
#[test]
#[serial]
fn picks_up_script_vars_when_entering_trusted_directory() {
Playground::setup("autoenv_test_2", |dirs, sandbox| {
sandbox.with_files(vec![FileWithContent(
".nu-env",
&format!(
"{}\n{}",
r#"[env]
testkey = "testvalue"
[scriptvars]
myscript = "echo myval"
"#,
SCRIPTS
),
)]);
let expected = "myval";
let actual = Trusted::in_path(&dirs, || nu!(cwd: dirs.test(), "echo $nu.env.myscript"));
assert_eq!(actual.out, expected);
})
}
#[test]
#[serial]
fn picks_up_env_keys_when_entering_trusted_directory_indirectly() {
Playground::setup("autoenv_test_3", |dirs, sandbox| {
sandbox.mkdir("crates");
sandbox.with_files(vec![FileWithContent(
".nu-env",
r#"[env]
nu-version = "0.27.1" "#,
)]);
let expected = "0.27.1";
let actual = Trusted::in_path(&dirs, || {
nu!(cwd: dirs.test().join("crates"), r#"
cd ../../autoenv_test_3
echo $nu.env.nu-version
"#)
});
assert_eq!(actual.out, expected);
})
}
#[test]
#[serial]
fn entering_a_trusted_directory_runs_entry_scripts() {
Playground::setup("autoenv_test_4", |dirs, sandbox| {
sandbox.with_files(vec![FileWithContent(
".nu-env",
&format!(
"{}\n{}",
r#"[env]
testkey = "testvalue"
[scriptvars]
myscript = "echo myval"
"#,
SCRIPTS
),
)]);
let actual = Trusted::in_path(&dirs, || {
nu!(cwd: dirs.test(), pipeline(r#"
ls
| where name == "hello.txt"
| get name
"#))
});
assert_eq!(actual.out, "hello.txt");
})
}
#[test]
#[serial]
fn leaving_a_trusted_directory_runs_exit_scripts() {
Playground::setup("autoenv_test_5", |dirs, sandbox| {
sandbox.with_files(vec![FileWithContent(
".nu-env",
&format!(
"{}\n{}",
r#"[env]
testkey = "testvalue"
[scriptvars]
myscript = "echo myval"
"#,
SCRIPTS
),
)]);
let actual = Trusted::in_path(&dirs, || {
nu!(cwd: dirs.test(), r#"
cd ..
ls autoenv_test_5 | get name | path basename | where $it == "bye.txt"
"#)
});
assert_eq!(actual.out, "bye.txt");
})
}
#[test]
#[serial]
fn entry_scripts_are_called_when_revisiting_a_trusted_directory() {
Playground::setup("autoenv_test_6", |dirs, sandbox| {
sandbox.with_files(vec![FileWithContent(
".nu-env",
&format!(
"{}\n{}",
r#"[env]
testkey = "testvalue"
[scriptvars]
myscript = "echo myval"
"#,
SCRIPTS
),
)]);
let actual = Trusted::in_path(&dirs, || {
nu!(cwd: dirs.test(), r#"
do { rm hello.txt ; = $nothing } ; # Silence file deletion message from output
cd ..
cd autoenv_test_6
ls | where name == "hello.txt" | get name
"#)
});
assert_eq!(actual.out, "hello.txt");
})
}
#[test]
#[serial]
fn given_a_trusted_directory_with_entry_scripts_when_entering_a_subdirectory_entry_scripts_are_not_called(
) {
Playground::setup("autoenv_test_7", |dirs, sandbox| {
sandbox.mkdir("time_to_cook_arepas");
sandbox.with_files(vec![FileWithContent(
".nu-env",
&format!(
"{}\n{}",
r#"[env]
testkey = "testvalue"
[scriptvars]
myscript = "echo myval"
"#,
SCRIPTS
),
)]);
let actual = Trusted::in_path(&dirs, || {
nu!(cwd: dirs.test(), r#"
cd time_to_cook_arepas
ls | where name == "hello.txt" | count
"#)
});
assert_eq!(actual.out, "0");
})
}
#[test]
#[serial]
fn given_a_trusted_directory_with_exit_scripts_when_entering_a_subdirectory_exit_scripts_are_not_called(
) {
Playground::setup("autoenv_test_8", |dirs, sandbox| {
sandbox.mkdir("time_to_cook_arepas");
sandbox.with_files(vec![FileWithContent(
".nu-env",
&format!(
"{}\n{}",
r#"[env]
testkey = "testvalue"
[scriptvars]
myscript = "echo myval"
"#,
SCRIPTS
),
)]);
let actual = Trusted::in_path(&dirs, || {
nu!(cwd: dirs.test(), r#"
cd time_to_cook_arepas
ls | where name == "bye.txt" | count
"#)
});
assert_eq!(actual.out, "0");
})
}
#[test]
#[serial]
fn given_a_hierachy_of_trusted_directories_when_entering_in_any_nested_ones_should_carry_over_variables_set_from_the_root(
) {
Playground::setup("autoenv_test_9", |dirs, sandbox| {
sandbox.mkdir("nu_plugin_rb");
sandbox.with_files(vec![
FileWithContent(
".nu-env",
r#"[env]
organization = "nushell""#,
),
FileWithContent(
"nu_plugin_rb/.nu-env",
r#"[env]
language = "Ruby""#,
),
]);
let actual = Trusted::in_path(&dirs, || {
nu!(cwd: dirs.test().parent().unwrap(), r#"
do { autoenv trust autoenv_test_9/nu_plugin_rb ; = $nothing } # Silence autoenv trust message from output
cd autoenv_test_9/nu_plugin_rb
echo $nu.env.organization
"#)
});
assert_eq!(actual.out, "nushell");
})
}
#[test]
#[serial]
fn given_a_hierachy_of_trusted_directories_nested_ones_should_overwrite_variables_from_parent_directories(
) {
Playground::setup("autoenv_test_10", |dirs, sandbox| {
sandbox.mkdir("nu_plugin_rb");
sandbox.with_files(vec![
FileWithContent(
".nu-env",
r#"[env]
organization = "nushell""#,
),
FileWithContent(
"nu_plugin_rb/.nu-env",
r#"[env]
organization = "Andrab""#,
),
]);
let actual = Trusted::in_path(&dirs, || {
nu!(cwd: dirs.test().parent().unwrap(), r#"
do { autoenv trust autoenv_test_10/nu_plugin_rb ; = $nothing } # Silence autoenv trust message from output
cd autoenv_test_10/nu_plugin_rb
echo $nu.env.organization
"#)
});
assert_eq!(actual.out, "Andrab");
})
}
#[test]
#[serial]
fn given_a_hierachy_of_trusted_directories_going_back_restores_overwritten_variables() {
Playground::setup("autoenv_test_11", |dirs, sandbox| {
sandbox.mkdir("nu_plugin_rb");
sandbox.with_files(vec![
FileWithContent(
".nu-env",
r#"[env]
organization = "nushell""#,
),
FileWithContent(
"nu_plugin_rb/.nu-env",
r#"[env]
organization = "Andrab""#,
),
]);
let actual = Trusted::in_path(&dirs, || {
nu!(cwd: dirs.test().parent().unwrap(), r#"
do { autoenv trust autoenv_test_11/nu_plugin_rb ; = $nothing } # Silence autoenv trust message from output
cd autoenv_test_11
cd nu_plugin_rb
do { rm ../.nu-env ; = $nothing } # By deleting the root nu-env we have guarantees that the variable gets restored (not by autoenv when re-entering)
cd ..
echo $nu.env.organization
"#)
});
assert_eq!(actual.out, "nushell");
})
}

View File

@@ -1,5 +1,9 @@
use nu_test_support::{nu, pipeline};
#[cfg(feature = "directories-support")]
#[cfg(feature = "which-support")]
mod environment;
mod pipeline;
#[test]

View File

@@ -34,237 +34,6 @@ fn takes_rows_of_nu_value_strings_and_pipes_it_to_stdin_of_external() {
})
}
#[cfg(feature = "directories-support")]
#[cfg(feature = "which-support")]
#[test]
fn autoenv() {
use nu_test_support::fs::Stub::FileWithContent;
Playground::setup("autoenv_test", |dirs, sandbox| {
sandbox.mkdir("foo/bar");
sandbox.mkdir("bizz/buzz");
sandbox.mkdir("foob");
// Windows uses a different command to create an empty file so we need to have different content on windows.
let full_nu_env = if cfg!(target_os = "windows") {
r#"[env]
testkey = "testvalue"
[scriptvars]
myscript = "echo myval"
[scripts]
entryscripts = ["echo nul > hello.txt"]
exitscripts = ["echo nul > bye.txt"]"#
} else {
r#"[env]
testkey = "testvalue"
[scriptvars]
myscript = "echo myval"
[scripts]
entryscripts = ["touch hello.txt"]
exitscripts = ["touch bye.txt"]"#
};
sandbox.with_files(vec![
FileWithContent(".nu-env", full_nu_env),
FileWithContent(
"foo/.nu-env",
r#"[env]
overwrite_me = "set_in_foo"
fookey = "fooval" "#,
),
FileWithContent(
"foo/bar/.nu-env",
r#"[env]
overwrite_me = "set_in_bar""#,
),
FileWithContent("bizz/.nu-env", full_nu_env),
]);
//Make sure basic keys are set
let actual = nu!(
cwd: dirs.test(),
r#"autoenv trust .
echo $nu.env.testkey"#
);
assert!(actual.out.ends_with("testvalue"));
// Make sure exitscripts are run in the directory they were specified.
let actual = nu!(
cwd: dirs.test(),
r#"autoenv trust
cd ..
cd autoenv_test
ls
ls | where name == "bye.txt" | get name"#
);
assert!(actual.out.contains("bye.txt"));
// Make sure entry scripts are run
let actual = nu!(
cwd: dirs.test(),
r#"cd ..
autoenv trust autoenv_test
cd autoenv_test
ls | where name == "hello.txt" | get name"#
);
assert!(actual.out.contains("hello.txt"));
// If inside a directory with exitscripts, entering a subdirectory should not trigger the exitscripts.
let actual = nu!(
cwd: dirs.test(),
r#"autoenv trust
cd foob
ls | where name == "bye.txt" | get name"#
);
assert!(!actual.out.contains("bye.txt"));
// Make sure entryscripts are run when re-visiting a directory
let actual = nu!(
cwd: dirs.test(),
r#"autoenv trust bizz
cd bizz
rm hello.txt
cd ..
cd bizz
ls | where name == "hello.txt" | get name"#
);
assert!(actual.out.contains("hello.txt"));
// Entryscripts should not run after changing to a subdirectory.
let actual = nu!(
cwd: dirs.test(),
r#"autoenv trust bizz
cd bizz
cd buzz
ls | where name == hello.txt | get name"#
);
assert!(!actual.out.ends_with("hello.txt"));
//Backing out of the directory should unset the keys
// let actual = nu!(
// cwd: dirs.test(),
// r#"cd ..
// echo $nu.env.testkey"#
// );
// assert!(!actual.out.ends_with("testvalue"));
// Make sure script keys are set
let actual = nu!(
cwd: dirs.test(),
r#"echo $nu.env.myscript"#
);
assert!(actual.out.ends_with("myval"));
//Going to sibling directory without passing parent should work.
let actual = nu!(
cwd: dirs.test(),
r#"autoenv trust foo
cd foob
cd ../foo
echo $nu.env.fookey
cd .."#
);
assert!(actual.out.ends_with("fooval"));
//Going to sibling directory should unset keys
// let actual = nu!(
// cwd: dirs.test(),
// r#"cd foo
// cd ../foob
// echo $nu.env.fookey
// cd .."#
// );
// assert!(!actual.out.ends_with("fooval"));
// Make sure entry scripts are run
let actual = nu!(
cwd: dirs.test(),
r#"ls | where name == "hello.txt" | get name"#
);
assert!(actual.out.contains("hello.txt"));
//Variables set in parent directories should be set even if you directly cd to a subdir
let actual = nu!(
cwd: dirs.test(),
r#"autoenv trust foo
cd foo/bar
autoenv trust
echo $nu.env.fookey"#
);
assert!(actual.out.ends_with("fooval"));
//Subdirectories should overwrite the values of parent directories.
let actual = nu!(
cwd: dirs.test(),
r#"autoenv trust foo
cd foo/bar
autoenv trust
echo $nu.env.overwrite_me"#
);
assert!(actual.out.ends_with("set_in_bar"));
//Make sure that overwritten values are restored.
//By deleting foo/.nu-env, we make sure that the value is actually restored and not just set again by autoenv when we re-visit foo.
let actual = nu!(
cwd: dirs.test(),
r#"cd foo
cd bar
rm ../.nu-env
cd ..
echo $nu.env.overwrite_me"#
);
assert!(actual.out.ends_with("set_in_foo"))
})
}
#[cfg(feature = "which")]
#[test]
fn nu_let_env_overwrites() {
Playground::setup("syncs_env_test_1", |dirs, sandbox| {
sandbox.with_files(vec![FileWithContent(
"configuration.toml",
r#"
[env]
SHELL = "/usr/bin/you_already_made_the_nu_choice"
"#,
)]);
let mut file = dirs.test().clone();
file.push("configuration.toml");
let fake_config = FakeConfig::new(&file);
let mut actual = EnvironmentSyncer::new();
actual.set_config(Box::new(fake_config));
// Here, the environment variables from the current session
// are cleared since we will load and set them from the
// configuration file (if any)
actual.clear_env_vars(&mut ctx);
// Nu loads the environment variables from the configuration file (if any)
actual.load_environment();
// By this point, Nu has already loaded the environment variables
// stored in the configuration file. Before continuing we check
// if any new environment variables have been added from the ones loaded
// in the configuration file.
//
// Nu sees the missing "USER" variable and accounts for it.
actual.sync_env_vars(&mut ctx);
let actual = nu!(
cwd: dirs.test(),
r#"let-env SHELL = bob
echo $nu.env.SHELL
"#
);
assert!(actual.out.ends_with("set_in_foo"))
});
}
#[test]
fn invocation_properly_redirects() {
let actual = nu!(