mirror of
https://github.com/nushell/nushell.git
synced 2025-07-28 03:19:33 +02:00
.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
# Description This makes assignment operations and `const` behave the same way `let` and `mut` do, absorbing the rest of the pipeline. Changes the lexer to be able to recognize assignment operators as a separate token, and then makes the lite parser continue to push spans into the same command regardless of any redirections or pipes if an assignment operator is encountered. Because the pipeline is no longer split up by the lite parser at this point, it's trivial to just parse the right hand side as if it were a subexpression not contained within parentheses. # User-Facing Changes Big breaking change. These are all now possible: ```nushell const path = 'a' | path join 'b' mut x = 2 $x = random int $x = [1 2 3] | math sum $env.FOO = random chars ``` In the past, these would have led to (an attempt at) bare word string parsing. So while `$env.FOO = bar` would have previously set the environment variable `FOO` to the string `"bar"`, it now tries to run the command named `bar`, hence the major breaking change. However, this is desirable because it is very consistent - if you see the `=`, you can just assume it absorbs everything else to the right of it. # Tests + Formatting Added tests for the new behaviour. Adjusted some existing tests that depended on the right hand side of assignments being parsed as barewords. # After Submitting - [ ] release notes (breaking change!)
108 lines
3.3 KiB
Rust
108 lines
3.3 KiB
Rust
use nu_test_support::nu;
|
|
|
|
#[test]
|
|
fn basic_stdout() {
|
|
let without_complete = nu!(r#"
|
|
nu --testbin cococo test
|
|
"#);
|
|
let with_complete = nu!(r#"
|
|
(nu --testbin cococo test | complete).stdout
|
|
"#);
|
|
|
|
assert_eq!(with_complete.out, without_complete.out);
|
|
}
|
|
|
|
#[test]
|
|
fn basic_exit_code() {
|
|
let with_complete = nu!(r#"
|
|
(nu --testbin cococo test | complete).exit_code
|
|
"#);
|
|
|
|
assert_eq!(with_complete.out, "0");
|
|
}
|
|
|
|
#[test]
|
|
fn error() {
|
|
let actual = nu!("not-found | complete");
|
|
assert!(actual.err.contains("Command `not-found` not found"));
|
|
}
|
|
|
|
#[test]
|
|
#[cfg(not(windows))]
|
|
fn capture_error_with_too_much_stderr_not_hang_nushell() {
|
|
use nu_test_support::fs::Stub::FileWithContent;
|
|
use nu_test_support::playground::Playground;
|
|
Playground::setup("external with many stderr message", |dirs, sandbox| {
|
|
let bytes: usize = 81920;
|
|
let mut large_file_body = String::with_capacity(bytes);
|
|
for _ in 0..bytes {
|
|
large_file_body.push('a');
|
|
}
|
|
sandbox.with_files(&[FileWithContent("a_large_file.txt", &large_file_body)]);
|
|
|
|
let actual =
|
|
nu!(cwd: dirs.test(), "sh -c 'cat a_large_file.txt 1>&2' | complete | get stderr");
|
|
|
|
assert_eq!(actual.out, large_file_body);
|
|
})
|
|
}
|
|
|
|
#[test]
|
|
#[cfg(not(windows))]
|
|
fn capture_error_with_too_much_stdout_not_hang_nushell() {
|
|
use nu_test_support::fs::Stub::FileWithContent;
|
|
use nu_test_support::playground::Playground;
|
|
Playground::setup("external with many stdout message", |dirs, sandbox| {
|
|
let bytes: usize = 81920;
|
|
let mut large_file_body = String::with_capacity(bytes);
|
|
for _ in 0..bytes {
|
|
large_file_body.push('a');
|
|
}
|
|
sandbox.with_files(&[FileWithContent("a_large_file.txt", &large_file_body)]);
|
|
|
|
let actual = nu!(cwd: dirs.test(), "sh -c 'cat a_large_file.txt' | complete | get stdout");
|
|
|
|
assert_eq!(actual.out, large_file_body);
|
|
})
|
|
}
|
|
|
|
#[test]
|
|
#[cfg(not(windows))]
|
|
fn capture_error_with_both_stdout_stderr_messages_not_hang_nushell() {
|
|
use nu_test_support::fs::Stub::FileWithContent;
|
|
use nu_test_support::playground::Playground;
|
|
Playground::setup(
|
|
"external with many stdout and stderr messages",
|
|
|dirs, sandbox| {
|
|
let script_body = r#"
|
|
x=$(printf '=%.0s' $(seq 40960))
|
|
echo $x
|
|
echo $x 1>&2
|
|
"#;
|
|
let expect_body = "=".repeat(40960);
|
|
|
|
sandbox.with_files(&[FileWithContent("test.sh", script_body)]);
|
|
|
|
// check for stdout
|
|
let actual = nu!(cwd: dirs.test(), "sh test.sh | complete | get stdout | str trim");
|
|
assert_eq!(actual.out, expect_body);
|
|
// check for stderr
|
|
let actual = nu!(cwd: dirs.test(), "sh test.sh | complete | get stderr | str trim");
|
|
assert_eq!(actual.out, expect_body);
|
|
},
|
|
)
|
|
}
|
|
|
|
#[test]
|
|
fn combined_pipe_redirection() {
|
|
let actual = nu!("$env.FOO = 'hello'; $env.BAR = 'world'; nu --testbin echo_env_mixed out-err FOO BAR o+e>| complete | get stdout");
|
|
assert_eq!(actual.out, "helloworld");
|
|
}
|
|
|
|
#[test]
|
|
fn err_pipe_redirection() {
|
|
let actual =
|
|
nu!("$env.FOO = 'hello'; nu --testbin echo_env_stderr FOO e>| complete | get stdout");
|
|
assert_eq!(actual.out, "hello");
|
|
}
|