@@ -14,6 +14,7 @@ pub use self::book::{load_book, Book, BookItem, BookItems, Chapter};
14
14
pub use self :: init:: BookBuilder ;
15
15
pub use self :: summary:: { parse_summary, Link , SectionNumber , Summary , SummaryItem } ;
16
16
17
+ use log:: { debug, error, info, log_enabled, trace, warn} ;
17
18
use std:: io:: Write ;
18
19
use std:: path:: PathBuf ;
19
20
use std:: process:: Command ;
@@ -246,6 +247,13 @@ impl MDBook {
246
247
247
248
/// Run `rustdoc` tests on the book, linking against the provided libraries.
248
249
pub fn test ( & mut self , library_paths : Vec < & str > ) -> Result < ( ) > {
250
+ // test_chapter with chapter:None will run all tests.
251
+ self . test_chapter ( library_paths, None )
252
+ }
253
+
254
+ /// Run `rustdoc` tests on a specific chapter of the book, linking against the provided libraries.
255
+ /// If `chapter` is `None`, all tests will be run.
256
+ pub fn test_chapter ( & mut self , library_paths : Vec < & str > , chapter : Option < & str > ) -> Result < ( ) > {
249
257
let library_args: Vec < & str > = ( 0 ..library_paths. len ( ) )
250
258
. map ( |_| "-L" )
251
259
. zip ( library_paths. into_iter ( ) )
@@ -254,6 +262,8 @@ impl MDBook {
254
262
255
263
let temp_dir = TempFileBuilder :: new ( ) . prefix ( "mdbook-" ) . tempdir ( ) ?;
256
264
265
+ let mut chapter_found = false ;
266
+
257
267
// FIXME: Is "test" the proper renderer name to use here?
258
268
let preprocess_context =
259
269
PreprocessorContext :: new ( self . root . clone ( ) , self . config . clone ( ) , "test" . to_string ( ) ) ;
@@ -270,8 +280,16 @@ impl MDBook {
270
280
_ => continue ,
271
281
} ;
272
282
273
- let path = self . source_dir ( ) . join ( & chapter_path) ;
274
- info ! ( "Testing file: {:?}" , path) ;
283
+ if let Some ( chapter) = chapter {
284
+ if ch. name != chapter && chapter_path. to_str ( ) != Some ( chapter) {
285
+ if chapter == "?" {
286
+ info ! ( "Skipping chapter '{}'..." , ch. name) ;
287
+ }
288
+ continue ;
289
+ }
290
+ }
291
+ chapter_found = true ;
292
+ info ! ( "Testing chapter '{}': {:?}" , ch. name, chapter_path) ;
275
293
276
294
// write preprocessed file to tempdir
277
295
let path = temp_dir. path ( ) . join ( & chapter_path) ;
@@ -311,6 +329,11 @@ impl MDBook {
311
329
if failed {
312
330
bail ! ( "One or more tests failed" ) ;
313
331
}
332
+ if let Some ( chapter) = chapter {
333
+ if !chapter_found {
334
+ bail ! ( "Chapter not found: {}" , chapter) ;
335
+ }
336
+ }
314
337
Ok ( ( ) )
315
338
}
316
339
0 commit comments