From 004002a4db1b43a241d4c875aa0266905f64701c Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 22 Jan 2025 14:37:05 +0100 Subject: [PATCH] Add regression test for `long_description` display --- src/test/fakes.rs | 8 ++++++ src/web/crate_details.rs | 55 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/src/test/fakes.rs b/src/test/fakes.rs index ac7187073..c493f6f62 100644 --- a/src/test/fakes.rs +++ b/src/test/fakes.rs @@ -231,6 +231,13 @@ impl<'a> FakeRelease<'a> { self } + pub(crate) fn target_source(mut self, path: &'a str) -> Self { + if let Some(target) = self.package.targets.first_mut() { + target.src_path = Some(path.into()); + } + self + } + pub(crate) fn no_cargo_toml(mut self) -> Self { self.no_cargo_toml = true; self @@ -503,6 +510,7 @@ impl<'a> FakeRelease<'a> { if let Some(markdown) = self.readme { fs::write(crate_dir.join("README.md"), markdown)?; } + store_files_into(&self.source_files, crate_dir)?; // Many tests rely on the default-target being linux, so it should not // be set to docsrs_metadata::HOST_TARGET, because then tests fail on all diff --git a/src/web/crate_details.rs b/src/web/crate_details.rs index e47c5e929..f8f117911 100644 --- a/src/web/crate_details.rs +++ b/src/web/crate_details.rs @@ -2187,6 +2187,61 @@ mod tests { }); } + #[test] + fn no_readme() { + async_wrapper(|env| async move { + env.fake_release() + .await + .name("dummy") + .version("0.2.0") + .source_file( + "Cargo.toml", + br#"[package] +name = "dummy" +version = "0.2.0" + +[lib] +name = "dummy" +path = "src/lib.rs" +"#, + ) + .source_file( + "src/lib.rs", + b"//! # Crate-level docs +//! +//! ``` +//! let x = 21; +//! ``` +", + ) + .target_source("src/lib.rs") + .create() + .await?; + + let web = env.web_app().await; + let response = web.get("/crate/dummy/0.2.0").await?; + assert!(response.status().is_success()); + + let dom = kuchikiki::parse_html().one(response.text().await?); + dom.select_first("#main").expect("not main crate docs"); + // First we check that the crate-level docs have been rendered as expected. + assert_eq!( + dom.select_first("#main h1") + .expect("no h1 found") + .text_contents(), + "Crate-level docs" + ); + // Then we check that by default, the language used for highlighting is rust. + assert_eq!( + dom.select_first("#main pre .syntax-source.syntax-rust") + .expect("no rust code block found") + .text_contents(), + "let x = 21;\n" + ); + Ok(()) + }); + } + #[test] fn test_crate_name_with_other_uri_chars() { async_wrapper(|env| async move {