Skip to content

Commit

Permalink
Add regression test for long_description display
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez authored and syphar committed Jan 22, 2025
1 parent 5fadfec commit 29a0e81
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/test/fakes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
55 changes: 55 additions & 0 deletions src/web/crate_details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 29a0e81

Please sign in to comment.