forked from extern/nushell
61455b457d
# Description This fixes up some clippy warnings and removes some old names/info from our unit tests # User-Facing Changes Internal changes only # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
121 lines
3.1 KiB
Rust
121 lines
3.1 KiB
Rust
use nu_test_support::fs::Stub::EmptyFile;
|
|
use nu_test_support::playground::Playground;
|
|
use nu_test_support::{nu, pipeline};
|
|
|
|
#[test]
|
|
fn empty_glob_pattern_triggers_error() {
|
|
Playground::setup("glob_test_1", |dirs, sandbox| {
|
|
sandbox.with_files(vec![
|
|
EmptyFile("yehuda.txt"),
|
|
EmptyFile("jttxt"),
|
|
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"),
|
|
EmptyFile("jttxt"),
|
|
EmptyFile("andres.txt"),
|
|
]);
|
|
|
|
let actual = nu!(
|
|
cwd: dirs.test(),
|
|
pipeline("glob '*' | length"),
|
|
);
|
|
|
|
assert_eq!(actual.out, "3");
|
|
})
|
|
}
|
|
|
|
#[test]
|
|
fn glob_subdirs() {
|
|
Playground::setup("glob_subdirs", |dirs, sandbox| {
|
|
sandbox.with_files(vec![
|
|
EmptyFile("yehuda.txt"),
|
|
EmptyFile("jttxt"),
|
|
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(),
|
|
pipeline("glob '**/*' | length"),
|
|
);
|
|
|
|
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"),
|
|
EmptyFile("jttxt"),
|
|
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(),
|
|
pipeline("glob '**/*' -D | length"),
|
|
);
|
|
|
|
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"),
|
|
EmptyFile("jttxt"),
|
|
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(),
|
|
pipeline("glob '*' -F | length"),
|
|
);
|
|
|
|
assert_eq!(
|
|
actual.out, "1",
|
|
"should only find one folder; ignoring cwd, files, subfolders"
|
|
);
|
|
})
|
|
}
|