Skip to content

Commit

Permalink
Added integration tests to make sure files are redirected as intended
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael-F-Bryan committed May 26, 2020
1 parent b2d5039 commit 4c23189
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion tests/rendered_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ use mdbook::utils::fs::write_file;
use mdbook::MDBook;
use select::document::Document;
use select::predicate::{Class, Name, Predicate};
use std::collections::HashMap;
use std::ffi::OsStr;
use std::fs;
use std::io::Write;
use std::path::Path;
use std::path::{Path, PathBuf};
use tempfile::Builder as TempFileBuilder;
use walkdir::{DirEntry, WalkDir};

Expand Down Expand Up @@ -511,6 +512,32 @@ fn markdown_options() {
);
}

#[test]
fn redirects_are_emitted_correctly() {
let temp = DummyBook::new().build().unwrap();
let mut md = MDBook::load(temp.path()).unwrap();

// override the "outputs.html.redirect" table
let redirects: HashMap<PathBuf, String> = vec![
(PathBuf::from("index.html"), String::from("overview.html")),
(
PathBuf::from("nexted/page.md"),
String::from("https://rust-lang.org/"),
),
]
.into_iter()
.collect();
md.config.set("output.html.redirect", &redirects).unwrap();

md.build().unwrap();

for (original, redirect) in &redirects {
let redirect_file = md.build_dir_for("html").join(original);
let contents = fs::read_to_string(&redirect_file).unwrap();
assert!(contents.contains(redirect));
}
}

#[cfg(feature = "search")]
mod search {
use crate::dummy_book::DummyBook;
Expand Down

0 comments on commit 4c23189

Please sign in to comment.