nushell/crates/nu-command/tests/commands/redirection.rs
JT 8cca447e8c
A set of fixes for stderr redirect (#7219)
# Description

This is a set of fixes to `err>` to make it work a bit more predictably.

I've also revised the tests, which accidentally tested the wrong thing
for redirection, but should be more correct now.

# User-Facing Changes

_(List of all changes that impact the user experience here. This helps
us keep track of breaking changes.)_

# 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.
2022-11-24 16:58:15 +13:00

67 lines
1.5 KiB
Rust

use nu_test_support::nu;
use nu_test_support::playground::Playground;
#[cfg(not(windows))]
#[test]
fn redirect_err() {
Playground::setup("redirect_err_test", |dirs, _sandbox| {
let output = nu!(
cwd: dirs.test(),
"cat asdfasdfasdf.txt err> a.txt; cat a.txt"
);
assert!(output.out.contains("asdfasdfasdf.txt"));
})
}
#[cfg(windows)]
#[test]
fn redirect_err() {
Playground::setup("redirect_err_test", |dirs, _sandbox| {
let output = nu!(
cwd: dirs.test(),
"dir missingapplication err> a; (open a | size).bytes >= 16"
);
assert!(output.out.contains("true"));
})
}
#[cfg(not(windows))]
#[test]
fn redirect_outerr() {
Playground::setup("redirect_outerr_test", |dirs, _sandbox| {
let output = nu!(
cwd: dirs.test(),
"cat asdfasdfasdf.txt out+err> a; cat a"
);
assert!(output.out.contains("asdfasdfasdf.txt"));
})
}
#[cfg(windows)]
#[test]
fn redirect_outerr() {
Playground::setup("redirect_outerr_test", |dirs, _sandbox| {
let output = nu!(
cwd: dirs.test(),
"dir missingapplication out+err> a; (open a | size).bytes >= 16"
);
assert!(output.out.contains("true"));
})
}
#[test]
fn redirect_out() {
Playground::setup("redirect_out_test", |dirs, _sandbox| {
let output = nu!(
cwd: dirs.test(),
"echo 'hello' out> a; open a"
);
assert!(output.out.contains("hello"));
})
}