diff --git a/src/site.rs b/src/site.rs index e9ebc81..f375dc3 100644 --- a/src/site.rs +++ b/src/site.rs @@ -302,7 +302,7 @@ impl Site { let output_dir = output_dir.as_ref(); let span = info_span!("Site::render", ?site_dir, ?output_dir); let _enter = span.enter(); - todo!() + todo!("Site::render stub") } } /// Error encountered interacting with a [`Site`] diff --git a/tests/render-structure.rs b/tests/render-structure.rs new file mode 100644 index 0000000..7f15f97 --- /dev/null +++ b/tests/render-structure.rs @@ -0,0 +1,49 @@ +use std::path::PathBuf; + +use color_eyre::eyre::{ensure, Context, Result}; +use stranger_site_gen::site::Site; +use walkdir::WalkDir; + +/// Test that rendering a site produces the correct overall structure, does not test the contents of +/// the generated files +#[test] +fn render_structure() -> Result<()> { + // Get a pair of temporary directories + let tempdir_input = tempfile::tempdir().context("Failed to get temporary directory")?; + let tempdir_input_path = tempdir_input.path(); + let tempdir_output = tempfile::tempdir().context("Failed to get temporary directory")?; + let tempdir_output_path = tempdir_output.path(); + // Generate our site + let mut site = Site::default(); + // Write it out + site.write(tempdir_input_path) + .context("Failed to write out site")?; + // Now render the site to the output path + site.render(tempdir_input_path, tempdir_output_path) + .context("Failed to render site")?; + // Generate out list of known good paths + let mut good_paths: Vec<_> = [ + "index.html", + "posts/new-blog-who-this.html", + "statics/.gitkeep", + "styles/default.css", + "styles/index.css", + "styles/post.css", + ] + .into_iter() + .map(PathBuf::from) + .collect(); + good_paths.sort(); + // Now walk the output directory + let mut output_paths = Vec::new(); + for item in WalkDir::new(tempdir_output_path) { + let item = item.context("Failed walking output")?.into_path(); + if item.is_file() { + output_paths.push(item); + } + } + output_paths.sort(); + // Compare the results + assert_eq!(good_paths, output_paths); + Ok(()) +}