From ebc01dbb714e76e5fe8be09cb162d0ec92d23577 Mon Sep 17 00:00:00 2001 From: Michael-F-Bryan Date: Sat, 30 May 2020 04:15:24 +0800 Subject: [PATCH] Updated the test to follow our docs --- tests/rendered_output.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tests/rendered_output.rs b/tests/rendered_output.rs index 56615703..db0badd7 100644 --- a/tests/rendered_output.rs +++ b/tests/rendered_output.rs @@ -16,7 +16,7 @@ use std::collections::HashMap; use std::ffi::OsStr; use std::fs; use std::io::Write; -use std::path::{Path, PathBuf}; +use std::path::{Component, Path, PathBuf}; use tempfile::Builder as TempFileBuilder; use walkdir::{DirEntry, WalkDir}; @@ -532,12 +532,22 @@ fn redirects_are_emitted_correctly() { md.build().unwrap(); for (original, redirect) in &redirects { - let redirect_file = md.build_dir_for("html").join(original); + let mut redirect_file = md.build_dir_for("html"); + // append everything except the bits that make it absolute + // (e.g. "/" or "C:\") + redirect_file.extend(remove_absolute_components(&original)); let contents = fs::read_to_string(&redirect_file).unwrap(); assert!(contents.contains(redirect)); } } +fn remove_absolute_components(path: &Path) -> impl Iterator + '_ { + path.components().skip_while(|c| match c { + Component::Prefix(_) | Component::RootDir => true, + _ => false, + }) +} + #[cfg(feature = "search")] mod search { use crate::dummy_book::DummyBook;