From 4c2318922f861ac4a452a50ab202d2bb7eb1d35d Mon Sep 17 00:00:00 2001 From: Michael-F-Bryan Date: Wed, 27 May 2020 02:35:15 +0800 Subject: [PATCH] Added integration tests to make sure files are redirected as intended --- tests/rendered_output.rs | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/tests/rendered_output.rs b/tests/rendered_output.rs index 82b07045..3b76cbd2 100644 --- a/tests/rendered_output.rs +++ b/tests/rendered_output.rs @@ -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}; @@ -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 = 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;