]>
Commit | Line | Data |
---|---|---|
2c00a5a8 XL |
1 | //! Some integration tests to make sure the `SUMMARY.md` parser can deal with |
2 | //! some real-life examples. | |
3 | ||
9fa01778 | 4 | use mdbook::book; |
2c00a5a8 XL |
5 | use std::fs::File; |
6 | use std::io::Read; | |
7 | use std::path::Path; | |
2c00a5a8 XL |
8 | |
9 | macro_rules! summary_md_test { | |
10 | ($name:ident, $filename:expr) => { | |
11 | #[test] | |
12 | fn $name() { | |
13 | env_logger::try_init().ok(); | |
14 | ||
15 | let filename = Path::new(env!("CARGO_MANIFEST_DIR")) | |
16 | .join("tests") | |
17 | .join("summary_md_files") | |
18 | .join($filename); | |
19 | ||
20 | if !filename.exists() { | |
21 | panic!("{} Doesn't exist", filename.display()); | |
22 | } | |
23 | ||
24 | let mut content = String::new(); | |
25 | File::open(&filename) | |
26 | .unwrap() | |
27 | .read_to_string(&mut content) | |
28 | .unwrap(); | |
29 | ||
30 | if let Err(e) = book::parse_summary(&content) { | |
31 | use error_chain::ChainedError; | |
32 | ||
33 | eprintln!("Error parsing {}", filename.display()); | |
34 | eprintln!(); | |
35 | eprintln!("{}", e.display_chain()); | |
36 | panic!(); | |
37 | } | |
38 | } | |
39 | }; | |
40 | } | |
41 | ||
42 | summary_md_test!(rust_by_example, "rust_by_example.md"); | |
43 | summary_md_test!(rust_ffi_guide, "rust_ffi_guide.md"); | |
44 | summary_md_test!(example_book, "example_book.md"); | |
45 | summary_md_test!(the_book_2nd_edition, "the_book-2nd_edition.md"); |