diff --git a/components/site/tests/common.rs b/components/site/tests/common.rs index f5caaf182..267bdf801 100644 --- a/components/site/tests/common.rs +++ b/components/site/tests/common.rs @@ -22,7 +22,7 @@ macro_rules! file_exists { #[macro_export] macro_rules! file_contains { - ($root: expr, $path: expr, $text: expr) => {{ + (@impl $root: expr, $path: expr) => {{ use std::io::prelude::*; let mut path = $root.clone(); for component in $path.split('/') { @@ -31,11 +31,24 @@ macro_rules! file_contains { let mut file = std::fs::File::open(&path).expect(&format!("Failed to open {:?}", $path)); let mut s = String::new(); file.read_to_string(&mut s).unwrap(); - println!("{}", s); + println!("{path:?} {s}"); + s + }}; + ($root: expr, $path: expr, $text: expr) => {{ + let s = file_contains!(@impl $root, $path); s.contains($text) }}; } +#[macro_export] +macro_rules! file_contains_regex { + ($root: expr, $path: expr, $pat: expr) => {{ + let s = file_contains!(@impl $root, $path); + let re = libs::regex::Regex::new($pat).unwrap(); + re.is_match(&s) + }}; +} + /// We return the tmpdir otherwise it would get out of scope and be deleted /// The tests can ignore it if they dont need it by prefixing it with a `_` pub fn build_site(name: &str) -> (Site, TempDir, PathBuf) { diff --git a/components/site/tests/site.rs b/components/site/tests/site.rs index bf0811e15..a5b5446ce 100644 --- a/components/site/tests/site.rs +++ b/components/site/tests/site.rs @@ -21,7 +21,7 @@ fn can_parse_site() { let library = site.library.read().unwrap(); // Correct number of pages (sections do not count as pages, draft are ignored) - assert_eq!(library.pages.len(), 36); + assert_eq!(library.pages.len(), 37); let posts_path = path.join("content").join("posts"); // Make sure the page with a url doesn't have any sections @@ -44,7 +44,7 @@ fn can_parse_site() { let posts_section = library.sections.get(&posts_path.join("_index.md")).unwrap(); assert_eq!(posts_section.subsections.len(), 2); - assert_eq!(posts_section.pages.len(), 10); // 11 with 1 draft == 10 + assert_eq!(posts_section.pages.len(), 12); // 13 with 1 draft == 12 assert_eq!(posts_section.ancestors, vec![index_section.file.relative.clone()]); // Make sure we remove all the pwd + content from the sections @@ -155,6 +155,47 @@ fn can_build_site_without_live_reload() { "posts/tutorials/devops/nix.md" )); + assert!(file_exists!(public, "posts/access-render/index.html")); + + // render = false pages can still be accessed directly + assert!(file_contains!( + public, + "posts/access-render/index.html", + "Path of unrendered page: /posts/render/" + )); + // render = false pages can still be accessed through sections + assert!(file_contains_regex!( + public, + "posts/access-render/index.html", + r#"Pages in section with unrendered page: