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