mirror of
https://github.com/rust-lang/cargo.git
synced 2025-10-01 11:30:39 +00:00
Remove outdated check on scrape units, add test for doc = false
This commit is contained in:
parent
125c6b4ccd
commit
968caae025
@ -387,15 +387,6 @@ pub fn create_bcx<'a, 'cfg>(
|
|||||||
has_dev_units,
|
has_dev_units,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// The set of scraped targets should be a strict subset of the set of documented targets,
|
|
||||||
// except in the special case of examples targets.
|
|
||||||
if cfg!(debug_assertions) {
|
|
||||||
let valid_targets = units.iter().map(|u| &u.target).collect::<HashSet<_>>();
|
|
||||||
for unit in &all_units {
|
|
||||||
assert!(unit.target.is_example() || valid_targets.contains(&unit.target));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let valid_units = all_units
|
let valid_units = all_units
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter(|unit| {
|
.filter(|unit| {
|
||||||
|
@ -196,7 +196,7 @@ fn configure_target() {
|
|||||||
)
|
)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
p.cargo("doc --lib --bins -Zunstable-options -Zrustdoc-scrape-examples")
|
p.cargo("doc -Zunstable-options -Zrustdoc-scrape-examples")
|
||||||
.masquerade_as_nightly_cargo(&["rustdoc-scrape-examples"])
|
.masquerade_as_nightly_cargo(&["rustdoc-scrape-examples"])
|
||||||
.run();
|
.run();
|
||||||
|
|
||||||
@ -519,3 +519,64 @@ fn use_dev_deps_if_explicitly_enabled() {
|
|||||||
)
|
)
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cargo_test(nightly, reason = "rustdoc scrape examples flags are unstable")]
|
||||||
|
fn only_scrape_documented_targets() {
|
||||||
|
// package bar has doc = false and should not be eligible for documtation.
|
||||||
|
let run_with_config = |config: &str, should_scrape: bool| {
|
||||||
|
let p = project()
|
||||||
|
.file(
|
||||||
|
"Cargo.toml",
|
||||||
|
&format!(
|
||||||
|
r#"
|
||||||
|
[package]
|
||||||
|
name = "bar"
|
||||||
|
version = "0.0.1"
|
||||||
|
authors = []
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
{config}
|
||||||
|
|
||||||
|
[workspace]
|
||||||
|
members = ["foo"]
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
foo = {{ path = "foo" }}
|
||||||
|
"#
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.file("src/lib.rs", "pub fn bar() { foo::foo(); }")
|
||||||
|
.file(
|
||||||
|
"foo/Cargo.toml",
|
||||||
|
r#"
|
||||||
|
[package]
|
||||||
|
name = "foo"
|
||||||
|
version = "0.0.1"
|
||||||
|
authors = []
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
.file("foo/src/lib.rs", "pub fn foo() {}")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
p.cargo("doc --workspace -Zunstable-options -Zrustdoc-scrape-examples")
|
||||||
|
.masquerade_as_nightly_cargo(&["rustdoc-scrape-examples"])
|
||||||
|
.run();
|
||||||
|
|
||||||
|
let doc_html = p.read_file("target/doc/foo/fn.foo.html");
|
||||||
|
let example_found = doc_html.contains("Examples found in repository");
|
||||||
|
if should_scrape {
|
||||||
|
assert!(example_found);
|
||||||
|
} else {
|
||||||
|
assert!(!example_found);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// By default, bar should be scraped.
|
||||||
|
run_with_config("", true);
|
||||||
|
// If bar isn't supposed to be documented, then it is not eligible
|
||||||
|
// for scraping.
|
||||||
|
run_with_config("doc = false", false);
|
||||||
|
// But if the user explicitly says bar should be scraped, then it should
|
||||||
|
// be scraped.
|
||||||
|
run_with_config("doc = false\ndoc-scrape-examples = true", true);
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user