2
2
3
3
use mdbook:: book:: BookBuilder ;
4
4
use mdbook:: MDBook ;
5
- use snapbox:: IntoData ;
5
+ use snapbox:: { cmd :: Command , IntoData } ;
6
6
use std:: collections:: BTreeMap ;
7
7
use std:: path:: { Path , PathBuf } ;
8
- use std:: process:: Command ;
9
8
use std:: sync:: atomic:: { AtomicU32 , Ordering } ;
10
9
11
10
/// Test number used for generating unique temp directory names.
@@ -227,6 +226,7 @@ impl BookTest {
227
226
expect_status : StatusCode :: Success ,
228
227
expect_stderr_data : None ,
229
228
expect_stdout_data : None ,
229
+ stdin_data : None ,
230
230
} ;
231
231
f ( & mut cmd) ;
232
232
cmd. run ( ) ;
@@ -272,6 +272,7 @@ pub struct BookCommand {
272
272
expect_status : StatusCode ,
273
273
expect_stderr_data : Option < snapbox:: Data > ,
274
274
expect_stdout_data : Option < snapbox:: Data > ,
275
+ stdin_data : Option < snapbox:: Data > ,
275
276
}
276
277
277
278
impl BookCommand {
@@ -299,6 +300,12 @@ impl BookCommand {
299
300
self
300
301
}
301
302
303
+ /// Sets the stdin data to use when running the command.
304
+ pub fn stdin ( & mut self , input : impl snapbox:: IntoData ) -> & mut Self {
305
+ self . stdin_data = Some ( input. into_data ( ) ) ;
306
+ self
307
+ }
308
+
302
309
/// Adds arguments to the command to run.
303
310
pub fn args ( & mut self , args : & [ & str ] ) -> & mut Self {
304
311
self . args . extend ( args. into_iter ( ) . map ( |t| t. to_string ( ) ) ) ;
@@ -314,7 +321,8 @@ impl BookCommand {
314
321
/// Runs the command, and verifies the output.
315
322
fn run ( & mut self ) {
316
323
let mut cmd = Command :: new ( env ! ( "CARGO_BIN_EXE_mdbook" ) ) ;
317
- cmd. current_dir ( & self . dir )
324
+ cmd = cmd
325
+ . current_dir ( & self . dir )
318
326
. args ( & self . args )
319
327
. env_remove ( "RUST_LOG" )
320
328
// Don't read the system git config which is out of our control.
@@ -328,11 +336,15 @@ impl BookCommand {
328
336
329
337
for ( k, v) in & self . env {
330
338
match v {
331
- Some ( v) => cmd. env ( k, v) ,
332
- None => cmd. env_remove ( k) ,
339
+ Some ( v) => cmd = cmd . env ( k, v) ,
340
+ None => cmd = cmd . env_remove ( k) ,
333
341
} ;
334
342
}
335
343
344
+ if let Some ( stdin_data) = & self . stdin_data {
345
+ cmd = cmd. stdin ( stdin_data) ;
346
+ }
347
+
336
348
let output = cmd. output ( ) . expect ( "mdbook should be runnable" ) ;
337
349
let stdout = std:: str:: from_utf8 ( & output. stdout ) . expect ( "stdout is not utf8" ) ;
338
350
let stderr = std:: str:: from_utf8 ( & output. stderr ) . expect ( "stderr is not utf8" ) ;
0 commit comments