Skip to content

Commit 5d2914a

Browse files
committed
run-make-support: add support for passing stdin bytes in rustdoc
1 parent e27af29 commit 5d2914a

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/tools/run-make-support/src/rustdoc.rs

+22-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::env;
2+
use std::io::Write;
23
use std::path::Path;
3-
use std::process::{Command, Output};
4+
use std::process::{Command, Output, Stdio};
45

56
use crate::{handle_failed_output, set_host_rpath};
67

@@ -62,6 +63,26 @@ impl Rustdoc {
6263
self
6364
}
6465

66+
/// Run the constructed command and assert that it is successfully run.
67+
#[track_caller]
68+
pub fn run_with_stdin<I: AsRef<[u8]>>(&mut self, input: I) -> ::std::process::Output {
69+
let caller_location = ::std::panic::Location::caller();
70+
let caller_line_number = caller_location.line();
71+
72+
self.cmd.stdin(Stdio::piped());
73+
let mut child = self.cmd.spawn().unwrap();
74+
let mut stdin = child.stdin.take().unwrap();
75+
stdin.write_all(input.as_ref()).unwrap();
76+
drop(stdin);
77+
78+
let output = child.wait_with_output().unwrap();
79+
80+
if !output.status.success() {
81+
handle_failed_output(&self.cmd, output, caller_line_number);
82+
}
83+
output
84+
}
85+
6586
#[track_caller]
6687
pub fn run_fail_assert_exit_code(&mut self, code: i32) -> Output {
6788
let caller_location = std::panic::Location::caller();

0 commit comments

Comments
 (0)