1
0
mirror of https://github.com/nushell/nushell.git synced 2025-08-11 06:04:38 +02:00
Files
.cargo
.githooks
.github
assets
benches
crates
nu-cli
nu-cmd-base
nu-cmd-extra
nu-cmd-lang
nu-cmd-plugin
nu-color-config
nu-command
src
tests
commands
assignment
base
bytes
conversions
database
date
debug
hash_
math
move_
network
path
platform
query
random
skip
str_
take
url
alias.rs
all.rs
any.rs
append.rs
break_.rs
cal.rs
cd.rs
chunks.rs
compact.rs
complete.rs
config_env_default.rs
config_nu_default.rs
continue_.rs
debug_info.rs
def.rs
default.rs
detect_columns.rs
do_.rs
drop.rs
du.rs
each.rs
echo.rs
empty.rs
error_make.rs
every.rs
exec.rs
export_def.rs
fill.rs
filter.rs
find.rs
first.rs
flatten.rs
for_.rs
format.rs
generate.rs
get.rs
glob.rs
griddle.rs
group_by.rs
headers.rs
help.rs
histogram.rs
ignore.rs
insert.rs
inspect.rs
interleave.rs
into_datetime.rs
into_filesize.rs
into_int.rs
join.rs
last.rs
length.rs
let_.rs
lines.rs
loop_.rs
ls.rs
match_.rs
merge.rs
mktemp.rs
mod.rs
mut_.rs
nu_check.rs
open.rs
par_each.rs
parse.rs
prepend.rs
print.rs
range.rs
redirection.rs
reduce.rs
reject.rs
rename.rs
return_.rs
reverse.rs
rm.rs
roll.rs
rotate.rs
run_external.rs
save.rs
select.rs
semicolon.rs
seq.rs
seq_char.rs
seq_date.rs
sort.rs
sort_by.rs
source_env.rs
split_by.rs
split_column.rs
split_row.rs
table.rs
tee.rs
terminal.rs
to_text.rs
touch.rs
transpose.rs
try_.rs
ucp.rs
ulimit.rs
umkdir.rs
uname.rs
uniq.rs
uniq_by.rs
update.rs
upsert.rs
use_.rs
where_.rs
which.rs
while_.rs
window.rs
with_env.rs
wrap.rs
zip.rs
format_conversions
main.rs
Cargo.toml
LICENSE
README.md
nu-derive-value
nu-engine
nu-explore
nu-glob
nu-json
nu-lsp
nu-parser
nu-path
nu-plugin
nu-plugin-core
nu-plugin-engine
nu-plugin-protocol
nu-plugin-test-support
nu-pretty-hex
nu-protocol
nu-std
nu-system
nu-table
nu-term-grid
nu-test-support
nu-utils
nu_plugin_custom_values
nu_plugin_example
nu_plugin_formats
nu_plugin_gstat
nu_plugin_inc
nu_plugin_nu_example
nu_plugin_polars
nu_plugin_python
nu_plugin_query
nu_plugin_stress_internals
nuon
README.md
devdocs
docker
scripts
src
tests
wix
.gitattributes
.gitignore
CITATION.cff
CODE_OF_CONDUCT.md
CONTRIBUTING.md
Cargo.lock
Cargo.toml
Cross.toml
LICENSE
README.md
SECURITY.md
rust-toolchain.toml
toolkit.nu
typos.toml
nushell/crates/nu-command/tests/commands/du.rs
Stefan Holderbach 406df7f208 Avoid taking unnecessary ownership of intermediates ()
# Description

Judiciously try to avoid allocations/clone by changing the signature of
functions

- **Don't pass str by value unnecessarily if only read**
- **Don't require a vec in `Sandbox::with_files`**
- **Remove unnecessary string clone**
- **Fixup unnecessary borrow**
- **Use `&str` in shape color instead**
- **Vec -> Slice**
- **Elide string clone**
- **Elide `Path` clone**
- **Take &str to elide clone in tests**

# User-Facing Changes
None

# Tests + Formatting
This touches many tests purely in changing from owned to borrowed/static
data
2024-05-04 00:53:15 +00:00

103 lines
2.5 KiB
Rust

use nu_test_support::fs::Stub::EmptyFile;
use nu_test_support::{nu, pipeline, playground::Playground};
use rstest::rstest;
#[test]
fn test_du_flag_min_size() {
let actual = nu!(
cwd: "tests/fixtures/formats", pipeline(
r#"
du -m -1
"#
));
assert!(actual
.err
.contains("Negative value passed when positive one is required"));
let actual = nu!(
cwd: "tests/fixtures/formats", pipeline(
r#"
du -m 1
"#
));
assert!(actual.err.is_empty());
}
#[test]
fn test_du_flag_max_depth() {
let actual = nu!(
cwd: "tests/fixtures/formats", pipeline(
r#"
du -d -2
"#
));
assert!(actual
.err
.contains("Negative value passed when positive one is required"));
let actual = nu!(
cwd: "tests/fixtures/formats", pipeline(
r#"
du -d 2
"#
));
assert!(actual.err.is_empty());
}
#[rstest]
#[case("a]c")]
#[case("a[c")]
#[case("a[bc]d")]
#[case("a][c")]
fn du_files_with_glob_metachars(#[case] src_name: &str) {
Playground::setup("du_test_16", |dirs, sandbox| {
sandbox.with_files(&[EmptyFile(src_name)]);
let src = dirs.test().join(src_name);
let actual = nu!(
cwd: dirs.test(),
"du -d 1 '{}'",
src.display(),
);
assert!(actual.err.is_empty());
// also test for variables.
let actual = nu!(
cwd: dirs.test(),
"let f = '{}'; du -d 1 $f",
src.display(),
);
assert!(actual.err.is_empty());
});
}
#[cfg(not(windows))]
#[rstest]
#[case("a]?c")]
#[case("a*.?c")]
// windows doesn't allow filename with `*`.
fn du_files_with_glob_metachars_nw(#[case] src_name: &str) {
du_files_with_glob_metachars(src_name);
}
#[test]
fn du_with_multiple_path() {
let actual = nu!(cwd: "tests/fixtures", "du cp formats | get path | path basename");
assert!(actual.out.contains("cp"));
assert!(actual.out.contains("formats"));
assert!(!actual.out.contains("lsp"));
assert!(actual.status.success());
// report errors if one path not exists
let actual = nu!(cwd: "tests/fixtures", "du cp asdf | get path | path basename");
assert!(actual.err.contains("directory not found"));
assert!(!actual.status.success());
// du with spreading empty list should returns nothing.
let actual = nu!(cwd: "tests/fixtures", "du ...[] | length");
assert_eq!(actual.out, "0");
}