@@ -15,8 +15,9 @@ pub use self::init::BookBuilder;
15
15
pub use self :: summary:: { parse_summary, Link , SectionNumber , Summary , SummaryItem } ;
16
16
17
17
use log:: { debug, error, info, log_enabled, trace, warn} ;
18
- use std:: io:: Write ;
19
- use std:: path:: PathBuf ;
18
+ use std:: ffi:: OsString ;
19
+ use std:: io:: { IsTerminal , Write } ;
20
+ use std:: path:: { Path , PathBuf } ;
20
21
use std:: process:: Command ;
21
22
use tempfile:: Builder as TempFileBuilder ;
22
23
use toml:: Value ;
@@ -264,10 +265,18 @@ impl MDBook {
264
265
/// Run `rustdoc` tests on a specific chapter of the book, linking against the provided libraries.
265
266
/// If `chapter` is `None`, all tests will be run.
266
267
pub fn test_chapter ( & mut self , library_paths : Vec < & str > , chapter : Option < & str > ) -> Result < ( ) > {
267
- let library_args: Vec < & str > = ( 0 ..library_paths. len ( ) )
268
- . map ( |_| "-L" )
269
- . zip ( library_paths. into_iter ( ) )
270
- . flat_map ( |x| vec ! [ x. 0 , x. 1 ] )
268
+ let cwd = std:: env:: current_dir ( ) ?;
269
+ let library_args: Vec < OsString > = library_paths
270
+ . into_iter ( )
271
+ . flat_map ( |path| {
272
+ let path = Path :: new ( path) ;
273
+ let path = if path. is_relative ( ) {
274
+ cwd. join ( path) . into_os_string ( )
275
+ } else {
276
+ path. to_path_buf ( ) . into_os_string ( )
277
+ } ;
278
+ [ OsString :: from ( "-L" ) , path]
279
+ } )
271
280
. collect ( ) ;
272
281
273
282
let temp_dir = TempFileBuilder :: new ( ) . prefix ( "mdbook-" ) . tempdir ( ) ?;
@@ -294,6 +303,7 @@ impl MDBook {
294
303
. collect ( ) ;
295
304
let ( book, _) = self . preprocess_book ( & TestRenderer ) ?;
296
305
306
+ let color_output = std:: io:: stderr ( ) . is_terminal ( ) ;
297
307
let mut failed = false ;
298
308
for item in book. iter ( ) {
299
309
if let BookItem :: Chapter ( ref ch) = * item {
@@ -319,7 +329,10 @@ impl MDBook {
319
329
tmpf. write_all ( ch. content . as_bytes ( ) ) ?;
320
330
321
331
let mut cmd = Command :: new ( "rustdoc" ) ;
322
- cmd. arg ( & path) . arg ( "--test" ) . args ( & library_args) ;
332
+ cmd. current_dir ( temp_dir. path ( ) )
333
+ . arg ( & chapter_path)
334
+ . arg ( "--test" )
335
+ . args ( & library_args) ;
323
336
324
337
if let Some ( edition) = self . config . rust . edition {
325
338
match edition {
@@ -335,6 +348,10 @@ impl MDBook {
335
348
}
336
349
}
337
350
351
+ if color_output {
352
+ cmd. args ( & [ "--color" , "always" ] ) ;
353
+ }
354
+
338
355
debug ! ( "running {:?}" , cmd) ;
339
356
let output = cmd. output ( ) ?;
340
357
0 commit comments