forked from extern/nushell
remove several export env usage in test code
This commit is contained in:
parent
0b080338a9
commit
3f7b5657c9
@ -54,14 +54,6 @@ impl Command for Module {
|
||||
span: Span::test_data(),
|
||||
}),
|
||||
},
|
||||
Example {
|
||||
description: "Define an environment variable in a module and evaluate it",
|
||||
example: r#"module foo { export env FOO_ENV { "BAZ" } }; use foo FOO_ENV; $env.FOO_ENV"#,
|
||||
result: Some(Value::String {
|
||||
val: "BAZ".to_string(),
|
||||
span: Span::test_data(),
|
||||
}),
|
||||
},
|
||||
Example {
|
||||
description: "Define a custom command that participates in the environment in a module and call it",
|
||||
example: r#"module foo { export def-env bar [] { let-env FOO_BAR = "BAZ" } }; use foo bar; bar; $env.FOO_BAR"#,
|
||||
|
@ -125,7 +125,7 @@ impl Command for OverlayHide {
|
||||
},
|
||||
Example {
|
||||
description: "Hide the last activated overlay",
|
||||
example: r#"module spam { export env FOO { "foo" } }
|
||||
example: r#"module spam { export-env { let-env FOO = "foo" } }
|
||||
overlay use spam
|
||||
overlay hide"#,
|
||||
result: None,
|
||||
|
@ -199,7 +199,7 @@ impl Command for OverlayUse {
|
||||
},
|
||||
Example {
|
||||
description: "Create an overlay from a file",
|
||||
example: r#"echo 'export env FOO { "foo" }' | save spam.nu
|
||||
example: r#"echo 'export-env { let-env FOO = "foo" }' | save spam.nu
|
||||
overlay use spam.nu
|
||||
$env.FOO"#,
|
||||
result: None,
|
||||
|
@ -145,14 +145,6 @@ impl Command for Use {
|
||||
span: Span::test_data(),
|
||||
}),
|
||||
},
|
||||
Example {
|
||||
description: "Define an environment variable in a module and evaluate it",
|
||||
example: r#"module foo { export env FOO_ENV { "BAZ" } }; use foo FOO_ENV; $env.FOO_ENV"#,
|
||||
result: Some(Value::String {
|
||||
val: "BAZ".to_string(),
|
||||
span: Span::test_data(),
|
||||
}),
|
||||
},
|
||||
Example {
|
||||
description: "Define a custom command that participates in the environment in a module and call it",
|
||||
example: r#"module foo { export def-env bar [] { let-env FOO_BAR = "BAZ" } }; use foo bar; bar; $env.FOO_BAR"#,
|
||||
|
@ -189,9 +189,9 @@ impl Command for ViewSource {
|
||||
},
|
||||
Example {
|
||||
description: "View the source of a module",
|
||||
example: r#"module mod-foo { export env FOO_ENV { 'BAZ' } }; view-source mod-foo"#,
|
||||
example: r#"module mod-foo { export-env { let-env FOO_ENV = 'BAZ' } }; view-source mod-foo"#,
|
||||
result: Some(Value::String {
|
||||
val: " export env FOO_ENV { 'BAZ' }".to_string(),
|
||||
val: " export-env { let-env FOO_ENV = 'BAZ' }".to_string(),
|
||||
span: Span::test_data(),
|
||||
}),
|
||||
},
|
||||
|
@ -230,7 +230,7 @@ fn parse_module_success_2() {
|
||||
r#"
|
||||
# foo.nu
|
||||
|
||||
export env MYNAME { "Arthur, King of the Britons" }
|
||||
export-env { let-env MYNAME = "Arthur, King of the Britons" }
|
||||
"#,
|
||||
)]);
|
||||
|
||||
|
@ -1084,94 +1084,6 @@ pub fn parse_export_in_module(
|
||||
|
||||
exportables
|
||||
}
|
||||
b"env" => {
|
||||
if let Some(id) = working_set.find_decl(b"export env", &Type::Any) {
|
||||
call.decl_id = id;
|
||||
} else {
|
||||
return (
|
||||
garbage_pipeline(spans),
|
||||
vec![],
|
||||
Some(ParseError::InternalError(
|
||||
"missing 'export env' command".into(),
|
||||
export_span,
|
||||
)),
|
||||
);
|
||||
}
|
||||
|
||||
let sig = working_set.get_decl(call.decl_id);
|
||||
let call_signature = sig.signature().call_signature();
|
||||
|
||||
call.head = span(&spans[0..=1]);
|
||||
|
||||
let mut result = vec![];
|
||||
|
||||
if let Some(name_span) = spans.get(2) {
|
||||
let (name_expr, err) =
|
||||
parse_string(working_set, *name_span, expand_aliases_denylist);
|
||||
error = error.or(err);
|
||||
call.add_positional(name_expr);
|
||||
|
||||
let env_var_name = working_set.get_span_contents(*name_span).to_vec();
|
||||
|
||||
if let Some(block_span) = spans.get(3) {
|
||||
let (block_expr, err) = parse_block_expression(
|
||||
working_set,
|
||||
&SyntaxShape::Block(None),
|
||||
*block_span,
|
||||
expand_aliases_denylist,
|
||||
);
|
||||
error = error.or(err);
|
||||
|
||||
if let Expression {
|
||||
expr: Expr::Block(block_id),
|
||||
..
|
||||
} = block_expr
|
||||
{
|
||||
result.push(Exportable::EnvVar {
|
||||
name: env_var_name,
|
||||
id: block_id,
|
||||
});
|
||||
} else {
|
||||
error = error.or_else(|| {
|
||||
Some(ParseError::InternalError(
|
||||
"block was not parsed as a block".into(),
|
||||
*block_span,
|
||||
))
|
||||
});
|
||||
}
|
||||
|
||||
call.add_positional(block_expr);
|
||||
} else {
|
||||
let err_span = Span {
|
||||
start: name_span.end,
|
||||
end: name_span.end,
|
||||
};
|
||||
|
||||
error = error.or_else(|| {
|
||||
Some(ParseError::MissingPositional(
|
||||
"block".into(),
|
||||
err_span,
|
||||
call_signature,
|
||||
))
|
||||
});
|
||||
}
|
||||
} else {
|
||||
let err_span = Span {
|
||||
start: kw_span.end,
|
||||
end: kw_span.end,
|
||||
};
|
||||
|
||||
error = error.or_else(|| {
|
||||
Some(ParseError::MissingPositional(
|
||||
"environment variable name".into(),
|
||||
err_span,
|
||||
call_signature,
|
||||
))
|
||||
});
|
||||
}
|
||||
|
||||
result
|
||||
}
|
||||
_ => {
|
||||
error = error.or_else(|| {
|
||||
Some(ParseError::Expected(
|
||||
@ -1336,7 +1248,6 @@ pub fn parse_module_block(
|
||||
error = error.or(err);
|
||||
|
||||
for pipeline in &output.block {
|
||||
// TODO: Should we add export env predecls as well?
|
||||
if pipeline.commands.len() == 1 {
|
||||
parse_def_predecl(
|
||||
working_set,
|
||||
|
@ -43,7 +43,7 @@ fn module_def_imports_5() -> TestResult {
|
||||
#[test]
|
||||
fn module_env_imports_1() -> TestResult {
|
||||
run_test(
|
||||
r#"module foo { export env a { '1' } }; use foo; $env.'foo a'"#,
|
||||
r#"module foo { export-env { let-env a = '1' } }; overlay use foo; $env.a"#,
|
||||
"1",
|
||||
)
|
||||
}
|
||||
@ -51,31 +51,15 @@ fn module_env_imports_1() -> TestResult {
|
||||
#[test]
|
||||
fn module_env_imports_2() -> TestResult {
|
||||
run_test(
|
||||
r#"module foo { export env a { '1' } }; use foo a; $env.a"#,
|
||||
"1",
|
||||
r#"module foo { export-env { let-env a = '1'; let-env b = '2' } }; overlay use foo; $env.b"#,
|
||||
"2",
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn module_env_imports_3() -> TestResult {
|
||||
run_test(
|
||||
r#"module foo { export env a { '1' }; export env b { '2' } }; use foo *; $env.b"#,
|
||||
"2",
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn module_env_imports_4() -> TestResult {
|
||||
fail_test(
|
||||
r#"module foo { export env a { '1' }; export env b { '2' } }; use foo c"#,
|
||||
"not find import",
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn module_env_imports_5() -> TestResult {
|
||||
run_test(
|
||||
r#"module foo { export env a { '1' }; export env b { '2' }; export env c { '3' } }; use foo [a, c]; $env.c"#,
|
||||
r#"module foo { export-env { let-env a = '1' }; export-env { let-env b = '2' }; export-env {let-env c = '3'} }; overlay use foo; $env.c"#,
|
||||
"3",
|
||||
)
|
||||
}
|
||||
@ -83,7 +67,7 @@ fn module_env_imports_5() -> TestResult {
|
||||
#[test]
|
||||
fn module_def_and_env_imports_1() -> TestResult {
|
||||
run_test(
|
||||
r#"module spam { export env foo { "foo" }; export def foo [] { "bar" } }; use spam foo; $env.foo"#,
|
||||
r#"module spam { export-env { let-env foo = "foo" }; export def foo [] { "bar" } }; overlay use spam; $env.foo"#,
|
||||
"foo",
|
||||
)
|
||||
}
|
||||
@ -91,7 +75,7 @@ fn module_def_and_env_imports_1() -> TestResult {
|
||||
#[test]
|
||||
fn module_def_and_env_imports_2() -> TestResult {
|
||||
run_test(
|
||||
r#"module spam { export env foo { "foo" }; export def foo [] { "bar" } }; use spam foo; foo"#,
|
||||
r#"module spam { export-env { let-env foo = "foo" }; export def foo [] { "bar" } }; use spam foo; foo"#,
|
||||
"bar",
|
||||
)
|
||||
}
|
||||
@ -107,7 +91,7 @@ fn module_def_import_uses_internal_command() -> TestResult {
|
||||
#[test]
|
||||
fn module_env_import_uses_internal_command() -> TestResult {
|
||||
run_test(
|
||||
r#"module foo { def b [] { "2" }; export env a { b } }; use foo; $env.'foo a'"#,
|
||||
r#"module foo { def b [] { "2" }; export-env { let-env a = b } }; use foo; overlay use foo; $env.a"#,
|
||||
"2",
|
||||
)
|
||||
}
|
||||
|
@ -116,7 +116,7 @@ fn prefixed_overlay_keeps_custom_decl() {
|
||||
#[test]
|
||||
fn add_overlay_env() {
|
||||
let inp = &[
|
||||
r#"module spam { export env FOO { "foo" } }"#,
|
||||
r#"module spam { export-env { let-env FOO = "foo" } }"#,
|
||||
r#"overlay use spam"#,
|
||||
r#"$env.FOO"#,
|
||||
];
|
||||
@ -131,7 +131,7 @@ fn add_overlay_env() {
|
||||
#[test]
|
||||
fn add_prefixed_overlay_env_no_prefix() {
|
||||
let inp = &[
|
||||
r#"module spam { export env FOO { "foo" } }"#,
|
||||
r#"module spam { export-env { let-env FOO = "foo" } }"#,
|
||||
r#"overlay use --prefix spam"#,
|
||||
r#"$env.FOO"#,
|
||||
];
|
||||
@ -224,9 +224,9 @@ fn update_overlay_from_module() {
|
||||
#[test]
|
||||
fn update_overlay_from_module_env() {
|
||||
let inp = &[
|
||||
r#"module spam { export env FOO { "foo" } }"#,
|
||||
r#"module spam { export-env { let-env FOO = "foo" } }"#,
|
||||
r#"overlay use spam"#,
|
||||
r#"module spam { export env FOO { "bar" } }"#,
|
||||
r#"module spam { export-env { let-env FOO = "bar" } }"#,
|
||||
r#"overlay use spam"#,
|
||||
r#"$env.FOO"#,
|
||||
];
|
||||
@ -295,7 +295,7 @@ fn remove_overlay_scoped() {
|
||||
#[test]
|
||||
fn remove_overlay_env() {
|
||||
let inp = &[
|
||||
r#"module spam { export env FOO { "foo" } }"#,
|
||||
r#"module spam { export-env { let-env FOO = "foo" } }"#,
|
||||
r#"overlay use spam"#,
|
||||
r#"overlay hide spam"#,
|
||||
r#"$env.FOO"#,
|
||||
@ -311,7 +311,7 @@ fn remove_overlay_env() {
|
||||
#[test]
|
||||
fn remove_overlay_scoped_env() {
|
||||
let inp = &[
|
||||
r#"module spam { export env FOO { "foo" } }"#,
|
||||
r#"module spam { export-env { let-env FOO = "foo" } }"#,
|
||||
r#"overlay use spam"#,
|
||||
r#"do { overlay hide spam }"#,
|
||||
r#"$env.FOO"#,
|
||||
|
Loading…
Reference in New Issue
Block a user