mirror of
https://github.com/nushell/nushell.git
synced 2024-12-01 21:03:58 +01:00
b2c5af457e
This improves incremental build time when working on what was previously the root package. For example, previously all plugins would be rebuilt with a change to `src/commands/classified/external.rs`, but now only `nu-cli` will have to be rebuilt (and anything that depends on it).
134 lines
3.2 KiB
Rust
134 lines
3.2 KiB
Rust
use nu_test_support::fs::Stub::EmptyFile;
|
|
use nu_test_support::playground::Playground;
|
|
use nu_test_support::{nu, nu_error, pipeline};
|
|
|
|
#[test]
|
|
fn lists_regular_files() {
|
|
Playground::setup("ls_test_1", |dirs, sandbox| {
|
|
sandbox.with_files(vec![
|
|
EmptyFile("yehuda.txt"),
|
|
EmptyFile("jonathan.txt"),
|
|
EmptyFile("andres.txt"),
|
|
]);
|
|
|
|
let actual = nu!(
|
|
cwd: dirs.test(), pipeline(
|
|
r#"
|
|
ls
|
|
| count
|
|
| echo $it
|
|
"#
|
|
));
|
|
|
|
assert_eq!(actual, "3");
|
|
})
|
|
}
|
|
|
|
#[test]
|
|
fn lists_regular_files_using_asterisk_wildcard() {
|
|
Playground::setup("ls_test_2", |dirs, sandbox| {
|
|
sandbox.with_files(vec![
|
|
EmptyFile("los.txt"),
|
|
EmptyFile("tres.txt"),
|
|
EmptyFile("amigos.txt"),
|
|
EmptyFile("arepas.clu"),
|
|
]);
|
|
|
|
let actual = nu!(
|
|
cwd: dirs.test(), pipeline(
|
|
r#"
|
|
ls *.txt
|
|
| count
|
|
| echo $it
|
|
"#
|
|
));
|
|
|
|
assert_eq!(actual, "3");
|
|
})
|
|
}
|
|
|
|
#[test]
|
|
fn lists_regular_files_using_question_mark_wildcard() {
|
|
Playground::setup("ls_test_3", |dirs, sandbox| {
|
|
sandbox.with_files(vec![
|
|
EmptyFile("yehuda.10.txt"),
|
|
EmptyFile("jonathan.10.txt"),
|
|
EmptyFile("andres.10.txt"),
|
|
EmptyFile("chicken_not_to_be_picked_up.100.txt"),
|
|
]);
|
|
|
|
let actual = nu!(
|
|
cwd: dirs.test(), pipeline(
|
|
r#"
|
|
ls *.??.txt
|
|
| count
|
|
| echo $it
|
|
"#
|
|
));
|
|
|
|
assert_eq!(actual, "3");
|
|
})
|
|
}
|
|
|
|
#[test]
|
|
fn lists_all_files_in_directories_from_stream() {
|
|
Playground::setup("ls_test_4", |dirs, sandbox| {
|
|
sandbox
|
|
.with_files(vec![EmptyFile("root1.txt"), EmptyFile("root2.txt")])
|
|
.within("dir_a")
|
|
.with_files(vec![
|
|
EmptyFile("yehuda.10.txt"),
|
|
EmptyFile("jonathan.10.txt"),
|
|
])
|
|
.within("dir_b")
|
|
.with_files(vec![
|
|
EmptyFile("andres.10.txt"),
|
|
EmptyFile("chicken_not_to_be_picked_up.100.txt"),
|
|
]);
|
|
|
|
let actual = nu!(
|
|
cwd: dirs.test(), pipeline(
|
|
r#"
|
|
echo dir_a dir_b
|
|
| ls $it
|
|
| count
|
|
| echo $it
|
|
"#
|
|
));
|
|
|
|
assert_eq!(actual, "4");
|
|
})
|
|
}
|
|
|
|
#[test]
|
|
fn does_not_fail_if_glob_matches_empty_directory() {
|
|
Playground::setup("ls_test_5", |dirs, sandbox| {
|
|
sandbox.within("dir_a");
|
|
|
|
let actual = nu!(
|
|
cwd: dirs.test(), pipeline(
|
|
r#"
|
|
ls dir_a
|
|
| count
|
|
| echo $it
|
|
"#
|
|
));
|
|
|
|
assert_eq!(actual, "0");
|
|
})
|
|
}
|
|
|
|
#[test]
|
|
fn fails_when_glob_doesnt_match() {
|
|
Playground::setup("ls_test_5", |dirs, sandbox| {
|
|
sandbox.with_files(vec![EmptyFile("root1.txt"), EmptyFile("root2.txt")]);
|
|
|
|
let actual = nu_error!(
|
|
cwd: dirs.test(),
|
|
"ls root3*"
|
|
);
|
|
|
|
assert!(actual.contains("invalid file or pattern"));
|
|
})
|
|
}
|