Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for rustdoc-map generation when using sparse registries #11403

Merged
merged 1 commit into from
Nov 29, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions tests/testsuite/rustdoc_extern_html.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,3 +342,85 @@ fn rebuilds_when_changing() {
)
.run();
}

#[cargo_test(nightly, reason = "--extern-html-root-url is unstable")]
fn alt_sparse_registry() {
// Supports other registry names.

registry::init();
let _registry = registry::RegistryBuilder::new()
.http_index()
.alternative()
.build();

Package::new("bar", "1.0.0")
.alternative(true)
.file(
"src/lib.rs",
r#"
extern crate baz;
pub struct Queen;
pub use baz::King;
"#,
)
.registry_dep("baz", "1.0")
.publish();
Package::new("baz", "1.0.0")
.alternative(true)
.file("src/lib.rs", "pub struct King;")
.publish();
Package::new("grimm", "1.0.0")
.file("src/lib.rs", "pub struct Gold;")
.publish();

let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.1.0"
edition = "2018"

[dependencies]
bar = { version = "1.0", registry="alternative" }
grimm = "1.0"
"#,
)
.file(
"src/lib.rs",
r#"
pub fn queen() -> bar::Queen { bar::Queen }
pub fn king() -> bar::King { bar::King }
pub fn gold() -> grimm::Gold { grimm::Gold }
"#,
)
.file(
".cargo/config",
r#"
[doc.extern-map.registries]
alternative = "https://example.com/{pkg_name}/{version}/"
crates-io = "https://docs.rs/"
"#,
)
.build();
p.cargo("doc -v --no-deps -Zrustdoc-map -Zsparse-registry")
.masquerade_as_nightly_cargo(&["rustdoc-map", "sparse-registry"])
.with_stderr_contains(
"[RUNNING] `rustdoc [..]--crate-name foo \
[..]bar=https://example.com/bar/1.0.0/[..]grimm=https://docs.rs/grimm/1.0.0/[..]",
)
.run();
let queen = p.read_file("target/doc/foo/fn.queen.html");
assert!(queen.contains(r#"href="https://example.com/bar/1.0.0/bar/struct.Queen.html""#));
// The king example fails to link. Rustdoc seems to want the origin crate
// name (baz) for re-exports. There are many issues in the issue tracker
// for rustdoc re-exports, so I'm not sure, but I think this is maybe a
// rustdoc issue. Alternatively, Cargo could provide mappings for all
// transitive dependencies to fix this.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be, but let's move on first :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah my bad, that was a comment that is in the test that I adapted this from (you can see it in the original test here:

// name (baz) for re-exports. There are many issues in the issue tracker
)

let king = p.read_file("target/doc/foo/fn.king.html");
assert!(king.contains(r#"-> King"#));

let gold = p.read_file("target/doc/foo/fn.gold.html");
assert!(gold.contains(r#"href="https://docs.rs/grimm/1.0.0/grimm/struct.Gold.html""#));
}