nushell/crates/nu-command/tests/commands
WindSoilder 8aa2632661
Support redirect err and out to different streams (#7685)
# Description

Closes: #7364 

# User-Facing Changes

Given the following shell script:
```bash
x=$(printf '=%.0s' {1..100})
echo $x
echo $x 1>&2
```

It supports the following command:
```
bash test.sh out> out.txt err> err.txt
```

Then both `out.txt` and `err.txt` will contain `=`(100 times)

## About the change

The core idea is that when doing lite-parsing, introduce a new variant
`LiteElement::SeparateRedirection` if we meet two Redirection
token(which is generated by `lex` function),
During converting from lite block to block,
`LiteElement::SeparateRedirection` will be converted to
`PipelineElement::SeparateRedirection`.

Then in the block eval process, if we get
`PipelineElement::SeparateRedirection`, we invoke `save` command with
`--stderr` arguments to acthive our behavior.



## What happened internally?
Take the following command as example:
```
^ls out> out.txt err> err.txt
```

lex parsing result(`Tokens`) are not changed, but `LiteBlock` and
`Block` is changed after this pr.

### LiteBlock before
```rust
LiteBlock {
    block: [
        LitePipeline { commands: [
            Command(None, LiteCommand { comments: [], parts: [Span { start: 39041, end: 39044 }] }),
            // actually the span of first Redirection is wrong too..
            Redirection(Span { start: 39058, end: 39062 }, Stdout, LiteCommand { comments: [], parts: [Span { start: 39050, end: 39057 }] }),
            Redirection(Span { start: 39058, end: 39062 }, Stderr, LiteCommand { comments: [], parts: [Span { start: 39063, end: 39070 }] })
        ]
    }]
}
```
### LiteBlock after
```rust
LiteBlock {
    block: [
        LitePipeline { commands: [
            Command(
                None, 
                LiteCommand { comments: [], parts: [Span { start: 38525, end: 38528 }] }),
                // new one! two Redirection merged into one SeparateRedirection.
                SeparateRedirection { 
                    out: (Span { start: 38529, end: 38533 }, LiteCommand { comments: [], parts: [Span { start: 38534, end: 38541 }] }),
                    err: (Span { start: 38542, end: 38546 }, LiteCommand { comments: [], parts: [Span { start: 38547, end: 38554 }] })
                }
        ]
    }]
}
```

### Block before
```rust
Pipeline {
    elements: [
        Expression(None, Expression {
            expr: ExternalCall(Expression { expr: String("ls"), span: Span { start: 39042, end: 39044 }, ty: String, custom_completion: None }, [], false),
            span: Span { start: 39041, end: 39044 },
            ty: Any, custom_completion: None 
        }),
        Redirection(Span { start: 39058, end: 39062 }, Stdout, Expression { expr: String("out.txt"), span: Span { start: 39050, end: 39057 }, ty: String, custom_completion: None }),
        Redirection(Span { start: 39058, end: 39062 }, Stderr, Expression { expr: String("err.txt"), span: Span { start: 39063, end: 39070 }, ty: String, custom_completion: None })] }
```

### Block after
```rust
Pipeline {
    elements: [
        Expression(None, Expression {
            expr: ExternalCall(Expression { expr: String("ls"), span: Span { start: 38526, end: 38528 }, ty: String, custom_completion: None }, [], false),
            span: Span { start: 38525, end: 38528 },
            ty: Any,
            custom_completion: None 
        }),
        // new one! SeparateRedirection
        SeparateRedirection {
            out: (Span { start: 38529, end: 38533 }, Expression { expr: String("out.txt"), span: Span { start: 38534, end: 38541 }, ty: String, custom_completion: None }),
            err: (Span { start: 38542, end: 38546 }, Expression { expr: String("err.txt"), span: Span { start: 38547, end: 38554 }, ty: String, custom_completion: None }) 
        }
    ]
}
```
# 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

# 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.
2023-01-12 10:22:30 +01:00
..
assignment ++= appendAssign operator (#7346) (#7354) 2022-12-09 11:20:58 -05:00
date Standardise the use of ShellError::UnsupportedInput and ShellError::TypeMismatch and add spans to every instance of the former (#7217) 2022-12-23 01:48:53 -05:00
hash_ Deprecate hash base64, extend decode and add encode commands (#5863) 2022-06-26 00:35:23 +03:00
math Remove math eval command (#7284) 2023-01-04 23:50:18 +01:00
move_ Fix mv error message issues (arrows, Windows paths) (#7197) 2022-11-23 16:55:13 +13:00
network Clippy fix for Rust 1.63 (#6299) 2022-08-11 11:54:54 -05:00
path add -n for path expand, so it doesn't follow symlink (#6255) 2022-08-10 08:43:56 -05:00
platform Return error when kill didn't terminate successfully (#6354) 2022-08-18 11:58:51 -05:00
query Feature cleanup (#7182) 2022-11-22 16:58:11 -08:00
random Another batch of command tests (#4496) 2022-02-16 07:38:02 -05:00
skip last, skip, drop, take until, take while, skip until, skip while, where, reverse, shuffle, append, prepend and sort-by raise error when given non-lists (#7623) 2022-12-31 13:35:12 +02:00
str_ Remove math eval command (#7284) 2023-01-04 23:50:18 +01:00
take last, skip, drop, take until, take while, skip until, skip while, where, reverse, shuffle, append, prepend and sort-by raise error when given non-lists (#7623) 2022-12-31 13:35:12 +02:00
url Standardise the use of ShellError::UnsupportedInput and ShellError::TypeMismatch and add spans to every instance of the former (#7217) 2022-12-23 01:48:53 -05:00
alias.rs Expand Nushell's help system (#7611) 2022-12-30 17:44:37 +02:00
all.rs Replace row conditions with closures in commands (#7428) 2022-12-10 19:24:06 +02:00
any.rs Replace row conditions with closures in commands (#7428) 2022-12-10 19:24:06 +02:00
append.rs revert changes on prepend and append (#7660) 2023-01-02 17:09:55 -08:00
break_.rs New commands: break, continue, return, and loop (#7230) 2022-11-25 09:39:16 +13:00
cal.rs return Error if get meet nothing and without "i" (#7002) 2022-12-31 13:27:09 +02:00
cd.rs fix: fixcd (#6799) 2022-11-05 07:38:39 +13:00
compact.rs Remove old nushell/merge engine-q 2022-02-07 14:54:06 -05:00
continue_.rs New commands: break, continue, return, and loop (#7230) 2022-11-25 09:39:16 +13:00
cp.rs Add decimals to int when using into string --decimals (#6085) 2022-08-12 21:13:50 -05:00
def.rs def: make various punctuation misuses into errors (#7624) 2022-12-31 13:18:53 +02:00
default.rs Make get hole errors and cell path hole errors identical (improvement on #7002) (#7647) 2023-01-02 14:45:43 -08:00
do_.rs A set of fixes for stderr redirect (#7219) 2022-11-24 16:58:15 +13:00
drop.rs last, skip, drop, take until, take while, skip until, skip while, where, reverse, shuffle, append, prepend and sort-by raise error when given non-lists (#7623) 2022-12-31 13:35:12 +02:00
each.rs Remove erroneous test (#7179) 2022-11-21 17:04:36 +01:00
echo.rs Require block params (#4505) 2022-02-17 06:40:24 -05:00
empty.rs Fix $in in blocks given to any and all (#6951) 2022-11-01 11:36:54 -07:00
enter.rs Remove old nushell/merge engine-q 2022-02-07 14:54:06 -05:00
error_make.rs add unspanned flag to error make, add tests (#6017) 2022-07-12 06:03:50 -05:00
every.rs Another batch of command tests (#4496) 2022-02-16 07:38:02 -05:00
exec.rs Add "fall-through" signatures (#7527) 2022-12-22 00:33:26 +02:00
export_def.rs allow -h flags for export subcommands (#6189) 2022-08-02 10:26:16 -05:00
find.rs Use 'table' on scripts and -c commands (#4377) 2022-02-09 05:58:54 -05:00
first.rs Make stream info visible to users in describe (#7589) 2023-01-03 21:08:05 -08:00
flatten.rs str collect => str join (#6531) 2022-09-11 11:48:27 +03:00
for_.rs break for, loop, while execution when external command runs to failed (#7475) 2022-12-14 16:20:18 +01:00
format.rs prevent panic with format command (#7522) 2022-12-19 13:10:02 +01:00
g.rs Make g - switch to the last used shell (#6249) 2022-08-06 10:11:03 -05:00
get.rs Make get hole errors and cell path hole errors identical (improvement on #7002) (#7647) 2023-01-02 14:45:43 -08:00
glob.rs Filter out empty glob patterns to "glob" command (#6707) 2022-10-15 18:00:38 +02:00
group_by.rs more test fixes (#4499) 2022-02-16 12:24:45 -06:00
headers.rs Type validation for headers command (#6918) (#7047) 2022-11-09 16:43:24 -08:00
help.rs Expand Nushell's help system (#7611) 2022-12-30 17:44:37 +02:00
histogram.rs add quantile column (#5583) 2022-05-18 20:47:26 -05:00
insert.rs Allow iteration blocks to have an optional extra index parameter (alternative to -n flags) (#6994) 2022-11-21 14:35:11 +01:00
into_filesize.rs fix overflow on negative bytes (#7070) 2022-11-10 22:33:15 +01:00
into_int.rs Binary into int (#5941) 2022-07-04 06:31:50 +12:00
last.rs Make stream info visible to users in describe (#7589) 2023-01-03 21:08:05 -08:00
length.rs Remove old nushell/merge engine-q 2022-02-07 14:54:06 -05:00
let_.rs Limited mutable variables (#7089) 2022-11-11 19:51:08 +13:00
lines.rs Replace row conditions with closures in commands (#7428) 2022-12-10 19:24:06 +02:00
loop_.rs break for, loop, while execution when external command runs to failed (#7475) 2022-12-14 16:20:18 +01:00
ls.rs let UnknownFlag error list out available flags (#7443) 2022-12-13 06:45:33 -06:00
merge.rs remove block input support in merge (#7177) 2022-11-23 17:01:27 +13:00
mkdir.rs mkdir change flag -s to -v (#7462) 2022-12-13 11:56:44 -05:00
mod.rs Make to text stream ListStreams (#7577) 2022-12-22 16:38:07 -08:00
mut_.rs Allow $env and mutable records to be mutated by = (closes #7110) (#7318) 2022-12-06 19:51:55 +02:00
n.rs Refactor shell switching related code (#6258) 2022-08-07 13:30:40 -05:00
nu_check.rs A set of fixes for stderr redirect (#7219) 2022-11-24 16:58:15 +13:00
open.rs Make get hole errors and cell path hole errors identical (improvement on #7002) (#7647) 2023-01-02 14:45:43 -08:00
p.rs Refactor shell switching related code (#6258) 2022-08-07 13:30:40 -05:00
parse.rs replace the regex crate with the fancy-regex crate (#6227) 2022-08-04 14:51:02 -05:00
prepend.rs revert changes on prepend and append (#7660) 2023-01-02 17:09:55 -08:00
print.rs add -e flag to print, to print the value to stderr (#5935) 2022-07-02 09:54:49 -05:00
range.rs Use 'table' on scripts and -c commands (#4377) 2022-02-09 05:58:54 -05:00
redirection.rs Support redirect err and out to different streams (#7685) 2023-01-12 10:22:30 +01:00
reduce.rs Remove math eval command (#7284) 2023-01-04 23:50:18 +01:00
reject.rs add signature information when get help on one command (#7079) 2022-11-20 07:22:42 -06:00
rename.rs Standardise the use of ShellError::UnsupportedInput and ShellError::TypeMismatch and add spans to every instance of the former (#7217) 2022-12-23 01:48:53 -05:00
return_.rs New commands: break, continue, return, and loop (#7230) 2022-11-25 09:39:16 +13:00
reverse.rs last, skip, drop, take until, take while, skip until, skip while, where, reverse, shuffle, append, prepend and sort-by raise error when given non-lists (#7623) 2022-12-31 13:35:12 +02:00
rm.rs make cd, cp, ls, mv, open and rm automatically strip ansi codes (#6220) 2022-08-04 06:59:20 -05:00
roll.rs Standardise the use of ShellError::UnsupportedInput and ShellError::TypeMismatch and add spans to every instance of the former (#7217) 2022-12-23 01:48:53 -05:00
rotate.rs str collect => str join (#6531) 2022-09-11 11:48:27 +03:00
run_external.rs don't expand tilde if we quote external arguments (#7711) 2023-01-11 19:14:19 -05:00
save.rs Fix save error handling (#7608) 2023-01-03 14:22:28 +01:00
select.rs Make get hole errors and cell path hole errors identical (improvement on #7002) (#7647) 2023-01-02 14:45:43 -08:00
semicolon.rs Remove old nushell/merge engine-q 2022-02-07 14:54:06 -05:00
seq_char.rs Simplify seq char (#7054) 2022-11-09 17:06:47 -08:00
seq.rs Make stream info visible to users in describe (#7589) 2023-01-03 21:08:05 -08:00
shells.rs Refactor shell listing related code (#6262) 2022-08-08 06:31:24 -05:00
sort_by.rs last, skip, drop, take until, take while, skip until, skip while, where, reverse, shuffle, append, prepend and sort-by raise error when given non-lists (#7623) 2022-12-31 13:35:12 +02:00
sort.rs Add -n flag to sort (formerly only available on sort-by) (#7293) 2022-12-01 07:11:30 -06:00
source_env.rs Initial support for parse-time constants (#7436) 2022-12-22 00:21:03 +02:00
split_by.rs Remove old nushell/merge engine-q 2022-02-07 14:54:06 -05:00
split_column.rs refactor: change column names from 'Column*' to 'column*' (#4556) 2022-02-19 19:26:47 -05:00
split_row.rs Remove old nushell/merge engine-q 2022-02-07 14:54:06 -05:00
table.rs Fix #7486 (#7487) 2022-12-15 09:55:15 -08:00
to_text.rs Make to text stream ListStreams (#7577) 2022-12-22 16:38:07 -08:00
touch.rs chore: chrono_update (#7132) 2022-11-27 07:19:02 +13:00
transpose.rs Prevents duplicate fields in transpose -r (#5840) 2022-06-22 19:19:06 -05:00
try_.rs Continue and Break on Try/Catch (#7683) 2023-01-05 21:41:51 +01:00
uniq_by.rs uniq-by command (#7295) 2022-12-02 11:36:01 +01:00
uniq.rs uniq -i does not convert to lowercase (#7192) (#7209) 2022-11-23 15:46:20 -08:00
update.rs Improve empty pipelines (#7383) 2022-12-08 07:31:57 +13:00
upsert.rs Improve empty pipelines (#7383) 2022-12-08 07:31:57 +13:00
use_.rs Expand Nushell's help system (#7611) 2022-12-30 17:44:37 +02:00
where_.rs last, skip, drop, take until, take while, skip until, skip while, where, reverse, shuffle, append, prepend and sort-by raise error when given non-lists (#7623) 2022-12-31 13:35:12 +02:00
which.rs Don't assume external ls (#4925) 2022-03-24 16:42:41 +13:00
while_.rs break for, loop, while execution when external command runs to failed (#7475) 2022-12-14 16:20:18 +01:00
with_env.rs Change other instances of $nothing to null (#7569) 2022-12-22 12:30:10 -08:00
wrap.rs Use 'table' on scripts and -c commands (#4377) 2022-02-09 05:58:54 -05:00
zip.rs Better errors when bash-like operators are used (#7241) 2022-12-08 12:02:11 +13:00