diff options
Diffstat (limited to 'test_util/src')
-rw-r--r-- | test_util/src/builders.rs | 27 | ||||
-rw-r--r-- | test_util/src/lib.rs | 24 | ||||
-rw-r--r-- | test_util/src/pty.rs | 7 |
3 files changed, 31 insertions, 27 deletions
diff --git a/test_util/src/builders.rs b/test_util/src/builders.rs index 84befb57a..4997dac2c 100644 --- a/test_util/src/builders.rs +++ b/test_util/src/builders.rs @@ -312,6 +312,14 @@ impl TestCommandBuilder { .collect::<Vec<_>>() } + fn build_envs(&self) -> HashMap<String, String> { + let mut envs = self.context.envs.clone(); + for (key, value) in &self.envs { + envs.insert(key.to_string(), value.to_string()); + } + envs + } + pub fn with_pty(&self, mut action: impl FnMut(Pty)) { if !Pty::is_supported() { return; @@ -319,11 +327,20 @@ impl TestCommandBuilder { let args = self.build_args(); let args = args.iter().map(|s| s.as_str()).collect::<Vec<_>>(); - let mut envs = self.envs.clone(); + let mut envs = self.build_envs(); if !envs.contains_key("NO_COLOR") { // set this by default for pty tests envs.insert("NO_COLOR".to_string(), "1".to_string()); } + + // note(dsherret): for some reason I need to inject the current + // environment here for the pty tests or else I get dns errors + if !self.env_clear { + for (key, value) in std::env::vars() { + envs.entry(key).or_insert(value); + } + } + action(Pty::new( &self.build_command_path(), &args, @@ -361,13 +378,7 @@ impl TestCommandBuilder { command.env_clear(); } command.env("DENO_DIR", self.context.deno_dir.path()); - command.envs({ - let mut envs = self.context.envs.clone(); - for (key, value) in &self.envs { - envs.insert(key.to_string(), value.to_string()); - } - envs - }); + command.envs(self.build_envs()); command.current_dir(cwd); command.stdin(Stdio::piped()); diff --git a/test_util/src/lib.rs b/test_util/src/lib.rs index b38d72cd9..c844e594f 100644 --- a/test_util/src/lib.rs +++ b/test_util/src/lib.rs @@ -2166,24 +2166,12 @@ pub fn pattern_match(pattern: &str, s: &str, wildcard: &str) -> bool { t.1.is_empty() } -pub fn with_pty(deno_args: &[&str], mut action: impl FnMut(Pty)) { - if !Pty::is_supported() { - return; - } - - let deno_dir = new_deno_dir(); - let mut env_vars = std::collections::HashMap::new(); - env_vars.insert("NO_COLOR".to_string(), "1".to_string()); - env_vars.insert( - "DENO_DIR".to_string(), - deno_dir.path().to_string_lossy().to_string(), - ); - action(Pty::new( - &deno_exe_path(), - deno_args, - &testdata_path(), - Some(env_vars), - )) +pub fn with_pty(deno_args: &[&str], action: impl FnMut(Pty)) { + let context = TestContextBuilder::default().build(); + context + .new_command() + .args_vec(deno_args.iter().map(ToString::to_string).collect()) + .with_pty(action); } pub struct WrkOutput { diff --git a/test_util/src/pty.rs b/test_util/src/pty.rs index 80d06881e..2f89e481e 100644 --- a/test_util/src/pty.rs +++ b/test_util/src/pty.rs @@ -1,5 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. +use std::borrow::Cow; use std::collections::HashMap; use std::collections::HashSet; use std::io::Read; @@ -35,7 +36,7 @@ impl Pty { read_bytes: Vec::new(), last_index: 0, }; - if args[0] == "repl" && !args.contains(&"--quiet") { + if args.is_empty() || args[0] == "repl" && !args.contains(&"--quiet") { // wait for the repl to start up before writing to it pty.expect("exit using ctrl+d, ctrl+c, or close()"); } @@ -151,6 +152,10 @@ impl Pty { }); } + pub fn all_output(&self) -> Cow<str> { + String::from_utf8_lossy(&self.read_bytes) + } + #[track_caller] fn read_until_with_advancing( &mut self, |