From c7c427723bd2a065603cf081391c908b0ff4232d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C5=BD=C3=A1dn=C3=ADk?= Date: Fri, 18 Feb 2022 00:23:04 +0200 Subject: [PATCH] Test support fixes (#4517) * Fix failing pipeline() The `skip(1)` was there likely to remove the welcome message. * Fix typo * Fix nu! test macro to enter cwd correctly Nushell's current working directory is determined primarily by the PWD environment variable. --- crates/nu-test-support/src/lib.rs | 2 +- crates/nu-test-support/src/macros.rs | 12 +++++++----- src/utils.rs | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/crates/nu-test-support/src/lib.rs b/crates/nu-test-support/src/lib.rs index 7075ae0ca..7f297123d 100644 --- a/crates/nu-test-support/src/lib.rs +++ b/crates/nu-test-support/src/lib.rs @@ -26,8 +26,8 @@ impl Outcome { pub fn pipeline(commands: &str) -> String { commands + .trim() .lines() - .skip(1) .map(|line| line.trim()) .collect::>() .join(" ") diff --git a/crates/nu-test-support/src/macros.rs b/crates/nu-test-support/src/macros.rs index f69275441..e46181fbb 100644 --- a/crates/nu-test-support/src/macros.rs +++ b/crates/nu-test-support/src/macros.rs @@ -23,10 +23,8 @@ macro_rules! nu { // let commands = &*format!( // " - // cd \"{}\" // {} // exit", - // $crate::fs::in_directory($cwd), // $crate::fs::DisplayPath::display_path(&$path) // ); @@ -51,13 +49,16 @@ macro_rules! nu { Err(_) => panic!("Couldn't join paths for PATH var."), }; + let target_cwd = $crate::fs::in_directory(&$cwd); + let mut process = match Command::new($crate::fs::executable_path()) + .env("PWD", &target_cwd) // setting PWD is enough to set cwd .env(NATIVE_PATH_ENV_VAR, paths_joined) // .arg("--skip-plugins") // .arg("--no-history") // .arg("--config-file") // .arg($crate::fs::DisplayPath::display_path(&$crate::fs::fixtures().join("playground/config/default.toml"))) - .arg(format!("-c 'cd {}; {}'", $crate::fs::in_directory($cwd), $crate::fs::DisplayPath::display_path(&path))) + .arg(format!("-c '{}'", $crate::fs::DisplayPath::display_path(&path))) .stdout(Stdio::piped()) // .stdin(Stdio::piped()) .stderr(Stdio::piped()) @@ -109,10 +110,8 @@ macro_rules! nu_with_plugins { let commands = &*format!( " - cd \"{}\" {} exit", - $crate::fs::in_directory($cwd), $crate::fs::DisplayPath::display_path(&$path) ); @@ -133,7 +132,10 @@ macro_rules! nu_with_plugins { Err(_) => panic!("Couldn't join paths for PATH var."), }; + let target_cwd = $crate::fs::in_directory(&$cwd); + let mut process = match Command::new($crate::fs::executable_path()) + .env("PWD", &target_cwd) // setting PWD is enough to set cwd .env(NATIVE_PATH_ENV_VAR, paths_joined) .stdout(Stdio::piped()) .stdin(Stdio::piped()) diff --git a/src/utils.rs b/src/utils.rs index 21ecf7b25..843ce9ee4 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -9,7 +9,7 @@ use nu_protocol::{ }; use std::{io::Write, path::PathBuf}; -// This fill collect environment variables from std::env and adds them to a stack. +// This will collect environment variables from std::env and adds them to a stack. // // In order to ensure the values have spans, it first creates a dummy file, writes the collected // env vars into it (in a "NAME"="value" format, quite similar to the output of the Unix 'env'