2022-10-15 18:00:38 +02:00
|
|
|
use nu_test_support::fs::Stub::EmptyFile;
|
2023-08-31 23:10:29 +02:00
|
|
|
use nu_test_support::nu;
|
2022-10-15 18:00:38 +02:00
|
|
|
use nu_test_support::playground::Playground;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn empty_glob_pattern_triggers_error() {
|
|
|
|
Playground::setup("glob_test_1", |dirs, sandbox| {
|
|
|
|
sandbox.with_files(vec![
|
|
|
|
EmptyFile("yehuda.txt"),
|
2023-03-15 06:54:55 +01:00
|
|
|
EmptyFile("jttxt"),
|
2022-10-15 18:00:38 +02:00
|
|
|
EmptyFile("andres.txt"),
|
|
|
|
]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(),
|
|
|
|
"glob ''",
|
|
|
|
);
|
|
|
|
|
|
|
|
assert!(actual.err.contains("must not be empty"));
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn nonempty_glob_lists_matching_paths() {
|
|
|
|
Playground::setup("glob_sanity_star", |dirs, sandbox| {
|
|
|
|
sandbox.with_files(vec![
|
|
|
|
EmptyFile("yehuda.txt"),
|
2023-03-15 06:54:55 +01:00
|
|
|
EmptyFile("jttxt"),
|
2022-10-15 18:00:38 +02:00
|
|
|
EmptyFile("andres.txt"),
|
|
|
|
]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(),
|
2023-08-31 23:10:29 +02:00
|
|
|
"glob '*' | length",
|
2022-10-15 18:00:38 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "3");
|
|
|
|
})
|
|
|
|
}
|
2023-01-28 14:50:12 +01:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn glob_subdirs() {
|
|
|
|
Playground::setup("glob_subdirs", |dirs, sandbox| {
|
|
|
|
sandbox.with_files(vec![
|
|
|
|
EmptyFile("yehuda.txt"),
|
2023-03-15 06:54:55 +01:00
|
|
|
EmptyFile("jttxt"),
|
2023-01-28 14:50:12 +01:00
|
|
|
EmptyFile("andres.txt"),
|
|
|
|
]);
|
|
|
|
sandbox.mkdir("children");
|
|
|
|
sandbox.within("children").with_files(vec![
|
|
|
|
EmptyFile("timothy.txt"),
|
|
|
|
EmptyFile("tiffany.txt"),
|
|
|
|
EmptyFile("trish.txt"),
|
|
|
|
]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(),
|
2023-08-31 23:10:29 +02:00
|
|
|
"glob '**/*' | length",
|
2023-01-28 14:50:12 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
actual.out, "8",
|
|
|
|
"count must be 8 due to 6 files and 2 folders, including the cwd"
|
|
|
|
);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn glob_subdirs_ignore_dirs() {
|
|
|
|
Playground::setup("glob_subdirs_ignore_directories", |dirs, sandbox| {
|
|
|
|
sandbox.with_files(vec![
|
|
|
|
EmptyFile("yehuda.txt"),
|
2023-03-15 06:54:55 +01:00
|
|
|
EmptyFile("jttxt"),
|
2023-01-28 14:50:12 +01:00
|
|
|
EmptyFile("andres.txt"),
|
|
|
|
]);
|
|
|
|
sandbox.mkdir("children");
|
|
|
|
sandbox.within("children").with_files(vec![
|
|
|
|
EmptyFile("timothy.txt"),
|
|
|
|
EmptyFile("tiffany.txt"),
|
|
|
|
EmptyFile("trish.txt"),
|
|
|
|
]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(),
|
2023-08-31 23:10:29 +02:00
|
|
|
"glob '**/*' -D | length",
|
2023-01-28 14:50:12 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
actual.out, "6",
|
|
|
|
"directory count must be 6, ignoring the cwd and the children folders"
|
|
|
|
);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn glob_ignore_files() {
|
|
|
|
Playground::setup("glob_ignore_files", |dirs, sandbox| {
|
|
|
|
sandbox.with_files(vec![
|
|
|
|
EmptyFile("yehuda.txt"),
|
2023-03-15 06:54:55 +01:00
|
|
|
EmptyFile("jttxt"),
|
2023-01-28 14:50:12 +01:00
|
|
|
EmptyFile("andres.txt"),
|
|
|
|
]);
|
|
|
|
sandbox.mkdir("children");
|
|
|
|
sandbox.within("children").with_files(vec![
|
|
|
|
EmptyFile("timothy.txt"),
|
|
|
|
EmptyFile("tiffany.txt"),
|
|
|
|
EmptyFile("trish.txt"),
|
|
|
|
]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(),
|
2023-08-31 23:10:29 +02:00
|
|
|
"glob '*' -F | length",
|
2023-01-28 14:50:12 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
actual.out, "1",
|
|
|
|
"should only find one folder; ignoring cwd, files, subfolders"
|
|
|
|
);
|
|
|
|
})
|
|
|
|
}
|