//! Tests for include preprocessor. use crate::prelude::*; // Basic test for #include. #[test] fn include() { BookTest::from_dir("includes/all_includes") .check_main_file( "book/includes.html", str![[r##"
This is a sample include.
"##]], ) .check_main_file( "book/relative/includes.html", str![[r##"This is a sample include.
"##]], ); } // Checks for anchored includes. #[test] fn anchored_include() { BookTest::from_dir("includes/all_includes").check_main_file( "book/anchors.html", str![[r##""##]], ); } // Checks behavior of recursive include. #[test] fn recursive_include() { BookTest::from_dir("includes/all_includes") .run("build", |cmd| { cmd.expect_stderr(str![[r#" [TIMESTAMP] [INFO] (mdbook_driver::mdbook): Book building has started [TIMESTAMP] [ERROR] (mdbook_driver::builtin_preprocessors::links): Stack depth exceeded in recursive.md. Check for cyclic includes [TIMESTAMP] [INFO] (mdbook_driver::mdbook): Running the html backend [TIMESTAMP] [INFO] (mdbook_html::html_handlebars::hbs_renderer): HTML book written to `[ROOT]/book` "#]]); }) .check_main_file( "book/recursive.html", str![[r#"#![allow(unused)] fn main() { let x = 1; }
Around the world, around the world Around the world, around the world Around the world, around the world Around the world, around the world Around the world, around the world Around the world, around the world Around the world, around the world Around the world, around the world Around the world, around the world Around the world, around the world Around the world, around the world
"#]], ); } // Checks the behavior of `{{#playground}}` include. #[test] fn playground_include() { BookTest::from_dir("includes/all_includes") .check_main_file("book/playground.html", str![[r##""##]]); } // Checks the behavior of `{{#rustdoc_include}}`. #[test] fn rustdoc_include() { BookTest::from_dir("includes/all_includes") .check_main_file("book/rustdoc.html", str![[r##"fn main() { println!("Hello World!"); // You can even hide lines! :D println!("I am hidden! Expand the code snippet to see me"); }
fn some_function() { println!("some function"); } fn main() { some_function(); }
"##]]); }fn some_other_function() { println!("unused anchor"); } fn main() { some_other_function(); }