summaryrefslogtreecommitdiff
path: root/tests/util
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2024-05-28 14:58:43 -0400
committerGitHub <noreply@github.com>2024-05-28 14:58:43 -0400
commit448fe67b7a2142f62332b651f9d215534dceb1f5 (patch)
tree3cfc763f39bf275a537e6228767b3e43866f5d0f /tests/util
parentcd8f5f53f7616e4c74de0f1ff5eadd6ef024118a (diff)
feat(vendor): support modifying remote files in vendor folder without checksum errors (#23979)
Includes: * https://github.com/denoland/deno_graph/pull/486 * https://github.com/denoland/deno_graph/pull/488 * https://github.com/denoland/deno_lockfile/pull/25 * https://github.com/denoland/deno_lockfile/pull/22 * https://github.com/denoland/deno_graph/pull/483 * https://github.com/denoland/deno_graph/pull/470
Diffstat (limited to 'tests/util')
-rw-r--r--tests/util/server/src/builders.rs51
1 files changed, 43 insertions, 8 deletions
diff --git a/tests/util/server/src/builders.rs b/tests/util/server/src/builders.rs
index bf5de64dc..bd2d02f3f 100644
--- a/tests/util/server/src/builders.rs
+++ b/tests/util/server/src/builders.rs
@@ -387,6 +387,7 @@ pub struct TestCommandBuilder {
args_text: String,
args_vec: Vec<String>,
split_output: bool,
+ debug_output: bool,
}
impl TestCommandBuilder {
@@ -406,6 +407,7 @@ impl TestCommandBuilder {
command_name: "deno".to_string(),
args_text: "".to_string(),
args_vec: Default::default(),
+ debug_output: false,
}
}
@@ -482,6 +484,16 @@ impl TestCommandBuilder {
self
}
+ /// Set this to enable streaming the output of the command to stderr.
+ ///
+ /// Not deprecated, this is just here so you don't accidentally
+ /// commit code with this enabled.
+ #[deprecated]
+ pub fn debug_output(mut self) -> Self {
+ self.debug_output = true;
+ self
+ }
+
pub fn stdin<T: Into<Stdio>>(mut self, cfg: T) -> Self {
self.stdin = Some(StdioContainer::new(cfg.into()));
self
@@ -606,10 +618,27 @@ impl TestCommandBuilder {
}
pub fn run(&self) -> TestCommandOutput {
- fn read_pipe_to_string(mut pipe: os_pipe::PipeReader) -> String {
- let mut output = String::new();
- pipe.read_to_string(&mut output).unwrap();
- output
+ fn read_pipe_to_string(
+ mut pipe: os_pipe::PipeReader,
+ output_to_stderr: bool,
+ ) -> String {
+ if output_to_stderr {
+ let mut buffer = vec![0; 512];
+ let mut final_data = Vec::new();
+ loop {
+ let size = pipe.read(&mut buffer).unwrap();
+ if size == 0 {
+ break;
+ }
+ final_data.extend(&buffer[..size]);
+ std::io::stderr().write_all(&buffer[..size]).unwrap();
+ }
+ String::from_utf8_lossy(&final_data).to_string()
+ } else {
+ let mut output = String::new();
+ pipe.read_to_string(&mut output).unwrap();
+ output
+ }
}
fn sanitize_output(text: String, args: &[OsString]) -> String {
@@ -633,11 +662,16 @@ impl TestCommandBuilder {
let (stderr_reader, stderr_writer) = pipe().unwrap();
command.stdout(stdout_writer);
command.stderr(stderr_writer);
+ let debug_output = self.debug_output;
(
None,
Some((
- std::thread::spawn(move || read_pipe_to_string(stdout_reader)),
- std::thread::spawn(move || read_pipe_to_string(stderr_reader)),
+ std::thread::spawn(move || {
+ read_pipe_to_string(stdout_reader, debug_output)
+ }),
+ std::thread::spawn(move || {
+ read_pipe_to_string(stderr_reader, debug_output)
+ }),
)),
)
} else {
@@ -660,8 +694,9 @@ impl TestCommandBuilder {
// and dropping it closes them.
drop(command);
- let combined = combined_reader
- .map(|pipe| sanitize_output(read_pipe_to_string(pipe), &args));
+ let combined = combined_reader.map(|pipe| {
+ sanitize_output(read_pipe_to_string(pipe, self.debug_output), &args)
+ });
let status = process.wait().unwrap();
let std_out_err = std_out_err_handle.map(|(stdout, stderr)| {