Make pipe redirections consistent, add err>| etc. forms (#13334)

# Description

Fixes the lexer to recognize `out>|`, `err>|`, `out+err>|`, etc.

Previously only the short-style forms were recognized, which was
inconsistent with normal file redirections.

I also integrated it all more into the normal lex path by checking `|`
in a special way, which should be more performant and consistent, and
cleans up the code a bunch.

Closes #13331.

# User-Facing Changes
- Adds `out>|` (error), `err>|`, `out+err>|`, `err+out>|` as recognized
forms of the pipe redirection.

# Tests + Formatting
All passing. Added tests for the new forms.

# After Submitting
- [ ] release notes
This commit is contained in:
Devyn Cairns
2024-07-10 16:16:22 -07:00
committed by GitHub
parent 616e9faaf1
commit ea8c4e3af2
2 changed files with 44 additions and 82 deletions

View File

@ -149,17 +149,26 @@ fn command_substitution_wont_output_extra_newline() {
assert_eq!(actual.out, "bar");
}
#[test]
fn basic_err_pipe_works() {
let actual =
nu!(r#"with-env { FOO: "bar" } { nu --testbin echo_env_stderr FOO e>| str length }"#);
#[rstest::rstest]
#[case("err>|")]
#[case("e>|")]
fn basic_err_pipe_works(#[case] redirection: &str) {
let actual = nu!(
r#"with-env { FOO: "bar" } { nu --testbin echo_env_stderr FOO {redirection} str length }"#
.replace("{redirection}", redirection)
);
assert_eq!(actual.out, "3");
}
#[test]
fn basic_outerr_pipe_works() {
#[rstest::rstest]
#[case("out+err>|")]
#[case("err+out>|")]
#[case("o+e>|")]
#[case("e+o>|")]
fn basic_outerr_pipe_works(#[case] redirection: &str) {
let actual = nu!(
r#"with-env { FOO: "bar" } { nu --testbin echo_env_mixed out-err FOO FOO o+e>| str length }"#
r#"with-env { FOO: "bar" } { nu --testbin echo_env_mixed out-err FOO FOO {redirection} str length }"#
.replace("{redirection}", redirection)
);
assert_eq!(actual.out, "7");
}