Move from source to source-env (#6277)

* start working on source-env

* WIP

* Get most tests working, still one to go

* Fix file-relative paths; Report parser error

* Fix merge conflicts; Restore source as deprecated

* Tests: Use source-env; Remove redundant tests

* Fmt

* Respect hidden env vars

* Fix file-relative eval for source-env

* Add file-relative eval to "overlay use"

* Use FILE_PWD only in source-env and "overlay use"

* Ignore new tests for now

This will be another issue

* Throw an error if setting FILE_PWD manually

* Fix source-related test failures

* Fix nu-check to respect FILE_PWD

* Fix corrupted spans in source-env shell errors

* Fix up some references to old source

* Remove deprecation message

* Re-introduce deleted tests

Co-authored-by: kubouch <kubouch@gmail.com>
This commit is contained in:
JT
2022-09-01 08:32:56 +12:00
committed by GitHub
parent 11531b7630
commit c52d45cb97
33 changed files with 726 additions and 175 deletions

View File

@ -5,7 +5,9 @@ fn alias_simple() {
let actual = nu!(
cwd: "tests/fixtures/formats", pipeline(
r#"
alias bar = source sample_def.nu; bar; greet
alias bar = use sample_def.nu greet;
bar;
greet
"#
));
@ -13,12 +15,12 @@ fn alias_simple() {
}
#[test]
fn alias_hiding1() {
fn alias_hiding_1() {
let actual = nu!(
cwd: "tests/fixtures/formats", pipeline(
r#"
source ./activate-foo.nu;
$nu.scope.aliases | find deactivate-foo | length
overlay use ./activate-foo.nu;
$nu.scope.aliases | find deactivate-foo | length
"#
));
@ -26,13 +28,13 @@ fn alias_hiding1() {
}
#[test]
fn alias_hiding2() {
fn alias_hiding_2() {
let actual = nu!(
cwd: "tests/fixtures/formats", pipeline(
r#"
source ./activate-foo.nu;
deactivate-foo;
$nu.scope.aliases | find deactivate-foo | length
overlay use ./activate-foo.nu;
deactivate-foo;
$nu.scope.aliases | find deactivate-foo | length
"#
));

View File

@ -7,12 +7,12 @@ fn def_with_comment() {
Playground::setup("def_with_comment", |dirs, _| {
let data = r#"
#My echo
def e [arg] {echo $arg}
export def e [arg] {echo $arg}
"#;
fs::write(dirs.root().join("def_test"), data).expect("Unable to write file");
let actual = nu!(
cwd: dirs.root(),
"source def_test; help e | to json -r"
"use def_test e; help e | to json -r"
);
assert!(actual.out.contains("My echo\\n\\n"));

View File

@ -69,7 +69,7 @@ mod semicolon;
mod shells;
mod skip;
mod sort_by;
mod source;
mod source_env;
mod split_by;
mod split_column;
mod split_row;

View File

@ -216,7 +216,9 @@ fn parse_dir_failure() {
"#
));
assert!(actual.err.contains("Path is not a file"));
assert!(actual
.err
.contains("File extension must be the type of .nu"));
})
}
@ -733,7 +735,7 @@ fn parse_script_with_nested_scripts_success() {
.with_files(vec![FileWithContentToBeTrimmed(
"lol/lol.nu",
r#"
source ../foo.nu
source-env ../foo.nu
use lol_shell.nu
overlay use ../lol/lol_shell.nu
"#,
@ -761,3 +763,33 @@ fn parse_script_with_nested_scripts_success() {
assert_eq!(actual.out, "true");
})
}
#[test]
fn nu_check_respects_file_pwd() {
Playground::setup("nu_check_test_25", |dirs, sandbox| {
sandbox
.mkdir("lol")
.with_files(vec![FileWithContentToBeTrimmed(
"lol/lol.nu",
r#"
let-env RETURN = (nu-check ../foo.nu)
"#,
)])
.with_files(vec![FileWithContentToBeTrimmed(
"foo.nu",
r#"
echo 'foo'
"#,
)]);
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
source-env lol/lol.nu;
$env.RETURN
"#
));
assert_eq!(actual.out, "true");
})
}

View File

@ -25,22 +25,20 @@ fn sources_also_files_under_custom_lib_dirs_path() {
nu.within("lib").with_files(vec![FileWithContent(
"my_library.nu",
r#"
source my_library/main.nu
source-env my_library/main.nu
"#,
)]);
nu.within("lib/my_library").with_files(vec![FileWithContent(
"main.nu",
r#"
def hello [] {
echo "hello nu"
}
let-env hello = "hello nu"
"#,
)]);
let actual = nu!(
cwd: ".", pipeline(
r#"
source my_library.nu ;
source-env my_library.nu ;
hello
"#
@ -59,7 +57,7 @@ fn try_source_foo_with_double_quotes_in(testdir: &str, playdir: &str) {
sandbox.mkdir(&testdir);
sandbox.with_files(vec![FileWithContent(&foo_file, "echo foo")]);
let cmd = String::from("source ") + r#"""# + foo_file.as_str() + r#"""#;
let cmd = String::from("source-env ") + r#"""# + foo_file.as_str() + r#"""#;
let actual = nu!(cwd: dirs.test(), &cmd);
@ -76,7 +74,7 @@ fn try_source_foo_with_single_quotes_in(testdir: &str, playdir: &str) {
sandbox.mkdir(&testdir);
sandbox.with_files(vec![FileWithContent(&foo_file, "echo foo")]);
let cmd = String::from("source ") + r#"'"# + foo_file.as_str() + r#"'"#;
let cmd = String::from("source-env ") + r#"'"# + foo_file.as_str() + r#"'"#;
let actual = nu!(cwd: dirs.test(), &cmd);
@ -93,7 +91,7 @@ fn try_source_foo_without_quotes_in(testdir: &str, playdir: &str) {
sandbox.mkdir(&testdir);
sandbox.with_files(vec![FileWithContent(&foo_file, "echo foo")]);
let cmd = String::from("source ") + foo_file.as_str();
let cmd = String::from("source-env ") + foo_file.as_str();
let actual = nu!(cwd: dirs.test(), &cmd);

View File

@ -3,7 +3,7 @@ use nu_test_support::playground::Playground;
use nu_test_support::{nu, pipeline};
const ZIP_POWERED_TEST_ASSERTION_SCRIPT: &str = r#"
def expect [
export def expect [
left,
--to-eq,
right
@ -26,7 +26,7 @@ fn zips_two_tables() {
cwd: ".", pipeline(
&format!(
r#"
source {} ;
use {} expect ;
let contributors = ([
[name, commits];
@ -51,8 +51,8 @@ fn zips_two_lists() {
let actual = nu!(
cwd: ".", pipeline(
r#"
echo [0 2 4 6 8] | zip [1 3 5 7 9] | flatten | into string | str collect '-'
"#
echo [0 2 4 6 8] | zip [1 3 5 7 9] | flatten | into string | str collect '-'
"#
));
assert_eq!(actual.out, "0-1-2-3-4-5-6-7-8-9");