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};
|
2023-04-08 20:52:37 +02:00
|
|
|
use pretty_assertions::assert_eq;
|
2022-03-05 14:20:13 +01:00
|
|
|
|
2022-11-15 00:05:27 +01:00
|
|
|
#[test]
|
|
|
|
fn source_file_relative_to_file() {
|
2023-07-12 19:07:20 +02:00
|
|
|
let actual = nu!(cwd: "tests/parsing/samples", "
|
2022-11-15 00:05:27 +01:00
|
|
|
nu source_file_relative.nu
|
2023-07-12 19:07:20 +02:00
|
|
|
");
|
2022-11-15 00:05:27 +01:00
|
|
|
|
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",
|
2023-07-12 19:07:20 +02:00
|
|
|
"
|
2022-12-21 23:21:03 +01:00
|
|
|
const file = 'single_line.nu'
|
|
|
|
source $file
|
2023-07-12 19:07:20 +02:00
|
|
|
");
|
2022-12-21 23:21:03 +01:00
|
|
|
|
|
|
|
assert_eq!(actual.out, "5");
|
|
|
|
}
|
|
|
|
|
2022-03-05 14:20:13 +01:00
|
|
|
#[test]
|
|
|
|
fn run_nu_script_single_line() {
|
2023-07-12 19:07:20 +02:00
|
|
|
let actual = nu!(cwd: "tests/parsing/samples", "
|
2022-03-05 14:20:13 +01:00
|
|
|
nu single_line.nu
|
2023-07-12 19:07:20 +02:00
|
|
|
");
|
2022-03-05 14:20:13 +01:00
|
|
|
|
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() {
|
2023-07-12 19:07:20 +02:00
|
|
|
let actual = nu!(cwd: "tests/parsing/samples", "
|
2022-03-05 14:20:13 +01:00
|
|
|
nu multiline_start_pipe.nu
|
2023-07-12 19:07:20 +02:00
|
|
|
");
|
2022-03-05 14:20:13 +01:00
|
|
|
|
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() {
|
2023-07-12 19:07:20 +02:00
|
|
|
let actual = nu!(cwd: "tests/parsing/samples", "
|
2022-03-05 14:20:13 +01:00
|
|
|
nu multiline_start_pipe_win.nu
|
2023-07-12 19:07:20 +02:00
|
|
|
");
|
2022-03-05 14:20:13 +01:00
|
|
|
|
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() {
|
2023-07-12 19:07:20 +02:00
|
|
|
let actual = nu!(cwd: "tests/parsing/samples", "
|
2022-03-05 14:20:13 +01:00
|
|
|
nu multiline_end_pipe.nu
|
2023-07-12 19:07:20 +02:00
|
|
|
");
|
2022-03-05 14:20:13 +01:00
|
|
|
|
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() {
|
2023-07-12 19:07:20 +02:00
|
|
|
let actual = nu!(cwd: "tests/parsing/samples", "
|
2022-03-05 14:20:13 +01:00
|
|
|
nu multiline_end_pipe_win.nu
|
2023-07-12 19:07:20 +02:00
|
|
|
");
|
2022-03-05 14:20:13 +01:00
|
|
|
|
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",
|
2023-07-12 19:07:20 +02:00
|
|
|
"
|
2022-08-31 22:32:56 +02:00
|
|
|
use ../lol_shell.nu
|
|
|
|
|
2023-06-30 21:57:51 +02:00
|
|
|
$env.LOL = (lol_shell ls)
|
2023-07-12 19:07:20 +02:00
|
|
|
",
|
2022-08-31 22:32:56 +02:00
|
|
|
)])
|
|
|
|
.with_files(vec![FileWithContentToBeTrimmed(
|
|
|
|
"lol/lol_shell.nu",
|
|
|
|
r#"
|
|
|
|
export def ls [] { "lol" }
|
|
|
|
"#,
|
|
|
|
)]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
2023-07-12 19:07:20 +02:00
|
|
|
"
|
2022-08-31 22:32:56 +02:00
|
|
|
source-env lol/lol/lol.nu;
|
|
|
|
$env.LOL
|
2023-07-12 19:07:20 +02:00
|
|
|
"
|
2022-08-31 22:32:56 +02:00
|
|
|
));
|
|
|
|
|
|
|
|
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",
|
2023-07-12 19:07:20 +02:00
|
|
|
"
|
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
|
|
|
|
2023-06-30 21:57:51 +02:00
|
|
|
$env.LOL = $'($env.FOO) (lol_shell ls) (ls)'
|
2023-07-12 19:07:20 +02:00
|
|
|
",
|
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",
|
2023-07-12 19:07:20 +02:00
|
|
|
"
|
2023-06-30 21:57:51 +02:00
|
|
|
$env.FOO = 'foo'
|
2023-07-12 19:07:20 +02:00
|
|
|
",
|
2022-07-27 17:36:56 +02:00
|
|
|
)]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
2023-07-12 19:07:20 +02:00
|
|
|
"
|
2022-08-31 22:32:56 +02:00
|
|
|
source-env lol/lol/lol.nu;
|
|
|
|
$env.LOL
|
2023-07-12 19:07:20 +02:00
|
|
|
"
|
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",
|
2023-07-12 19:07:20 +02:00
|
|
|
"
|
2022-08-31 22:32:56 +02:00
|
|
|
source-env foo.nu
|
2023-07-12 19:07:20 +02:00
|
|
|
",
|
2022-07-27 17:36:56 +02:00
|
|
|
)])
|
|
|
|
.with_files(vec![FileWithContentToBeTrimmed(
|
|
|
|
"lol/foo.nu",
|
2023-07-12 19:07:20 +02:00
|
|
|
"
|
2023-06-30 21:57:51 +02:00
|
|
|
$env.FOO = 'good'
|
2023-07-12 19:07:20 +02:00
|
|
|
",
|
2022-07-27 17:36:56 +02:00
|
|
|
)])
|
|
|
|
.with_files(vec![FileWithContentToBeTrimmed(
|
|
|
|
"foo.nu",
|
2023-07-12 19:07:20 +02:00
|
|
|
"
|
2023-06-30 21:57:51 +02:00
|
|
|
$env.FOO = 'bad'
|
2023-07-12 19:07:20 +02:00
|
|
|
",
|
2022-07-27 17:36:56 +02:00
|
|
|
)]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
2023-07-12 19:07:20 +02:00
|
|
|
"
|
2022-08-31 22:32:56 +02:00
|
|
|
source-env lol/lol.nu;
|
2022-07-27 17:36:56 +02:00
|
|
|
$env.FOO
|
2023-07-12 19:07:20 +02:00
|
|
|
"
|
2022-07-27 17:36:56 +02:00
|
|
|
));
|
|
|
|
|
|
|
|
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",
|
2023-07-12 19:07:20 +02:00
|
|
|
"
|
2022-08-31 22:32:56 +02:00
|
|
|
source-env foo.nu
|
2023-07-12 19:07:20 +02:00
|
|
|
",
|
2022-07-27 17:36:56 +02:00
|
|
|
)])
|
|
|
|
.with_files(vec![FileWithContentToBeTrimmed(
|
|
|
|
"foo.nu",
|
2023-07-12 19:07:20 +02:00
|
|
|
"
|
2023-06-30 21:57:51 +02:00
|
|
|
$env.FOO = 'bad'
|
2023-07-12 19:07:20 +02:00
|
|
|
",
|
2022-07-27 17:36:56 +02:00
|
|
|
)]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
2023-07-12 19:07:20 +02:00
|
|
|
"
|
2022-08-31 22:32:56 +02:00
|
|
|
source-env lol/lol.nu
|
2023-07-12 19:07:20 +02:00
|
|
|
"
|
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() {
|
2023-07-12 19:07:20 +02:00
|
|
|
let actual = nu!("
|
2022-08-23 09:45:17 +02:00
|
|
|
module spam { export-env { } }
|
2023-07-12 19:07:20 +02:00
|
|
|
");
|
2022-08-23 09:45:17 +02:00
|
|
|
|
|
|
|
assert!(actual.err.is_empty());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn parse_export_env_missing_block() {
|
2023-07-12 19:07:20 +02:00
|
|
|
let actual = nu!("
|
2022-08-23 09:45:17 +02:00
|
|
|
module spam { export-env }
|
2023-07-12 19:07:20 +02:00
|
|
|
");
|
2022-08-23 09:45:17 +02:00
|
|
|
|
|
|
|
assert!(actual.err.contains("missing block"));
|
|
|
|
}
|
2023-04-01 21:48:45 +02:00
|
|
|
|
2023-04-10 23:52:51 +02:00
|
|
|
#[test]
|
|
|
|
fn call_command_with_non_ascii_argument() {
|
2023-07-12 19:07:20 +02:00
|
|
|
let actual = nu!("
|
2023-04-10 23:52:51 +02:00
|
|
|
def nu-arg [--umlaut(-ö): int] {}
|
|
|
|
nu-arg -ö 42
|
2023-07-12 19:07:20 +02:00
|
|
|
");
|
2023-04-10 23:52:51 +02:00
|
|
|
|
|
|
|
assert_eq!(actual.err.len(), 0);
|
|
|
|
}
|
2023-05-12 18:57:50 +02:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn parse_long_duration() {
|
2023-07-12 19:07:20 +02:00
|
|
|
let actual = nu!(r#"
|
2023-05-12 18:57:50 +02:00
|
|
|
"78.797877879789789sec" | into duration
|
|
|
|
"#);
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "1min 18sec 797ms");
|
|
|
|
}
|