2022-07-27 17:36:56 +02:00
|
|
|
use nu_test_support::fs::Stub::FileWithContentToBeTrimmed;
|
|
|
|
use nu_test_support::playground::Playground;
|
|
|
|
use nu_test_support::{nu, pipeline};
|
2022-03-05 14:20:13 +01:00
|
|
|
|
2022-11-15 00:05:27 +01:00
|
|
|
#[test]
|
|
|
|
fn source_file_relative_to_file() {
|
|
|
|
let actual = nu!(cwd: "tests/parsing/samples", r#"
|
|
|
|
nu source_file_relative.nu
|
|
|
|
"#);
|
|
|
|
|
2023-01-09 06:53:52 +01:00
|
|
|
assert_eq!(actual.out, "5");
|
2022-11-15 00:05:27 +01:00
|
|
|
}
|
|
|
|
|
2022-12-21 23:21:03 +01:00
|
|
|
#[test]
|
|
|
|
fn source_const_file() {
|
|
|
|
let actual = nu!(cwd: "tests/parsing/samples",
|
|
|
|
r#"
|
|
|
|
const file = 'single_line.nu'
|
|
|
|
source $file
|
|
|
|
"#);
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "5");
|
|
|
|
}
|
|
|
|
|
2022-03-05 14:20:13 +01:00
|
|
|
#[test]
|
|
|
|
fn run_nu_script_single_line() {
|
|
|
|
let actual = nu!(cwd: "tests/parsing/samples", r#"
|
|
|
|
nu single_line.nu
|
|
|
|
"#);
|
|
|
|
|
2023-01-09 06:53:52 +01:00
|
|
|
assert_eq!(actual.out, "5");
|
2022-03-05 14:20:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn run_nu_script_multiline_start_pipe() {
|
|
|
|
let actual = nu!(cwd: "tests/parsing/samples", r#"
|
|
|
|
nu multiline_start_pipe.nu
|
|
|
|
"#);
|
|
|
|
|
2023-01-09 06:53:52 +01:00
|
|
|
assert_eq!(actual.out, "4");
|
2022-03-05 14:20:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn run_nu_script_multiline_start_pipe_win() {
|
|
|
|
let actual = nu!(cwd: "tests/parsing/samples", r#"
|
|
|
|
nu multiline_start_pipe_win.nu
|
|
|
|
"#);
|
|
|
|
|
2023-01-09 06:53:52 +01:00
|
|
|
assert_eq!(actual.out, "3");
|
2022-03-05 14:20:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn run_nu_script_multiline_end_pipe() {
|
|
|
|
let actual = nu!(cwd: "tests/parsing/samples", r#"
|
|
|
|
nu multiline_end_pipe.nu
|
|
|
|
"#);
|
|
|
|
|
2023-01-09 06:53:52 +01:00
|
|
|
assert_eq!(actual.out, "2");
|
2022-03-05 14:20:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn run_nu_script_multiline_end_pipe_win() {
|
|
|
|
let actual = nu!(cwd: "tests/parsing/samples", r#"
|
|
|
|
nu multiline_end_pipe_win.nu
|
|
|
|
"#);
|
|
|
|
|
2023-01-09 06:53:52 +01:00
|
|
|
assert_eq!(actual.out, "3");
|
2022-03-05 14:20:13 +01:00
|
|
|
}
|
2022-07-27 17:36:56 +02:00
|
|
|
|
2022-08-31 22:32:56 +02:00
|
|
|
#[test]
|
|
|
|
fn parse_file_relative_to_parsed_file_simple() {
|
|
|
|
Playground::setup("relative_files_simple", |dirs, sandbox| {
|
|
|
|
sandbox
|
|
|
|
.mkdir("lol")
|
|
|
|
.mkdir("lol/lol")
|
|
|
|
.with_files(vec![FileWithContentToBeTrimmed(
|
|
|
|
"lol/lol/lol.nu",
|
|
|
|
r#"
|
|
|
|
use ../lol_shell.nu
|
|
|
|
|
|
|
|
let-env LOL = (lol_shell ls)
|
|
|
|
"#,
|
|
|
|
)])
|
|
|
|
.with_files(vec![FileWithContentToBeTrimmed(
|
|
|
|
"lol/lol_shell.nu",
|
|
|
|
r#"
|
|
|
|
export def ls [] { "lol" }
|
|
|
|
"#,
|
|
|
|
)]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
|
|
|
r#"
|
|
|
|
source-env lol/lol/lol.nu;
|
|
|
|
$env.LOL
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "lol");
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[ignore]
|
2022-07-27 17:36:56 +02:00
|
|
|
#[test]
|
|
|
|
fn parse_file_relative_to_parsed_file() {
|
|
|
|
Playground::setup("relative_files", |dirs, sandbox| {
|
|
|
|
sandbox
|
|
|
|
.mkdir("lol")
|
|
|
|
.mkdir("lol/lol")
|
|
|
|
.with_files(vec![FileWithContentToBeTrimmed(
|
|
|
|
"lol/lol/lol.nu",
|
|
|
|
r#"
|
2022-08-31 22:32:56 +02:00
|
|
|
source-env ../../foo.nu
|
2022-07-27 17:36:56 +02:00
|
|
|
use ../lol_shell.nu
|
2022-08-21 16:27:56 +02:00
|
|
|
overlay use ../../lol/lol_shell.nu
|
2022-07-27 17:36:56 +02:00
|
|
|
|
2022-08-31 22:32:56 +02:00
|
|
|
let-env LOL = $'($env.FOO) (lol_shell ls) (ls)'
|
2022-07-27 17:36:56 +02:00
|
|
|
"#,
|
|
|
|
)])
|
|
|
|
.with_files(vec![FileWithContentToBeTrimmed(
|
|
|
|
"lol/lol_shell.nu",
|
|
|
|
r#"
|
|
|
|
export def ls [] { "lol" }
|
|
|
|
"#,
|
|
|
|
)])
|
|
|
|
.with_files(vec![FileWithContentToBeTrimmed(
|
|
|
|
"foo.nu",
|
|
|
|
r#"
|
|
|
|
let-env FOO = 'foo'
|
|
|
|
"#,
|
|
|
|
)]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
|
|
|
r#"
|
2022-08-31 22:32:56 +02:00
|
|
|
source-env lol/lol/lol.nu;
|
|
|
|
$env.LOL
|
2022-07-27 17:36:56 +02:00
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "foo lol lol");
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn parse_file_relative_to_parsed_file_dont_use_cwd_1() {
|
|
|
|
Playground::setup("relative_files", |dirs, sandbox| {
|
|
|
|
sandbox
|
|
|
|
.mkdir("lol")
|
|
|
|
.with_files(vec![FileWithContentToBeTrimmed(
|
|
|
|
"lol/lol.nu",
|
|
|
|
r#"
|
2022-08-31 22:32:56 +02:00
|
|
|
source-env foo.nu
|
2022-07-27 17:36:56 +02:00
|
|
|
"#,
|
|
|
|
)])
|
|
|
|
.with_files(vec![FileWithContentToBeTrimmed(
|
|
|
|
"lol/foo.nu",
|
|
|
|
r#"
|
|
|
|
let-env FOO = 'good'
|
|
|
|
"#,
|
|
|
|
)])
|
|
|
|
.with_files(vec![FileWithContentToBeTrimmed(
|
|
|
|
"foo.nu",
|
|
|
|
r#"
|
|
|
|
let-env FOO = 'bad'
|
|
|
|
"#,
|
|
|
|
)]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
|
|
|
r#"
|
2022-08-31 22:32:56 +02:00
|
|
|
source-env lol/lol.nu;
|
2022-07-27 17:36:56 +02:00
|
|
|
$env.FOO
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "good");
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn parse_file_relative_to_parsed_file_dont_use_cwd_2() {
|
|
|
|
Playground::setup("relative_files", |dirs, sandbox| {
|
|
|
|
sandbox
|
|
|
|
.mkdir("lol")
|
|
|
|
.with_files(vec![FileWithContentToBeTrimmed(
|
|
|
|
"lol/lol.nu",
|
|
|
|
r#"
|
2022-08-31 22:32:56 +02:00
|
|
|
source-env foo.nu
|
2022-07-27 17:36:56 +02:00
|
|
|
"#,
|
|
|
|
)])
|
|
|
|
.with_files(vec![FileWithContentToBeTrimmed(
|
|
|
|
"foo.nu",
|
|
|
|
r#"
|
|
|
|
let-env FOO = 'bad'
|
|
|
|
"#,
|
|
|
|
)]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
|
|
|
r#"
|
2022-08-31 22:32:56 +02:00
|
|
|
source-env lol/lol.nu
|
2022-07-27 17:36:56 +02:00
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert!(actual.err.contains("File not found"));
|
|
|
|
})
|
|
|
|
}
|
2022-08-23 09:45:17 +02:00
|
|
|
|
|
|
|
#[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"));
|
|
|
|
}
|
2023-04-01 21:48:45 +02:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn numberlike_command_name() {
|
|
|
|
let actual = nu!(cwd: "tests/parsing/samples",
|
|
|
|
r#"
|
|
|
|
def 7zup [] {}
|
|
|
|
"#);
|
|
|
|
|
|
|
|
assert!(actual.err.contains("backticks"));
|
|
|
|
}
|