forked from extern/nushell
Add Nushell REPL simulator; Fix bug in overlay add (#5478)
* Add Nushell REPL simulator; Fix bug in overlay add The `nu_repl` function takes an array of strings and processes them as if they were REPL lines entered one by one. This helps to discover bugs due to the state changes between the parse and eval stages. * Fix REPL tests on Windows
This commit is contained in:
parent
061e9294b3
commit
07ac3c3aab
@ -211,8 +211,8 @@ pub fn eval_source(
|
|||||||
(output, working_set.render())
|
(output, working_set.render())
|
||||||
};
|
};
|
||||||
|
|
||||||
let cwd = match nu_engine::env::current_dir_str(engine_state, stack) {
|
let cwd = match nu_engine::env::current_dir(engine_state, stack) {
|
||||||
Ok(p) => PathBuf::from(p),
|
Ok(p) => p,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
let working_set = StateWorkingSet::new(engine_state);
|
let working_set = StateWorkingSet::new(engine_state);
|
||||||
report_error(&working_set, &e);
|
report_error(&working_set, &e);
|
||||||
|
@ -53,8 +53,46 @@ https://www.nushell.sh/book/thinking_in_nushell.html#parsing-and-evaluation-are-
|
|||||||
|
|
||||||
// TODO: This logic is duplicated in the parser.
|
// TODO: This logic is duplicated in the parser.
|
||||||
if stack.has_env_overlay(&name_arg.item, engine_state) {
|
if stack.has_env_overlay(&name_arg.item, engine_state) {
|
||||||
stack.add_overlay(name_arg.item);
|
// Activate existing overlay
|
||||||
|
stack.add_overlay(name_arg.item.clone());
|
||||||
|
|
||||||
|
if let Some(module_id) = engine_state
|
||||||
|
.find_overlay(name_arg.item.as_bytes())
|
||||||
|
.map(|id| engine_state.get_overlay(id).origin)
|
||||||
|
{
|
||||||
|
if let Some(new_module_id) = engine_state.find_module(name_arg.item.as_bytes(), &[])
|
||||||
|
{
|
||||||
|
if module_id != new_module_id {
|
||||||
|
// The origin module of an overlay changed => update it
|
||||||
|
let module = engine_state.get_module(new_module_id);
|
||||||
|
|
||||||
|
for (name, block_id) in module.env_vars() {
|
||||||
|
let name = if let Ok(s) = String::from_utf8(name.clone()) {
|
||||||
|
s
|
||||||
|
} else {
|
||||||
|
return Err(ShellError::NonUtf8(name_arg.span));
|
||||||
|
};
|
||||||
|
|
||||||
|
let block = engine_state.get_block(block_id);
|
||||||
|
|
||||||
|
let val = eval_block(
|
||||||
|
engine_state,
|
||||||
|
stack,
|
||||||
|
block,
|
||||||
|
PipelineData::new(call.head),
|
||||||
|
false,
|
||||||
|
true,
|
||||||
|
)?
|
||||||
|
.into_value(call.head);
|
||||||
|
|
||||||
|
stack.add_env_var(name, val);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
|
// Create a new overlay from a module
|
||||||
let (overlay_name, module) =
|
let (overlay_name, module) =
|
||||||
if let Some(module_id) = engine_state.find_module(name_arg.item.as_bytes(), &[]) {
|
if let Some(module_id) = engine_state.find_module(name_arg.item.as_bytes(), &[]) {
|
||||||
(name_arg.item, engine_state.get_module(module_id))
|
(name_arg.item, engine_state.get_module(module_id))
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
extern crate nu_test_support;
|
extern crate nu_test_support;
|
||||||
|
|
||||||
|
mod nu_repl;
|
||||||
mod overlays;
|
mod overlays;
|
||||||
mod parsing;
|
mod parsing;
|
||||||
mod path;
|
mod path;
|
||||||
|
96
tests/nu_repl/mod.rs
Normal file
96
tests/nu_repl/mod.rs
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
use nu_command::create_default_context;
|
||||||
|
use nu_engine::eval_block;
|
||||||
|
use nu_parser::parse;
|
||||||
|
use nu_protocol::engine::{Stack, StateDelta, StateWorkingSet};
|
||||||
|
use nu_protocol::{PipelineData, Span, Value};
|
||||||
|
use nu_test_support::fs::in_directory;
|
||||||
|
use nu_test_support::Outcome;
|
||||||
|
|
||||||
|
fn outcome_err(msg: String) -> Outcome {
|
||||||
|
Outcome {
|
||||||
|
out: String::new(),
|
||||||
|
err: msg,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn outcome_ok(msg: String) -> Outcome {
|
||||||
|
Outcome {
|
||||||
|
out: msg,
|
||||||
|
err: String::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn nu_repl(cwd: &str, source_lines: &[&str]) -> Outcome {
|
||||||
|
let cwd = in_directory(cwd);
|
||||||
|
|
||||||
|
let mut engine_state = create_default_context(&cwd);
|
||||||
|
let mut stack = Stack::new();
|
||||||
|
|
||||||
|
stack.add_env_var(
|
||||||
|
"PWD".to_string(),
|
||||||
|
Value::String {
|
||||||
|
val: cwd.to_string(),
|
||||||
|
span: Span::test_data(),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
let delta = StateDelta::new(&engine_state);
|
||||||
|
if let Err(err) = engine_state.merge_delta(delta, Some(&mut stack), cwd) {
|
||||||
|
return outcome_err(format!("{:?}", &err));
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut last_output = String::new();
|
||||||
|
|
||||||
|
for (i, line) in source_lines.iter().enumerate() {
|
||||||
|
let (block, delta) = {
|
||||||
|
let mut working_set = StateWorkingSet::new(&engine_state);
|
||||||
|
let (block, err) = parse(
|
||||||
|
&mut working_set,
|
||||||
|
Some(&format!("line{}", i)),
|
||||||
|
line.as_bytes(),
|
||||||
|
false,
|
||||||
|
&[],
|
||||||
|
);
|
||||||
|
|
||||||
|
if let Some(err) = err {
|
||||||
|
return outcome_err(format!("{:?}", err));
|
||||||
|
}
|
||||||
|
(block, working_set.render())
|
||||||
|
};
|
||||||
|
|
||||||
|
let cwd = match nu_engine::env::current_dir(&engine_state, &stack) {
|
||||||
|
Ok(p) => p,
|
||||||
|
Err(e) => {
|
||||||
|
return outcome_err(format!("{:?}", &e));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if let Err(err) = engine_state.merge_delta(delta, Some(&mut stack), &cwd) {
|
||||||
|
return outcome_err(format!("{:?}", err));
|
||||||
|
}
|
||||||
|
|
||||||
|
let input = PipelineData::new(Span::test_data());
|
||||||
|
let config = engine_state.get_config();
|
||||||
|
|
||||||
|
match eval_block(&engine_state, &mut stack, &block, input, false, false) {
|
||||||
|
Ok(pipeline_data) => match pipeline_data.collect_string("", config) {
|
||||||
|
Ok(s) => last_output = s,
|
||||||
|
Err(err) => return outcome_err(format!("{:?}", err)),
|
||||||
|
},
|
||||||
|
Err(err) => return outcome_err(format!("{:?}", err)),
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME: permanent state changes like this hopefully in time can be removed
|
||||||
|
// and be replaced by just passing the cwd in where needed
|
||||||
|
if let Some(cwd) = stack.get_env_var(&engine_state, "PWD") {
|
||||||
|
let path = match cwd.as_string() {
|
||||||
|
Ok(p) => p,
|
||||||
|
Err(err) => return outcome_err(format!("{:?}", err)),
|
||||||
|
};
|
||||||
|
let _ = std::env::set_current_dir(path);
|
||||||
|
engine_state.add_env_var("PWD".into(), cwd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
outcome_ok(last_output)
|
||||||
|
}
|
@ -1,310 +1,342 @@
|
|||||||
|
use super::nu_repl::nu_repl;
|
||||||
use nu_test_support::{nu, pipeline};
|
use nu_test_support::{nu, pipeline};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn add_overlay() {
|
fn add_overlay() {
|
||||||
let actual = nu!(
|
let inp = &[
|
||||||
cwd: "tests/overlays", pipeline(
|
r#"module spam { export def foo [] { "foo" } }"#,
|
||||||
r#"
|
r#"overlay add spam"#,
|
||||||
module spam { export def foo [] { "foo" } };
|
r#"foo"#,
|
||||||
overlay add spam;
|
];
|
||||||
foo
|
|
||||||
"#
|
let actual = nu!(cwd: "tests/overlays", pipeline(&inp.join("; ")));
|
||||||
));
|
let actual_repl = nu_repl("tests/overlays", inp);
|
||||||
|
|
||||||
assert_eq!(actual.out, "foo");
|
assert_eq!(actual.out, "foo");
|
||||||
|
assert_eq!(actual_repl.out, "foo");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn add_overlay_env() {
|
fn add_overlay_env() {
|
||||||
let actual = nu!(
|
let inp = &[
|
||||||
cwd: "tests/overlays", pipeline(
|
r#"module spam { export env FOO { "foo" } }"#,
|
||||||
r#"
|
r#"overlay add spam"#,
|
||||||
module spam { export env FOO { "foo" } };
|
r#"$env.FOO"#,
|
||||||
overlay add spam;
|
];
|
||||||
$env.FOO
|
|
||||||
"#
|
let actual = nu!(cwd: "tests/overlays", pipeline(&inp.join("; ")));
|
||||||
));
|
let actual_repl = nu_repl("tests/overlays", inp);
|
||||||
|
|
||||||
assert_eq!(actual.out, "foo");
|
assert_eq!(actual.out, "foo");
|
||||||
|
assert_eq!(actual_repl.out, "foo");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn add_overlay_from_file_decl() {
|
fn add_overlay_from_file_decl() {
|
||||||
let actual = nu!(
|
let inp = &[r#"overlay add samples/spam.nu"#, r#"foo"#];
|
||||||
cwd: "tests/overlays", pipeline(
|
|
||||||
r#"
|
let actual = nu!(cwd: "tests/overlays", pipeline(&inp.join("; ")));
|
||||||
overlay add samples/spam.nu;
|
let actual_repl = nu_repl("tests/overlays", inp);
|
||||||
foo
|
|
||||||
"#
|
|
||||||
));
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "foo");
|
assert_eq!(actual.out, "foo");
|
||||||
|
assert_eq!(actual_repl.out, "foo");
|
||||||
|
}
|
||||||
|
|
||||||
|
// This one tests that the `nu_repl()` loop works correctly
|
||||||
|
#[test]
|
||||||
|
fn add_overlay_from_file_decl_cd() {
|
||||||
|
let inp = &[r#"cd samples"#, r#"overlay add spam.nu"#, r#"foo"#];
|
||||||
|
|
||||||
|
let actual_repl = nu_repl("tests/overlays", inp);
|
||||||
|
|
||||||
|
assert_eq!(actual_repl.out, "foo");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn add_overlay_from_file_alias() {
|
fn add_overlay_from_file_alias() {
|
||||||
let actual = nu!(
|
let inp = &[r#"overlay add samples/spam.nu"#, r#"bar"#];
|
||||||
cwd: "tests/overlays", pipeline(
|
|
||||||
r#"
|
let actual = nu!(cwd: "tests/overlays", pipeline(&inp.join("; ")));
|
||||||
overlay add samples/spam.nu;
|
let actual_repl = nu_repl("tests/overlays", inp);
|
||||||
bar
|
|
||||||
"#
|
|
||||||
));
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "bar");
|
assert_eq!(actual.out, "bar");
|
||||||
|
assert_eq!(actual_repl.out, "bar");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn add_overlay_from_file_env() {
|
fn add_overlay_from_file_env() {
|
||||||
let actual = nu!(
|
let inp = &[r#"overlay add samples/spam.nu"#, r#"$env.BAZ"#];
|
||||||
cwd: "tests/overlays", pipeline(
|
|
||||||
r#"
|
let actual = nu!(cwd: "tests/overlays", pipeline(&inp.join("; ")));
|
||||||
overlay add samples/spam.nu;
|
let actual_repl = nu_repl("tests/overlays", inp);
|
||||||
$env.BAZ
|
|
||||||
"#
|
|
||||||
));
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "baz");
|
assert_eq!(actual.out, "baz");
|
||||||
|
assert_eq!(actual_repl.out, "baz");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn add_overlay_scoped() {
|
fn add_overlay_scoped() {
|
||||||
let actual = nu!(
|
let inp = &[
|
||||||
cwd: "tests/overlays", pipeline(
|
r#"module spam { export def foo [] { "foo" } }"#,
|
||||||
r#"
|
r#"do { overlay add spam }"#,
|
||||||
module spam { export def foo [] { "foo" } };
|
r#"foo"#,
|
||||||
do { overlay add spam };
|
];
|
||||||
foo
|
|
||||||
"#
|
|
||||||
));
|
|
||||||
|
|
||||||
assert!(!actual.err.is_empty())
|
let actual = nu!(cwd: "tests/overlays", pipeline(&inp.join("; ")));
|
||||||
|
let actual_repl = nu_repl("tests/overlays", inp);
|
||||||
|
|
||||||
|
assert!(!actual.err.is_empty());
|
||||||
|
#[cfg(windows)]
|
||||||
|
assert!(actual_repl.out != "foo");
|
||||||
|
#[cfg(not(windows))]
|
||||||
|
assert!(!actual_repl.err.is_empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn update_overlay_from_module() {
|
fn update_overlay_from_module() {
|
||||||
let actual = nu!(
|
let inp = &[
|
||||||
cwd: "tests/overlays", pipeline(
|
r#"module spam { export def foo [] { "foo" } }"#,
|
||||||
r#"
|
r#"overlay add spam"#,
|
||||||
module spam { export def foo [] { "foo" } };
|
r#"module spam { export def foo [] { "bar" } }"#,
|
||||||
overlay add spam;
|
r#"overlay add spam"#,
|
||||||
module spam { export def foo [] { "bar" } };
|
r#"foo"#,
|
||||||
overlay add spam;
|
];
|
||||||
foo
|
|
||||||
"#
|
let actual = nu!(cwd: "tests/overlays", pipeline(&inp.join("; ")));
|
||||||
));
|
let actual_repl = nu_repl("tests/overlays", inp);
|
||||||
|
|
||||||
assert_eq!(actual.out, "bar");
|
assert_eq!(actual.out, "bar");
|
||||||
|
assert_eq!(actual_repl.out, "bar");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn update_overlay_from_module_env() {
|
fn update_overlay_from_module_env() {
|
||||||
let actual = nu!(
|
let inp = &[
|
||||||
cwd: "tests/overlays", pipeline(
|
r#"module spam { export env FOO { "foo" } }"#,
|
||||||
r#"
|
r#"overlay add spam"#,
|
||||||
module spam { export env FOO { "foo" } };
|
r#"module spam { export env FOO { "bar" } }"#,
|
||||||
overlay add spam;
|
r#"overlay add spam"#,
|
||||||
module spam { export env FOO { "bar" } };
|
r#"$env.FOO"#,
|
||||||
overlay add spam;
|
];
|
||||||
$env.FOO
|
|
||||||
"#
|
let actual = nu!(cwd: "tests/overlays", pipeline(&inp.join("; ")));
|
||||||
));
|
let actual_repl = nu_repl("tests/overlays", inp);
|
||||||
|
|
||||||
assert_eq!(actual.out, "bar");
|
assert_eq!(actual.out, "bar");
|
||||||
|
assert_eq!(actual_repl.out, "bar");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn remove_overlay() {
|
fn remove_overlay() {
|
||||||
let actual = nu!(
|
let inp = &[
|
||||||
cwd: "tests/overlays", pipeline(
|
r#"module spam { export def foo [] { "foo" } }"#,
|
||||||
r#"
|
r#"overlay add spam"#,
|
||||||
module spam { export def foo [] { "foo" } };
|
r#"overlay remove spam"#,
|
||||||
overlay add spam;
|
r#"foo"#,
|
||||||
overlay remove spam;
|
];
|
||||||
foo
|
|
||||||
"#
|
let actual = nu!(cwd: "tests/overlays", pipeline(&inp.join("; ")));
|
||||||
));
|
let actual_repl = nu_repl("tests/overlays", inp);
|
||||||
|
|
||||||
assert!(!actual.err.is_empty());
|
assert!(!actual.err.is_empty());
|
||||||
|
#[cfg(windows)]
|
||||||
|
assert!(actual_repl.out != "foo");
|
||||||
|
#[cfg(not(windows))]
|
||||||
|
assert!(!actual_repl.err.is_empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn remove_last_overlay() {
|
fn remove_last_overlay() {
|
||||||
let actual = nu!(
|
let inp = &[
|
||||||
cwd: "tests/overlays", pipeline(
|
r#"module spam { export def foo [] { "foo" } }"#,
|
||||||
r#"
|
r#"overlay add spam"#,
|
||||||
module spam { export def foo [] { "foo" } };
|
r#"overlay remove"#,
|
||||||
overlay add spam;
|
r#"foo"#,
|
||||||
overlay remove;
|
];
|
||||||
foo
|
|
||||||
"#
|
let actual = nu!(cwd: "tests/overlays", pipeline(&inp.join("; ")));
|
||||||
));
|
let actual_repl = nu_repl("tests/overlays", inp);
|
||||||
|
|
||||||
assert!(!actual.err.is_empty());
|
assert!(!actual.err.is_empty());
|
||||||
|
#[cfg(windows)]
|
||||||
|
assert!(actual_repl.out != "foo");
|
||||||
|
#[cfg(not(windows))]
|
||||||
|
assert!(!actual_repl.err.is_empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn remove_overlay_scoped() {
|
fn remove_overlay_scoped() {
|
||||||
let actual = nu!(
|
let inp = &[
|
||||||
cwd: "tests/overlays", pipeline(
|
r#"module spam { export def foo [] { "foo" } }"#,
|
||||||
r#"
|
r#"overlay add spam"#,
|
||||||
module spam { export def foo [] { "foo" } };
|
r#"do { overlay remove spam }"#,
|
||||||
overlay add spam;
|
r#"foo"#,
|
||||||
do {
|
];
|
||||||
overlay remove spam
|
|
||||||
};
|
let actual = nu!(cwd: "tests/overlays", pipeline(&inp.join("; ")));
|
||||||
foo
|
let actual_repl = nu_repl("tests/overlays", inp);
|
||||||
"#
|
|
||||||
));
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "foo");
|
assert_eq!(actual.out, "foo");
|
||||||
|
assert_eq!(actual_repl.out, "foo");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn remove_overlay_env() {
|
fn remove_overlay_env() {
|
||||||
let actual = nu!(
|
let inp = &[
|
||||||
cwd: "tests/overlays", pipeline(
|
r#"module spam { export env FOO { "foo" } }"#,
|
||||||
r#"
|
r#"overlay add spam"#,
|
||||||
module spam { export env FOO { "foo" } };
|
r#"overlay remove spam"#,
|
||||||
overlay add spam;
|
r#"$env.FOO"#,
|
||||||
overlay remove spam;
|
];
|
||||||
$env.FOO
|
|
||||||
"#
|
let actual = nu!(cwd: "tests/overlays", pipeline(&inp.join("; ")));
|
||||||
));
|
let actual_repl = nu_repl("tests/overlays", inp);
|
||||||
|
|
||||||
assert!(actual.err.contains("did you mean"));
|
assert!(actual.err.contains("did you mean"));
|
||||||
|
assert!(actual_repl.err.contains("DidYouMean"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn remove_overlay_scoped_env() {
|
fn remove_overlay_scoped_env() {
|
||||||
let actual = nu!(
|
let inp = &[
|
||||||
cwd: "tests/overlays", pipeline(
|
r#"module spam { export env FOO { "foo" } }"#,
|
||||||
r#"
|
r#"overlay add spam"#,
|
||||||
module spam { export env FOO { "foo" } };
|
r#"do { overlay remove spam }"#,
|
||||||
overlay add spam;
|
r#"$env.FOO"#,
|
||||||
do {
|
];
|
||||||
overlay remove spam
|
|
||||||
};
|
let actual = nu!(cwd: "tests/overlays", pipeline(&inp.join("; ")));
|
||||||
$env.FOO
|
let actual_repl = nu_repl("tests/overlays", inp);
|
||||||
"#
|
|
||||||
));
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "foo");
|
assert_eq!(actual.out, "foo");
|
||||||
|
assert_eq!(actual_repl.out, "foo");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn list_default_overlay() {
|
fn list_default_overlay() {
|
||||||
let actual = nu!(
|
let inp = &[r#"overlay list | last"#];
|
||||||
cwd: "tests/overlays", pipeline(
|
|
||||||
r#"
|
let actual = nu!(cwd: "tests/overlays", pipeline(&inp.join("; ")));
|
||||||
overlay list | last
|
let actual_repl = nu_repl("tests/overlays", inp);
|
||||||
"#,
|
|
||||||
));
|
|
||||||
|
|
||||||
assert_eq!(actual.out, "zero");
|
assert_eq!(actual.out, "zero");
|
||||||
|
assert_eq!(actual_repl.out, "zero");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn list_last_overlay() {
|
fn list_last_overlay() {
|
||||||
let actual = nu!(
|
let inp = &[
|
||||||
cwd: "tests/overlays", pipeline(
|
r#"module spam { export def foo [] { "foo" } }"#,
|
||||||
r#"
|
r#"overlay add spam"#,
|
||||||
module spam { export def foo [] { "foo" } };
|
r#"overlay list | last"#,
|
||||||
overlay add spam;
|
];
|
||||||
overlay list | last
|
|
||||||
"#,
|
let actual = nu!(cwd: "tests/overlays", pipeline(&inp.join("; ")));
|
||||||
));
|
let actual_repl = nu_repl("tests/overlays", inp);
|
||||||
|
|
||||||
assert_eq!(actual.out, "spam");
|
assert_eq!(actual.out, "spam");
|
||||||
|
assert_eq!(actual_repl.out, "spam");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn list_overlay_scoped() {
|
fn list_overlay_scoped() {
|
||||||
let actual = nu!(
|
let inp = &[
|
||||||
cwd: "tests/overlays", pipeline(
|
r#"module spam { export def foo [] { "foo" } }"#,
|
||||||
r#"
|
r#"overlay add spam"#,
|
||||||
module spam { export def foo [] { "foo" } };
|
r#"do { overlay list | last }"#,
|
||||||
overlay add spam;
|
];
|
||||||
do { overlay list | last }
|
|
||||||
"#
|
let actual = nu!(cwd: "tests/overlays", pipeline(&inp.join("; ")));
|
||||||
));
|
let actual_repl = nu_repl("tests/overlays", inp);
|
||||||
|
|
||||||
assert_eq!(actual.out, "spam");
|
assert_eq!(actual.out, "spam");
|
||||||
|
assert_eq!(actual_repl.out, "spam");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn remove_overlay_discard_decl() {
|
fn remove_overlay_discard_decl() {
|
||||||
let actual = nu!(
|
let inp = &[
|
||||||
cwd: "tests/overlays", pipeline(
|
r#"overlay add samples/spam.nu"#,
|
||||||
r#"
|
r#"def bagr [] { "bagr" }"#,
|
||||||
overlay add samples/spam.nu;
|
r#"overlay remove spam"#,
|
||||||
def bagr [] { "bagr" };
|
r#"bagr"#,
|
||||||
overlay remove spam;
|
];
|
||||||
bagr
|
|
||||||
"#
|
let actual = nu!(cwd: "tests/overlays", pipeline(&inp.join("; ")));
|
||||||
));
|
let actual_repl = nu_repl("tests/overlays", inp);
|
||||||
|
|
||||||
assert!(!actual.err.is_empty());
|
assert!(!actual.err.is_empty());
|
||||||
|
#[cfg(windows)]
|
||||||
|
assert!(actual_repl.out != "bagr");
|
||||||
|
#[cfg(not(windows))]
|
||||||
|
assert!(!actual_repl.err.is_empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn remove_overlay_discard_alias() {
|
fn remove_overlay_discard_alias() {
|
||||||
let actual = nu!(
|
let inp = &[
|
||||||
cwd: "tests/overlays", pipeline(
|
r#"overlay add samples/spam.nu"#,
|
||||||
r#"
|
r#"alias bagr = "bagr""#,
|
||||||
overlay add samples/spam.nu;
|
r#"overlay remove spam"#,
|
||||||
alias bagr = "bagr";
|
r#"bagr"#,
|
||||||
overlay remove spam;
|
];
|
||||||
bagr
|
|
||||||
"#
|
let actual = nu!(cwd: "tests/overlays", pipeline(&inp.join("; ")));
|
||||||
));
|
let actual_repl = nu_repl("tests/overlays", inp);
|
||||||
|
|
||||||
assert!(!actual.err.is_empty());
|
assert!(!actual.err.is_empty());
|
||||||
|
#[cfg(windows)]
|
||||||
|
assert!(actual_repl.out != "bagr");
|
||||||
|
#[cfg(not(windows))]
|
||||||
|
assert!(!actual_repl.err.is_empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn remove_overlay_discard_env() {
|
fn remove_overlay_discard_env() {
|
||||||
let actual = nu!(
|
let inp = &[
|
||||||
cwd: "tests/overlays", pipeline(
|
r#"overlay add samples/spam.nu"#,
|
||||||
r#"
|
r#"let-env BAGR = "bagr""#,
|
||||||
overlay add samples/spam.nu;
|
r#"overlay remove spam"#,
|
||||||
let-env BAGR = "bagr";
|
r#"$env.BAGR"#,
|
||||||
overlay remove spam;
|
];
|
||||||
$env.bagr
|
|
||||||
"#
|
let actual = nu!(cwd: "tests/overlays", pipeline(&inp.join("; ")));
|
||||||
));
|
let actual_repl = nu_repl("tests/overlays", inp);
|
||||||
|
|
||||||
assert!(actual.err.contains("did you mean"));
|
assert!(actual.err.contains("did you mean"));
|
||||||
|
assert!(actual_repl.err.contains("DidYouMean"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn preserve_overrides() {
|
fn preserve_overrides() {
|
||||||
let actual = nu!(
|
let inp = &[
|
||||||
cwd: "tests/overlays", pipeline(
|
r#"overlay add samples/spam.nu"#,
|
||||||
r#"
|
r#"def foo [] { "new-foo" }"#,
|
||||||
overlay add samples/spam.nu;
|
r#"overlay remove spam"#,
|
||||||
def foo [] { "new-foo" };
|
r#"overlay add spam"#,
|
||||||
overlay remove spam;
|
r#"foo"#,
|
||||||
overlay add spam;
|
];
|
||||||
foo
|
|
||||||
"#
|
let actual = nu!(cwd: "tests/overlays", pipeline(&inp.join("; ")));
|
||||||
));
|
let actual_repl = nu_repl("tests/overlays", inp);
|
||||||
|
|
||||||
assert_eq!(actual.out, "new-foo");
|
assert_eq!(actual.out, "new-foo");
|
||||||
|
assert_eq!(actual_repl.out, "new-foo");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn reset_overrides() {
|
fn reset_overrides() {
|
||||||
let actual = nu!(
|
let inp = &[
|
||||||
cwd: "tests/overlays", pipeline(
|
r#"overlay add samples/spam.nu"#,
|
||||||
r#"
|
r#"def foo [] { "new-foo" }"#,
|
||||||
overlay add samples/spam.nu;
|
r#"overlay remove spam"#,
|
||||||
def foo [] { "new-foo" };
|
r#"overlay add samples/spam.nu"#,
|
||||||
overlay remove spam;
|
r#"foo"#,
|
||||||
overlay add samples/spam.nu;
|
];
|
||||||
foo
|
|
||||||
"#
|
let actual = nu!(cwd: "tests/overlays", pipeline(&inp.join("; ")));
|
||||||
));
|
let actual_repl = nu_repl("tests/overlays", inp);
|
||||||
|
|
||||||
assert_eq!(actual.out, "foo");
|
assert_eq!(actual.out, "foo");
|
||||||
|
assert_eq!(actual_repl.out, "foo");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user