mirror of
https://github.com/rust-lang/mdBook
synced 2024-12-15 07:12:35 +00:00
fd7e8d1b7b
* Added a mechanism for creating alternate backends * Added a CmdRenderer and the ability to have multiple renderers * Made MDBook::load() autodetect renderers * Added a couple methods to RenderContext * Converted RenderContext.version to a String * Made sure all alternate renderers are invoked as `mdbook-*` * Factored out the logic for determining which renderer to use * Added tests for renderer detection * Made it so `mdbook test` works on the book-example again * Updated the "For Developers" docs * Removed `[output.epub]` from the example book's book.toml * Added a bit more info on how backends should work * Added a `destination` key to the RenderContext * Altered how we wait for an alternate backend to finish * Refactored the Renderer trait to not use MDBook and moved livereload to the template * Moved info for developers out of the book.toml format chapter * MOAR docs * MDBook::build() no longer takes &mut self * Replaced a bunch of println!()'s with proper log macros * Cleaned up the build() method and backend discovery * Added a couple notes and doc-comments * Found a race condition when backends exit really quickly * Added support for backends with arguments * Fixed a funny doc-comment
70 lines
1.8 KiB
Rust
70 lines
1.8 KiB
Rust
extern crate mdbook;
|
|
extern crate tempdir;
|
|
|
|
use std::path::PathBuf;
|
|
use std::fs;
|
|
use mdbook::MDBook;
|
|
use mdbook::config::Config;
|
|
use tempdir::TempDir;
|
|
|
|
|
|
/// Run `mdbook init` in an empty directory and make sure the default files
|
|
/// are created.
|
|
#[test]
|
|
fn base_mdbook_init_should_create_default_content() {
|
|
let created_files = vec!["book", "src", "src/SUMMARY.md", "src/chapter_1.md"];
|
|
|
|
let temp = TempDir::new("mdbook").unwrap();
|
|
for file in &created_files {
|
|
assert!(!temp.path().join(file).exists());
|
|
}
|
|
|
|
MDBook::init(temp.path()).build().unwrap();
|
|
|
|
for file in &created_files {
|
|
let target = temp.path().join(file);
|
|
println!("{}", target.display());
|
|
assert!(target.exists(), "{} doesn't exist", file);
|
|
}
|
|
}
|
|
|
|
/// Set some custom arguments for where to place the source and destination
|
|
/// files, then call `mdbook init`.
|
|
#[test]
|
|
fn run_mdbook_init_with_custom_book_and_src_locations() {
|
|
let created_files = vec!["out", "in", "in/SUMMARY.md", "in/chapter_1.md"];
|
|
|
|
let temp = TempDir::new("mdbook").unwrap();
|
|
for file in &created_files {
|
|
assert!(
|
|
!temp.path().join(file).exists(),
|
|
"{} shouldn't exist yet!",
|
|
file
|
|
);
|
|
}
|
|
|
|
let mut cfg = Config::default();
|
|
cfg.book.src = PathBuf::from("in");
|
|
cfg.build.build_dir = PathBuf::from("out");
|
|
|
|
MDBook::init(temp.path()).with_config(cfg).build().unwrap();
|
|
|
|
for file in &created_files {
|
|
let target = temp.path().join(file);
|
|
assert!(
|
|
target.exists(),
|
|
"{} should have been created by `mdbook init`",
|
|
file
|
|
);
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn book_toml_isnt_required() {
|
|
let temp = TempDir::new("mdbook").unwrap();
|
|
let md = MDBook::init(temp.path()).build().unwrap();
|
|
|
|
let _ = fs::remove_file(temp.path().join("book.toml"));
|
|
|
|
md.build().unwrap();
|
|
}
|