2017-12-11 01:26:11 +00:00
|
|
|
//! Some integration tests to make sure the `SUMMARY.md` parser can deal with
|
|
|
|
//! some real-life examples.
|
|
|
|
|
|
|
|
extern crate env_logger;
|
2017-12-11 04:17:20 +00:00
|
|
|
extern crate error_chain;
|
2017-12-11 01:26:11 +00:00
|
|
|
extern crate mdbook;
|
|
|
|
|
|
|
|
use std::fs::File;
|
|
|
|
use std::io::Read;
|
|
|
|
use std::path::Path;
|
|
|
|
use mdbook::book;
|
|
|
|
|
|
|
|
macro_rules! summary_md_test {
|
|
|
|
($name:ident, $filename:expr) => {
|
|
|
|
#[test]
|
|
|
|
fn $name() {
|
2017-12-30 10:43:46 +00:00
|
|
|
env_logger::try_init().ok();
|
2017-12-11 01:26:11 +00:00
|
|
|
|
|
|
|
let filename = Path::new(env!("CARGO_MANIFEST_DIR"))
|
|
|
|
.join("tests")
|
|
|
|
.join("summary_md_files")
|
|
|
|
.join($filename);
|
|
|
|
|
|
|
|
if !filename.exists() {
|
|
|
|
panic!("{} Doesn't exist", filename.display());
|
|
|
|
}
|
|
|
|
|
|
|
|
let mut content = String::new();
|
|
|
|
File::open(&filename)
|
|
|
|
.unwrap()
|
|
|
|
.read_to_string(&mut content)
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
if let Err(e) = book::parse_summary(&content) {
|
|
|
|
use error_chain::ChainedError;
|
|
|
|
|
2017-12-11 06:20:05 +00:00
|
|
|
eprintln!("Error parsing {}", filename.display());
|
2017-12-11 01:26:11 +00:00
|
|
|
eprintln!();
|
|
|
|
eprintln!("{}", e.display_chain());
|
|
|
|
panic!();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
summary_md_test!(rust_by_example, "rust_by_example.md");
|
|
|
|
summary_md_test!(rust_ffi_guide, "rust_ffi_guide.md");
|
|
|
|
summary_md_test!(example_book, "example_book.md");
|
2017-12-11 04:17:20 +00:00
|
|
|
summary_md_test!(the_book_2nd_edition, "the_book-2nd_edition.md");
|