Fix some of the tests in tests::shell (#12417)

# Description
Some of the tests in `tests::shell` were using `sh` unnecessarily, and
had `#[cfg(not(windows))]` when they should be testable on Windows if
`sh` is not used.

I also found that they were using `.expect()` incorrectly, under the
assumption that that would check their output, when really an
`assert_eq!` on the output is needed to do that. So these tests weren't
even really working properly before.

# User-Facing Changes
None

# Tests + Formatting
- 🟢 `toolkit fmt`
- 🟢 `toolkit clippy`
- 🟢 `toolkit test`
- 🟢 `toolkit test stdlib`
This commit is contained in:
Devyn Cairns 2024-04-05 20:57:47 -07:00 committed by GitHub
parent 0e36c43c64
commit 16cbed7d6e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -229,62 +229,46 @@ fn run_export_extern() {
}
#[test]
#[cfg(not(windows))]
fn run_in_login_mode() {
let child_output = std::process::Command::new("sh")
.arg("-c")
.arg(format!(
"{:?} --no-config-file --login --commands 'echo $nu.is-login'",
nu_test_support::fs::executable_path()
))
let child_output = std::process::Command::new(nu_test_support::fs::executable_path())
.args(["-n", "-l", "-c", "echo $nu.is-login"])
.output()
.expect("true");
.expect("failed to run nu");
assert_eq!("true\n", String::from_utf8_lossy(&child_output.stdout));
assert!(child_output.stderr.is_empty());
}
#[test]
#[cfg(not(windows))]
fn run_in_not_login_mode() {
let child_output = std::process::Command::new("sh")
.arg("-c")
.arg(format!(
"{:?} -c 'echo $nu.is-login'",
nu_test_support::fs::executable_path()
))
let child_output = std::process::Command::new(nu_test_support::fs::executable_path())
.args(["-c", "echo $nu.is-login"])
.output()
.expect("false");
.expect("failed to run nu");
assert_eq!("false\n", String::from_utf8_lossy(&child_output.stdout));
assert!(child_output.stderr.is_empty());
}
#[test]
#[cfg(not(windows))]
fn run_in_interactive_mode() {
let child_output = std::process::Command::new("sh")
.arg("-c")
.arg(format!(
"{:?} -i -c 'echo $nu.is-interactive'",
nu_test_support::fs::executable_path()
))
let child_output = std::process::Command::new(nu_test_support::fs::executable_path())
.args(["-i", "-c", "echo $nu.is-interactive"])
.output()
.expect("true");
.expect("failed to run nu");
assert_eq!("true\n", String::from_utf8_lossy(&child_output.stdout));
assert!(child_output.stderr.is_empty());
}
#[test]
#[cfg(not(windows))]
fn run_in_noninteractive_mode() {
let child_output = std::process::Command::new("sh")
.arg("-c")
.arg(format!(
"{:?} -c 'echo $nu.is-interactive'",
nu_test_support::fs::executable_path()
))
let child_output = std::process::Command::new(nu_test_support::fs::executable_path())
.args(["-c", "echo $nu.is-interactive"])
.output()
.expect("false");
.expect("failed to run nu");
assert_eq!("false\n", String::from_utf8_lossy(&child_output.stdout));
assert!(child_output.stderr.is_empty());
}