@@ -227,6 +227,7 @@ impl BookTest {
227
227
expect_status : StatusCode :: Success ,
228
228
expect_stderr_data : None ,
229
229
expect_stdout_data : None ,
230
+ debug : None ,
230
231
} ;
231
232
f ( & mut cmd) ;
232
233
cmd. run ( ) ;
@@ -272,6 +273,7 @@ pub struct BookCommand {
272
273
expect_status : StatusCode ,
273
274
expect_stderr_data : Option < snapbox:: Data > ,
274
275
expect_stdout_data : Option < snapbox:: Data > ,
276
+ debug : Option < String > ,
275
277
}
276
278
277
279
impl BookCommand {
@@ -311,6 +313,21 @@ impl BookCommand {
311
313
self
312
314
}
313
315
316
+ /// Use this to debug a command.
317
+ ///
318
+ /// Pass the value that you would normally pass to `RUST_LOG`, and this
319
+ /// will enable logging, print the command that runs and its output.
320
+ ///
321
+ /// This will fail if you use it in CI.
322
+ #[ allow( unused) ]
323
+ pub fn debug ( & mut self , value : & str ) -> & mut Self {
324
+ if std:: env:: var_os ( "CI" ) . is_some ( ) {
325
+ panic ! ( "debug is not allowed on CI" ) ;
326
+ }
327
+ self . debug = Some ( value. into ( ) ) ;
328
+ self
329
+ }
330
+
314
331
/// Runs the command, and verifies the output.
315
332
fn run ( & mut self ) {
316
333
let mut cmd = Command :: new ( env ! ( "CARGO_BIN_EXE_mdbook" ) ) ;
@@ -326,13 +343,20 @@ impl BookCommand {
326
343
. env_remove ( "GIT_COMMITTER_EMAIL" )
327
344
. env_remove ( "GIT_COMMITTER_NAME" ) ;
328
345
346
+ if let Some ( debug) = & self . debug {
347
+ cmd. env ( "RUST_LOG" , debug) ;
348
+ }
349
+
329
350
for ( k, v) in & self . env {
330
351
match v {
331
352
Some ( v) => cmd. env ( k, v) ,
332
353
None => cmd. env_remove ( k) ,
333
354
} ;
334
355
}
335
356
357
+ if self . debug . is_some ( ) {
358
+ eprintln ! ( "running {cmd:#?}" ) ;
359
+ }
336
360
let output = cmd. output ( ) . expect ( "mdbook should be runnable" ) ;
337
361
let stdout = std:: str:: from_utf8 ( & output. stdout ) . expect ( "stdout is not utf8" ) ;
338
362
let stderr = std:: str:: from_utf8 ( & output. stderr ) . expect ( "stderr is not utf8" ) ;
@@ -353,6 +377,9 @@ impl BookCommand {
353
377
} ,
354
378
_ => { }
355
379
}
380
+ if self . debug . is_some ( ) {
381
+ eprintln ! ( "{}" , render_output( ) ) ;
382
+ }
356
383
self . expect_status = StatusCode :: Success ; // Reset to default.
357
384
if let Some ( expect_stderr_data) = & self . expect_stderr_data {
358
385
if let Err ( e) = self . assert . try_eq (
0 commit comments