Allow "export-env" parsing in modules (#6382)

* Allow "export-env" parsing in modules

* Fmt

* Add test for importing module's environment
This commit is contained in:
Jakub Žádník
2022-08-23 10:45:17 +03:00
committed by GitHub
parent 839b264261
commit d97975e9fa
4 changed files with 126 additions and 12 deletions

View File

@@ -345,3 +345,21 @@ fn module_nested_imports_in_dirs_prefixed() {
assert_eq!(actual.out, "bar");
})
}
#[test]
fn module_eval_export_env() {
Playground::setup("module_eval_export_env", |dirs, sandbox| {
sandbox.with_files(vec![FileWithContentToBeTrimmed(
"spam.nu",
r#"
export-env { let-env FOO = 'foo' }
"#,
)]);
let inp = &[r#"source spam.nu"#, r#"$env.FOO"#];
let actual = nu!(cwd: dirs.test(), pipeline(&inp.join("; ")));
assert_eq!(actual.out, "foo");
})
}

View File

@@ -151,3 +151,23 @@ fn parse_file_relative_to_parsed_file_dont_use_cwd_2() {
assert!(actual.err.contains("File not found"));
})
}
#[test]
fn parse_export_env_in_module() {
let actual = nu!(cwd: "tests/parsing/samples",
r#"
module spam { export-env { } }
"#);
assert!(actual.err.is_empty());
}
#[test]
fn parse_export_env_missing_block() {
let actual = nu!(cwd: "tests/parsing/samples",
r#"
module spam { export-env }
"#);
assert!(actual.err.contains("missing block"));
}