mirror of
https://github.com/nushell/nushell
synced 2024-12-27 05:23:11 +00:00
* Fix failing unit tests on Windows (#5142) Fix let_env_expressions failing on Windows: The env expression uses PATH, but on windows Path is used. Fix correctly_escape_external_arguments, execute_binary_in_string failing on Windows: Using cococo now to make sure testresults are platform independent * Update macros.rs Co-authored-by: JT <547158+jntrnr@users.noreply.github.com>
This commit is contained in:
parent
57761149f4
commit
594006cfa0
3 changed files with 28 additions and 7 deletions
18
src/tests.rs
18
src/tests.rs
|
@ -16,12 +16,25 @@ mod test_type_check;
|
|||
|
||||
use assert_cmd::prelude::*;
|
||||
use pretty_assertions::assert_eq;
|
||||
use std::collections::HashMap;
|
||||
use std::io::Write;
|
||||
use std::process::Command;
|
||||
use tempfile::NamedTempFile;
|
||||
|
||||
pub type TestResult = Result<(), Box<dyn std::error::Error>>;
|
||||
|
||||
pub fn run_test_with_env(input: &str, expected: &str, env: &HashMap<&str, &str>) -> TestResult {
|
||||
let mut file = NamedTempFile::new()?;
|
||||
let name = file.path();
|
||||
|
||||
let mut cmd = Command::cargo_bin("nu")?;
|
||||
cmd.arg(name).envs(env);
|
||||
|
||||
writeln!(file, "{}", input)?;
|
||||
|
||||
run_cmd_and_assert(cmd, expected)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub fn run_test(input: &str, expected: &str) -> TestResult {
|
||||
let mut file = NamedTempFile::new()?;
|
||||
|
@ -32,6 +45,11 @@ pub fn run_test(input: &str, expected: &str) -> TestResult {
|
|||
|
||||
writeln!(file, "{}", input)?;
|
||||
|
||||
run_cmd_and_assert(cmd, expected)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
fn run_cmd_and_assert(mut cmd: Command, expected: &str) -> TestResult {
|
||||
let output = cmd.output()?;
|
||||
|
||||
let stderr = String::from_utf8_lossy(&output.stderr).to_string();
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use crate::tests::{fail_test, run_test, TestResult};
|
||||
use crate::tests::{fail_test, run_test, run_test_with_env, TestResult};
|
||||
use std::collections::HashMap;
|
||||
|
||||
use super::run_test_contains;
|
||||
|
||||
|
@ -197,9 +198,11 @@ fn equals_separates_long_flag() -> TestResult {
|
|||
|
||||
#[test]
|
||||
fn let_env_expressions() -> TestResult {
|
||||
run_test(
|
||||
r#"let-env PATH = if (env | any? name == VENV_OLD_PATH) { $env.VENV_OLD_PATH } else { $env.PATH }; echo done"#,
|
||||
"done",
|
||||
let env = HashMap::from([("VENV_OLD_PATH", "Foobar"), ("Path", "Quux")]);
|
||||
run_test_with_env(
|
||||
r#"let-env Path = if (env | any? name == VENV_OLD_PATH) { $env.VENV_OLD_PATH } else { $env.Path }; echo $env.Path"#,
|
||||
"Foobar",
|
||||
&env,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -66,7 +66,7 @@ fn automatically_change_directory_with_trailing_slash_and_same_name_as_command()
|
|||
|
||||
#[test]
|
||||
fn correctly_escape_external_arguments() {
|
||||
let actual = nu!(cwd: ".", r#"^echo '$0'"#);
|
||||
let actual = nu!(cwd: ".", r#"^nu --testbin cococo '$0'"#);
|
||||
|
||||
assert_eq!(actual.out, "$0");
|
||||
}
|
||||
|
@ -76,8 +76,8 @@ fn execute_binary_in_string() {
|
|||
let actual = nu!(
|
||||
cwd: ".",
|
||||
r#"
|
||||
let cmd = "echo"
|
||||
^$"($cmd)" "$0"
|
||||
let cmd = "nu"
|
||||
^$"($cmd)" --testbin cococo "$0"
|
||||
"#);
|
||||
|
||||
assert_eq!(actual.out, "$0");
|
||||
|
|
Loading…
Reference in a new issue