Add proper shadowing (#2851)

This commit is contained in:
Jonathan Turner 2021-01-03 20:48:02 +13:00 committed by GitHub
parent fc44df1e45
commit 27fe356214
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 2 deletions

View File

@ -89,7 +89,9 @@ impl Scope {
for frame in self.frames.lock().iter().rev() {
for v in frame.vars.iter() {
output.insert(v.0.clone(), v.1.clone());
if !output.contains_key(v.0) {
output.insert(v.0.clone(), v.1.clone());
}
}
}
@ -102,7 +104,9 @@ impl Scope {
for frame in self.frames.lock().iter().rev() {
for v in frame.env.iter() {
output.insert(v.0.clone(), v.1.clone());
if !output.contains_key(v.0) {
output.insert(v.0.clone(), v.1.clone());
}
}
}

View File

@ -455,6 +455,28 @@ fn set_env_doesnt_leak() {
assert!(actual.err.contains("did you mean"));
}
#[test]
fn proper_shadow_set_env_aliases() {
let actual = nu!(
cwd: ".",
r#"
set-env DEBUG = true; echo $nu.env.DEBUG | autoview; do { set-env DEBUG = false; echo $nu.env.DEBUG } | autoview; echo $nu.env.DEBUG
"#
);
assert_eq!(actual.out, "truefalsetrue");
}
#[test]
fn proper_shadow_set_aliases() {
let actual = nu!(
cwd: ".",
r#"
set DEBUG = false; echo $DEBUG | autoview; do { set DEBUG = true; echo $DEBUG } | autoview; echo $DEBUG
"#
);
assert_eq!(actual.out, "falsetruefalse");
}
#[cfg(feature = "which")]
#[test]
fn argument_invocation_reports_errors() {