2022-06-26 13:53:06 +02:00
|
|
|
use nu_test_support::fs::Stub::FileWithContentToBeTrimmed;
|
|
|
|
use nu_test_support::playground::Playground;
|
|
|
|
use nu_test_support::{nu, pipeline};
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn parse_script_success() {
|
|
|
|
Playground::setup("nu_check_test_1", |dirs, sandbox| {
|
2024-05-04 02:53:15 +02:00
|
|
|
sandbox.with_files(&[FileWithContentToBeTrimmed(
|
2022-06-26 13:53:06 +02:00
|
|
|
"script.nu",
|
|
|
|
r#"
|
|
|
|
greet "world"
|
|
|
|
|
|
|
|
def greet [name] {
|
|
|
|
echo "hello" $name
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
)]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
2023-07-21 17:32:37 +02:00
|
|
|
"
|
2022-06-26 13:53:06 +02:00
|
|
|
nu-check script.nu
|
2023-07-21 17:32:37 +02:00
|
|
|
"
|
2022-06-26 13:53:06 +02:00
|
|
|
));
|
|
|
|
|
|
|
|
assert!(actual.err.is_empty());
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn parse_script_with_wrong_type() {
|
|
|
|
Playground::setup("nu_check_test_2", |dirs, sandbox| {
|
2024-05-04 02:53:15 +02:00
|
|
|
sandbox.with_files(&[FileWithContentToBeTrimmed(
|
2022-06-26 13:53:06 +02:00
|
|
|
"script.nu",
|
|
|
|
r#"
|
|
|
|
greet "world"
|
|
|
|
|
|
|
|
def greet [name] {
|
|
|
|
echo "hello" $name
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
)]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
2023-07-21 17:32:37 +02:00
|
|
|
"
|
2023-10-19 22:08:09 +02:00
|
|
|
nu-check --debug --as-module script.nu
|
2023-07-21 17:32:37 +02:00
|
|
|
"
|
2022-06-26 13:53:06 +02:00
|
|
|
));
|
|
|
|
|
|
|
|
assert!(actual.err.contains("Failed to parse content"));
|
|
|
|
})
|
|
|
|
}
|
|
|
|
#[test]
|
|
|
|
fn parse_script_failure() {
|
|
|
|
Playground::setup("nu_check_test_3", |dirs, sandbox| {
|
2024-05-04 02:53:15 +02:00
|
|
|
sandbox.with_files(&[FileWithContentToBeTrimmed(
|
2022-06-26 13:53:06 +02:00
|
|
|
"script.nu",
|
|
|
|
r#"
|
|
|
|
greet "world"
|
|
|
|
|
|
|
|
def greet [name {
|
|
|
|
echo "hello" $name
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
)]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
2023-07-21 17:32:37 +02:00
|
|
|
"
|
2023-10-19 22:08:09 +02:00
|
|
|
nu-check --debug script.nu
|
2023-07-21 17:32:37 +02:00
|
|
|
"
|
2022-06-26 13:53:06 +02:00
|
|
|
));
|
|
|
|
|
|
|
|
assert!(actual.err.contains("Unexpected end of code"));
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn parse_module_success() {
|
|
|
|
Playground::setup("nu_check_test_4", |dirs, sandbox| {
|
2024-05-04 02:53:15 +02:00
|
|
|
sandbox.with_files(&[FileWithContentToBeTrimmed(
|
2022-06-26 13:53:06 +02:00
|
|
|
"foo.nu",
|
|
|
|
r#"
|
|
|
|
# foo.nu
|
|
|
|
|
|
|
|
export def hello [name: string] {
|
|
|
|
$"hello ($name)!"
|
|
|
|
}
|
|
|
|
|
|
|
|
export def hi [where: string] {
|
|
|
|
$"hi ($where)!"
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
)]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
2023-07-21 17:32:37 +02:00
|
|
|
"
|
2022-06-26 13:53:06 +02:00
|
|
|
nu-check --as-module foo.nu
|
2023-07-21 17:32:37 +02:00
|
|
|
"
|
2022-06-26 13:53:06 +02:00
|
|
|
));
|
|
|
|
|
|
|
|
assert!(actual.err.is_empty());
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn parse_module_with_wrong_type() {
|
|
|
|
Playground::setup("nu_check_test_5", |dirs, sandbox| {
|
2024-05-04 02:53:15 +02:00
|
|
|
sandbox.with_files(&[FileWithContentToBeTrimmed(
|
2022-06-26 13:53:06 +02:00
|
|
|
"foo.nu",
|
|
|
|
r#"
|
|
|
|
# foo.nu
|
|
|
|
|
|
|
|
export def hello [name: string {
|
|
|
|
$"hello ($name)!"
|
|
|
|
}
|
|
|
|
|
|
|
|
export def hi [where: string] {
|
|
|
|
$"hi ($where)!"
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
)]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
2023-07-21 17:32:37 +02:00
|
|
|
"
|
2023-10-19 22:08:09 +02:00
|
|
|
nu-check --debug foo.nu
|
2023-07-21 17:32:37 +02:00
|
|
|
"
|
2022-06-26 13:53:06 +02:00
|
|
|
));
|
|
|
|
|
|
|
|
assert!(actual.err.contains("Failed to parse content"));
|
|
|
|
})
|
|
|
|
}
|
|
|
|
#[test]
|
|
|
|
fn parse_module_failure() {
|
|
|
|
Playground::setup("nu_check_test_6", |dirs, sandbox| {
|
2024-05-04 02:53:15 +02:00
|
|
|
sandbox.with_files(&[FileWithContentToBeTrimmed(
|
2022-06-26 13:53:06 +02:00
|
|
|
"foo.nu",
|
|
|
|
r#"
|
|
|
|
# foo.nu
|
|
|
|
|
|
|
|
export def hello [name: string {
|
|
|
|
$"hello ($name)!"
|
|
|
|
}
|
|
|
|
|
|
|
|
export def hi [where: string] {
|
|
|
|
$"hi ($where)!"
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
)]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
2023-07-21 17:32:37 +02:00
|
|
|
"
|
2023-10-19 22:08:09 +02:00
|
|
|
nu-check --debug --as-module foo.nu
|
2023-07-21 17:32:37 +02:00
|
|
|
"
|
2022-06-26 13:53:06 +02:00
|
|
|
));
|
|
|
|
|
|
|
|
assert!(actual.err.contains("Unexpected end of code"));
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn file_not_exist() {
|
|
|
|
Playground::setup("nu_check_test_7", |dirs, _sandbox| {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
2023-07-21 17:32:37 +02:00
|
|
|
"
|
2022-06-26 13:53:06 +02:00
|
|
|
nu-check --as-module foo.nu
|
2023-07-21 17:32:37 +02:00
|
|
|
"
|
2022-06-26 13:53:06 +02:00
|
|
|
));
|
|
|
|
|
|
|
|
assert!(actual.err.contains("file not found"));
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn parse_module_success_2() {
|
|
|
|
Playground::setup("nu_check_test_10", |dirs, sandbox| {
|
2024-05-04 02:53:15 +02:00
|
|
|
sandbox.with_files(&[FileWithContentToBeTrimmed(
|
2022-06-26 13:53:06 +02:00
|
|
|
"foo.nu",
|
|
|
|
r#"
|
|
|
|
# foo.nu
|
|
|
|
|
2023-06-30 21:57:51 +02:00
|
|
|
export-env { $env.MYNAME = "Arthur, King of the Britons" }
|
2022-06-26 13:53:06 +02:00
|
|
|
"#,
|
|
|
|
)]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
2023-07-21 17:32:37 +02:00
|
|
|
"
|
2022-06-26 13:53:06 +02:00
|
|
|
nu-check --as-module foo.nu
|
2023-07-21 17:32:37 +02:00
|
|
|
"
|
2022-06-26 13:53:06 +02:00
|
|
|
));
|
|
|
|
|
|
|
|
assert!(actual.err.is_empty());
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn parse_script_success_with_raw_stream() {
|
|
|
|
Playground::setup("nu_check_test_11", |dirs, sandbox| {
|
2024-05-04 02:53:15 +02:00
|
|
|
sandbox.with_files(&[FileWithContentToBeTrimmed(
|
2022-06-26 13:53:06 +02:00
|
|
|
"script.nu",
|
|
|
|
r#"
|
|
|
|
greet "world"
|
|
|
|
|
|
|
|
def greet [name] {
|
|
|
|
echo "hello" $name
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
)]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
2023-07-21 17:32:37 +02:00
|
|
|
"
|
2022-07-27 17:36:56 +02:00
|
|
|
open script.nu | nu-check
|
2023-07-21 17:32:37 +02:00
|
|
|
"
|
2022-06-26 13:53:06 +02:00
|
|
|
));
|
|
|
|
|
|
|
|
assert!(actual.err.is_empty());
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn parse_module_success_with_raw_stream() {
|
|
|
|
Playground::setup("nu_check_test_12", |dirs, sandbox| {
|
2024-05-04 02:53:15 +02:00
|
|
|
sandbox.with_files(&[FileWithContentToBeTrimmed(
|
2022-06-26 13:53:06 +02:00
|
|
|
"foo.nu",
|
|
|
|
r#"
|
|
|
|
# foo.nu
|
|
|
|
|
|
|
|
export def hello [name: string] {
|
|
|
|
$"hello ($name)!"
|
|
|
|
}
|
|
|
|
|
|
|
|
export def hi [where: string] {
|
|
|
|
$"hi ($where)!"
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
)]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
2023-07-21 17:32:37 +02:00
|
|
|
"
|
2022-06-26 13:53:06 +02:00
|
|
|
open foo.nu | nu-check --as-module
|
2023-07-21 17:32:37 +02:00
|
|
|
"
|
2022-06-26 13:53:06 +02:00
|
|
|
));
|
|
|
|
|
|
|
|
assert!(actual.err.is_empty());
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn parse_string_as_script_success() {
|
|
|
|
Playground::setup("nu_check_test_13", |dirs, _sandbox| {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
|
|
|
r#"
|
|
|
|
echo $'two(char nl)lines' | nu-check
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert!(actual.err.is_empty());
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn parse_string_as_script() {
|
|
|
|
Playground::setup("nu_check_test_14", |dirs, _sandbox| {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
|
|
|
r#"
|
2023-10-19 22:08:09 +02:00
|
|
|
echo $'two(char nl)lines' | nu-check --debug --as-module
|
2022-06-26 13:53:06 +02:00
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
2022-11-24 04:58:15 +01:00
|
|
|
println!("the output is {}", actual.err);
|
2022-06-26 13:53:06 +02:00
|
|
|
assert!(actual.err.contains("Failed to parse content"));
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn parse_module_success_with_internal_stream() {
|
|
|
|
Playground::setup("nu_check_test_15", |dirs, sandbox| {
|
2024-05-04 02:53:15 +02:00
|
|
|
sandbox.with_files(&[FileWithContentToBeTrimmed(
|
2022-06-26 13:53:06 +02:00
|
|
|
"foo.nu",
|
|
|
|
r#"
|
|
|
|
# foo.nu
|
|
|
|
|
|
|
|
export def hello [name: string] {
|
|
|
|
$"hello ($name)!"
|
|
|
|
}
|
|
|
|
|
|
|
|
export def hi [where: string] {
|
|
|
|
$"hi ($where)!"
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
)]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
2023-07-21 17:32:37 +02:00
|
|
|
"
|
2022-06-26 13:53:06 +02:00
|
|
|
open foo.nu | lines | nu-check --as-module
|
2023-07-21 17:32:37 +02:00
|
|
|
"
|
2022-06-26 13:53:06 +02:00
|
|
|
));
|
|
|
|
|
|
|
|
assert!(actual.err.is_empty());
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn parse_script_success_with_complex_internal_stream() {
|
|
|
|
Playground::setup("nu_check_test_16", |dirs, sandbox| {
|
2024-05-04 02:53:15 +02:00
|
|
|
sandbox.with_files(&[FileWithContentToBeTrimmed(
|
2022-06-26 13:53:06 +02:00
|
|
|
"grep.nu",
|
|
|
|
r#"
|
|
|
|
#grep for nu
|
|
|
|
def grep-nu [
|
|
|
|
search #search term
|
|
|
|
entrada? #file or pipe
|
|
|
|
#
|
|
|
|
#Examples
|
|
|
|
#grep-nu search file.txt
|
2022-07-27 17:36:56 +02:00
|
|
|
#ls **/* | some_filter | grep-nu search
|
2022-06-26 13:53:06 +02:00
|
|
|
#open file.txt | grep-nu search
|
|
|
|
] {
|
2022-09-05 16:41:06 +02:00
|
|
|
if ($entrada | is-empty) {
|
2022-06-26 13:53:06 +02:00
|
|
|
if ($in | column? name) {
|
|
|
|
grep -ihHn $search ($in | get name)
|
|
|
|
} else {
|
|
|
|
($in | into string) | grep -ihHn $search
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
grep -ihHn $search $entrada
|
|
|
|
}
|
2022-07-27 17:36:56 +02:00
|
|
|
| lines
|
2022-06-26 13:53:06 +02:00
|
|
|
| parse "{file}:{line}:{match}"
|
|
|
|
| str trim
|
2022-07-27 17:36:56 +02:00
|
|
|
| update match {|f|
|
|
|
|
$f.match
|
2022-06-26 13:53:06 +02:00
|
|
|
| nu-highlight
|
|
|
|
}
|
|
|
|
| rename "source file" "line number"
|
|
|
|
}
|
|
|
|
|
|
|
|
"#,
|
|
|
|
)]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
2023-07-21 17:32:37 +02:00
|
|
|
"
|
2022-06-26 13:53:06 +02:00
|
|
|
open grep.nu | lines | nu-check
|
2023-07-21 17:32:37 +02:00
|
|
|
"
|
2022-06-26 13:53:06 +02:00
|
|
|
));
|
|
|
|
|
|
|
|
assert!(actual.err.is_empty());
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn parse_script_failure_with_complex_internal_stream() {
|
|
|
|
Playground::setup("nu_check_test_17", |dirs, sandbox| {
|
2024-05-04 02:53:15 +02:00
|
|
|
sandbox.with_files(&[FileWithContentToBeTrimmed(
|
2022-06-26 13:53:06 +02:00
|
|
|
"grep.nu",
|
|
|
|
r#"
|
|
|
|
#grep for nu
|
|
|
|
def grep-nu [
|
|
|
|
search #search term
|
|
|
|
entrada? #file or pipe
|
|
|
|
#
|
|
|
|
#Examples
|
|
|
|
#grep-nu search file.txt
|
2022-07-27 17:36:56 +02:00
|
|
|
#ls **/* | some_filter | grep-nu search
|
2022-06-26 13:53:06 +02:00
|
|
|
#open file.txt | grep-nu search
|
2022-07-27 17:36:56 +02:00
|
|
|
]
|
2022-09-05 16:41:06 +02:00
|
|
|
if ($entrada | is-empty) {
|
2022-06-26 13:53:06 +02:00
|
|
|
if ($in | column? name) {
|
|
|
|
grep -ihHn $search ($in | get name)
|
|
|
|
} else {
|
|
|
|
($in | into string) | grep -ihHn $search
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
grep -ihHn $search $entrada
|
|
|
|
}
|
2022-07-27 17:36:56 +02:00
|
|
|
| lines
|
2022-06-26 13:53:06 +02:00
|
|
|
| parse "{file}:{line}:{match}"
|
|
|
|
| str trim
|
2022-07-27 17:36:56 +02:00
|
|
|
| update match {|f|
|
|
|
|
$f.match
|
2022-06-26 13:53:06 +02:00
|
|
|
| nu-highlight
|
|
|
|
}
|
|
|
|
| rename "source file" "line number"
|
|
|
|
}
|
|
|
|
|
|
|
|
"#,
|
|
|
|
)]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
2023-07-21 17:32:37 +02:00
|
|
|
"
|
2022-06-26 13:53:06 +02:00
|
|
|
open grep.nu | lines | nu-check
|
2023-07-21 17:32:37 +02:00
|
|
|
"
|
2022-06-26 13:53:06 +02:00
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "false".to_string());
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn parse_script_success_with_complex_external_stream() {
|
|
|
|
Playground::setup("nu_check_test_18", |dirs, sandbox| {
|
2024-05-04 02:53:15 +02:00
|
|
|
sandbox.with_files(&[FileWithContentToBeTrimmed(
|
2022-06-26 13:53:06 +02:00
|
|
|
"grep.nu",
|
|
|
|
r#"
|
|
|
|
#grep for nu
|
|
|
|
def grep-nu [
|
|
|
|
search #search term
|
|
|
|
entrada? #file or pipe
|
|
|
|
#
|
|
|
|
#Examples
|
|
|
|
#grep-nu search file.txt
|
2022-07-27 17:36:56 +02:00
|
|
|
#ls **/* | some_filter | grep-nu search
|
2022-06-26 13:53:06 +02:00
|
|
|
#open file.txt | grep-nu search
|
|
|
|
] {
|
2022-09-05 16:41:06 +02:00
|
|
|
if ($entrada | is-empty) {
|
2022-06-26 13:53:06 +02:00
|
|
|
if ($in | column? name) {
|
|
|
|
grep -ihHn $search ($in | get name)
|
|
|
|
} else {
|
|
|
|
($in | into string) | grep -ihHn $search
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
grep -ihHn $search $entrada
|
|
|
|
}
|
2022-07-27 17:36:56 +02:00
|
|
|
| lines
|
2022-06-26 13:53:06 +02:00
|
|
|
| parse "{file}:{line}:{match}"
|
|
|
|
| str trim
|
2022-07-27 17:36:56 +02:00
|
|
|
| update match {|f|
|
|
|
|
$f.match
|
2022-06-26 13:53:06 +02:00
|
|
|
| nu-highlight
|
|
|
|
}
|
|
|
|
| rename "source file" "line number"
|
|
|
|
}
|
|
|
|
|
|
|
|
"#,
|
|
|
|
)]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
2023-07-21 17:32:37 +02:00
|
|
|
"
|
2022-06-26 13:53:06 +02:00
|
|
|
open grep.nu | nu-check
|
2023-07-21 17:32:37 +02:00
|
|
|
"
|
2022-06-26 13:53:06 +02:00
|
|
|
));
|
|
|
|
|
|
|
|
assert!(actual.err.is_empty());
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn parse_module_success_with_complex_external_stream() {
|
|
|
|
Playground::setup("nu_check_test_19", |dirs, sandbox| {
|
2024-05-04 02:53:15 +02:00
|
|
|
sandbox.with_files(&[FileWithContentToBeTrimmed(
|
2022-06-26 13:53:06 +02:00
|
|
|
"grep.nu",
|
|
|
|
r#"
|
|
|
|
#grep for nu
|
|
|
|
def grep-nu [
|
|
|
|
search #search term
|
|
|
|
entrada? #file or pipe
|
|
|
|
#
|
|
|
|
#Examples
|
|
|
|
#grep-nu search file.txt
|
2022-07-27 17:36:56 +02:00
|
|
|
#ls **/* | some_filter | grep-nu search
|
2022-06-26 13:53:06 +02:00
|
|
|
#open file.txt | grep-nu search
|
|
|
|
] {
|
2022-09-05 16:41:06 +02:00
|
|
|
if ($entrada | is-empty) {
|
2022-06-26 13:53:06 +02:00
|
|
|
if ($in | column? name) {
|
|
|
|
grep -ihHn $search ($in | get name)
|
|
|
|
} else {
|
|
|
|
($in | into string) | grep -ihHn $search
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
grep -ihHn $search $entrada
|
|
|
|
}
|
2022-07-27 17:36:56 +02:00
|
|
|
| lines
|
2022-06-26 13:53:06 +02:00
|
|
|
| parse "{file}:{line}:{match}"
|
|
|
|
| str trim
|
2022-07-27 17:36:56 +02:00
|
|
|
| update match {|f|
|
|
|
|
$f.match
|
2022-06-26 13:53:06 +02:00
|
|
|
| nu-highlight
|
|
|
|
}
|
|
|
|
| rename "source file" "line number"
|
|
|
|
}
|
|
|
|
|
|
|
|
"#,
|
|
|
|
)]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
2023-07-21 17:32:37 +02:00
|
|
|
"
|
2023-10-19 22:08:09 +02:00
|
|
|
open grep.nu | nu-check --debug --as-module
|
2023-07-21 17:32:37 +02:00
|
|
|
"
|
2022-06-26 13:53:06 +02:00
|
|
|
));
|
|
|
|
|
|
|
|
assert!(actual.err.is_empty());
|
|
|
|
})
|
|
|
|
}
|
2022-07-01 22:49:24 +02:00
|
|
|
|
|
|
|
#[test]
|
2024-03-09 17:58:02 +01:00
|
|
|
fn parse_with_flag_success_for_complex_external_stream() {
|
2022-07-01 22:49:24 +02:00
|
|
|
Playground::setup("nu_check_test_20", |dirs, sandbox| {
|
2024-05-04 02:53:15 +02:00
|
|
|
sandbox.with_files(&[FileWithContentToBeTrimmed(
|
2022-07-01 22:49:24 +02:00
|
|
|
"grep.nu",
|
|
|
|
r#"
|
|
|
|
#grep for nu
|
|
|
|
def grep-nu [
|
|
|
|
search #search term
|
|
|
|
entrada? #file or pipe
|
|
|
|
#
|
|
|
|
#Examples
|
|
|
|
#grep-nu search file.txt
|
2022-07-27 17:36:56 +02:00
|
|
|
#ls **/* | some_filter | grep-nu search
|
2022-07-01 22:49:24 +02:00
|
|
|
#open file.txt | grep-nu search
|
|
|
|
] {
|
2022-09-05 16:41:06 +02:00
|
|
|
if ($entrada | is-empty) {
|
2022-07-01 22:49:24 +02:00
|
|
|
if ($in | column? name) {
|
|
|
|
grep -ihHn $search ($in | get name)
|
|
|
|
} else {
|
|
|
|
($in | into string) | grep -ihHn $search
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
grep -ihHn $search $entrada
|
|
|
|
}
|
2022-07-27 17:36:56 +02:00
|
|
|
| lines
|
2022-07-01 22:49:24 +02:00
|
|
|
| parse "{file}:{line}:{match}"
|
|
|
|
| str trim
|
2022-07-27 17:36:56 +02:00
|
|
|
| update match {|f|
|
|
|
|
$f.match
|
2022-07-01 22:49:24 +02:00
|
|
|
| nu-highlight
|
|
|
|
}
|
|
|
|
| rename "source file" "line number"
|
|
|
|
}
|
|
|
|
|
|
|
|
"#,
|
|
|
|
)]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
2023-07-21 17:32:37 +02:00
|
|
|
"
|
2024-03-09 17:58:02 +01:00
|
|
|
open grep.nu | nu-check --debug
|
2023-07-21 17:32:37 +02:00
|
|
|
"
|
2022-07-01 22:49:24 +02:00
|
|
|
));
|
|
|
|
|
|
|
|
assert!(actual.err.is_empty());
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2024-03-09 17:58:02 +01:00
|
|
|
fn parse_with_flag_failure_for_complex_external_stream() {
|
2022-07-01 22:49:24 +02:00
|
|
|
Playground::setup("nu_check_test_21", |dirs, sandbox| {
|
2024-05-04 02:53:15 +02:00
|
|
|
sandbox.with_files(&[FileWithContentToBeTrimmed(
|
2022-07-01 22:49:24 +02:00
|
|
|
"grep.nu",
|
|
|
|
r#"
|
|
|
|
#grep for nu
|
2022-07-27 17:36:56 +02:00
|
|
|
def grep-nu
|
2022-07-01 22:49:24 +02:00
|
|
|
search #search term
|
|
|
|
entrada? #file or pipe
|
|
|
|
#
|
|
|
|
#Examples
|
|
|
|
#grep-nu search file.txt
|
2022-07-27 17:36:56 +02:00
|
|
|
#ls **/* | some_filter | grep-nu search
|
2022-07-01 22:49:24 +02:00
|
|
|
#open file.txt | grep-nu search
|
|
|
|
] {
|
2022-09-05 16:41:06 +02:00
|
|
|
if ($entrada | is-empty) {
|
2022-07-01 22:49:24 +02:00
|
|
|
if ($in | column? name) {
|
|
|
|
grep -ihHn $search ($in | get name)
|
|
|
|
} else {
|
|
|
|
($in | into string) | grep -ihHn $search
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
grep -ihHn $search $entrada
|
|
|
|
}
|
2022-07-27 17:36:56 +02:00
|
|
|
| lines
|
2022-07-01 22:49:24 +02:00
|
|
|
| parse "{file}:{line}:{match}"
|
|
|
|
| str trim
|
2022-07-27 17:36:56 +02:00
|
|
|
| update match {|f|
|
|
|
|
$f.match
|
2022-07-01 22:49:24 +02:00
|
|
|
| nu-highlight
|
|
|
|
}
|
|
|
|
| rename "source file" "line number"
|
|
|
|
}
|
|
|
|
|
|
|
|
"#,
|
|
|
|
)]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
2023-07-21 17:32:37 +02:00
|
|
|
"
|
2024-03-09 17:58:02 +01:00
|
|
|
open grep.nu | nu-check --debug
|
2023-07-21 17:32:37 +02:00
|
|
|
"
|
2022-07-01 22:49:24 +02:00
|
|
|
));
|
|
|
|
|
2024-03-09 17:58:02 +01:00
|
|
|
assert!(actual.err.contains("Failed to parse content"));
|
2022-07-01 22:49:24 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2024-03-09 17:58:02 +01:00
|
|
|
fn parse_with_flag_failure_for_complex_list_stream() {
|
2022-07-01 22:49:24 +02:00
|
|
|
Playground::setup("nu_check_test_22", |dirs, sandbox| {
|
2024-05-04 02:53:15 +02:00
|
|
|
sandbox.with_files(&[FileWithContentToBeTrimmed(
|
2022-07-01 22:49:24 +02:00
|
|
|
"grep.nu",
|
|
|
|
r#"
|
|
|
|
#grep for nu
|
2022-07-27 17:36:56 +02:00
|
|
|
def grep-nu
|
2022-07-01 22:49:24 +02:00
|
|
|
search #search term
|
|
|
|
entrada? #file or pipe
|
|
|
|
#
|
|
|
|
#Examples
|
|
|
|
#grep-nu search file.txt
|
2022-07-27 17:36:56 +02:00
|
|
|
#ls **/* | some_filter | grep-nu search
|
2022-07-01 22:49:24 +02:00
|
|
|
#open file.txt | grep-nu search
|
|
|
|
] {
|
2022-09-05 16:41:06 +02:00
|
|
|
if ($entrada | is-empty) {
|
2022-07-01 22:49:24 +02:00
|
|
|
if ($in | column? name) {
|
|
|
|
grep -ihHn $search ($in | get name)
|
|
|
|
} else {
|
|
|
|
($in | into string) | grep -ihHn $search
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
grep -ihHn $search $entrada
|
|
|
|
}
|
2022-07-27 17:36:56 +02:00
|
|
|
| lines
|
2022-07-01 22:49:24 +02:00
|
|
|
| parse "{file}:{line}:{match}"
|
|
|
|
| str trim
|
2022-07-27 17:36:56 +02:00
|
|
|
| update match {|f|
|
|
|
|
$f.match
|
2022-07-01 22:49:24 +02:00
|
|
|
| nu-highlight
|
|
|
|
}
|
|
|
|
| rename "source file" "line number"
|
|
|
|
}
|
|
|
|
|
|
|
|
"#,
|
|
|
|
)]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
2023-07-21 17:32:37 +02:00
|
|
|
"
|
2024-03-09 17:58:02 +01:00
|
|
|
open grep.nu | lines | nu-check --debug
|
2023-07-21 17:32:37 +02:00
|
|
|
"
|
2022-07-01 22:49:24 +02:00
|
|
|
));
|
|
|
|
|
2024-03-09 17:58:02 +01:00
|
|
|
assert!(actual.err.contains("Failed to parse content"));
|
2022-07-01 22:49:24 +02:00
|
|
|
})
|
|
|
|
}
|
2022-07-27 17:36:56 +02:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn parse_script_with_nested_scripts_success() {
|
|
|
|
Playground::setup("nu_check_test_24", |dirs, sandbox| {
|
|
|
|
sandbox
|
|
|
|
.mkdir("lol")
|
2024-05-04 02:53:15 +02:00
|
|
|
.with_files(&[FileWithContentToBeTrimmed(
|
2022-07-27 17:36:56 +02:00
|
|
|
"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
|
|
|
"#,
|
|
|
|
)])
|
2024-05-04 02:53:15 +02:00
|
|
|
.with_files(&[FileWithContentToBeTrimmed(
|
2022-07-27 17:36:56 +02:00
|
|
|
"lol/lol_shell.nu",
|
|
|
|
r#"
|
|
|
|
export def ls [] { "lol" }
|
|
|
|
"#,
|
|
|
|
)])
|
2024-05-04 02:53:15 +02:00
|
|
|
.with_files(&[FileWithContentToBeTrimmed(
|
2022-07-27 17:36:56 +02:00
|
|
|
"foo.nu",
|
|
|
|
r#"
|
2023-06-30 21:57:51 +02:00
|
|
|
$env.FOO = 'foo'
|
2022-07-27 17:36:56 +02:00
|
|
|
"#,
|
|
|
|
)]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
2023-07-21 17:32:37 +02:00
|
|
|
"
|
2022-07-27 17:36:56 +02:00
|
|
|
nu-check lol/lol.nu
|
2023-07-21 17:32:37 +02:00
|
|
|
"
|
2022-07-27 17:36:56 +02:00
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "true");
|
|
|
|
})
|
|
|
|
}
|
2022-08-31 22:32:56 +02:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn nu_check_respects_file_pwd() {
|
|
|
|
Playground::setup("nu_check_test_25", |dirs, sandbox| {
|
|
|
|
sandbox
|
|
|
|
.mkdir("lol")
|
2024-05-04 02:53:15 +02:00
|
|
|
.with_files(&[FileWithContentToBeTrimmed(
|
2022-08-31 22:32:56 +02:00
|
|
|
"lol/lol.nu",
|
|
|
|
r#"
|
2023-06-30 21:57:51 +02:00
|
|
|
$env.RETURN = (nu-check ../foo.nu)
|
2022-08-31 22:32:56 +02:00
|
|
|
"#,
|
|
|
|
)])
|
2024-05-04 02:53:15 +02:00
|
|
|
.with_files(&[FileWithContentToBeTrimmed(
|
2022-08-31 22:32:56 +02:00
|
|
|
"foo.nu",
|
|
|
|
r#"
|
|
|
|
echo 'foo'
|
|
|
|
"#,
|
|
|
|
)]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
2023-07-21 17:32:37 +02:00
|
|
|
"
|
2022-08-31 22:32:56 +02:00
|
|
|
source-env lol/lol.nu;
|
|
|
|
$env.RETURN
|
2023-07-21 17:32:37 +02:00
|
|
|
"
|
2022-08-31 22:32:56 +02:00
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "true");
|
|
|
|
})
|
|
|
|
}
|
2024-03-09 17:58:02 +01:00
|
|
|
#[test]
|
|
|
|
fn nu_check_module_dir() {
|
|
|
|
Playground::setup("nu_check_test_26", |dirs, sandbox| {
|
|
|
|
sandbox
|
|
|
|
.mkdir("lol")
|
2024-05-04 02:53:15 +02:00
|
|
|
.with_files(&[FileWithContentToBeTrimmed(
|
2024-03-09 17:58:02 +01:00
|
|
|
"lol/mod.nu",
|
|
|
|
r#"
|
|
|
|
export module foo.nu
|
|
|
|
export def main [] { 'lol' }
|
|
|
|
"#,
|
|
|
|
)])
|
2024-05-04 02:53:15 +02:00
|
|
|
.with_files(&[FileWithContentToBeTrimmed(
|
2024-03-09 17:58:02 +01:00
|
|
|
"lol/foo.nu",
|
|
|
|
r#"
|
|
|
|
export def main [] { 'lol foo' }
|
|
|
|
"#,
|
|
|
|
)]);
|
|
|
|
|
|
|
|
let actual = nu!(cwd: dirs.test(), pipeline( "nu-check lol"));
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "true");
|
|
|
|
})
|
|
|
|
}
|