summaryrefslogtreecommitdiffstats
path: root/src/tools/cargo/tests/testsuite/docscrape.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-19 09:26:03 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-19 09:26:03 +0000
commit9918693037dce8aa4bb6f08741b6812923486c18 (patch)
tree21d2b40bec7e6a7ea664acee056eb3d08e15a1cf /src/tools/cargo/tests/testsuite/docscrape.rs
parentReleasing progress-linux version 1.75.0+dfsg1-5~progress7.99u1. (diff)
downloadrustc-9918693037dce8aa4bb6f08741b6812923486c18.tar.xz
rustc-9918693037dce8aa4bb6f08741b6812923486c18.zip
Merging upstream version 1.76.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/tools/cargo/tests/testsuite/docscrape.rs')
-rw-r--r--src/tools/cargo/tests/testsuite/docscrape.rs78
1 files changed, 78 insertions, 0 deletions
diff --git a/src/tools/cargo/tests/testsuite/docscrape.rs b/src/tools/cargo/tests/testsuite/docscrape.rs
index d4d011ff3..91871be04 100644
--- a/src/tools/cargo/tests/testsuite/docscrape.rs
+++ b/src/tools/cargo/tests/testsuite/docscrape.rs
@@ -48,6 +48,84 @@ fn basic() {
assert!(p.build_dir().join("doc/src/ex/ex.rs.html").exists());
}
+// This test ensures that even if there is no `[workspace]` in the top-level `Cargo.toml` file, the
+// dependencies will get their examples scraped and that they appear in the generated documentation.
+#[cargo_test(nightly, reason = "-Zrustdoc-scrape-examples is unstable")]
+fn scrape_examples_for_non_workspace_reexports() {
+ let p = project()
+ .file(
+ "Cargo.toml",
+ r#"
+ [package]
+ name = "foo"
+ version = "0.0.1"
+ edition = "2021"
+ authors = []
+
+ [dependencies]
+ a = { path = "crates/a" }
+ "#,
+ )
+ .file("src/lib.rs", "pub use a::*;")
+ // Example
+ .file(
+ "examples/one.rs",
+ r#"use foo::*;
+fn main() {
+ let foo = Foo::new("yes".into());
+ foo.maybe();
+}"#,
+ )
+ // `a` crate
+ .file(
+ "crates/a/Cargo.toml",
+ r#"
+ [package]
+ name = "a"
+ version = "0.0.1"
+ authors = []
+ "#,
+ )
+ .file(
+ "crates/a/src/lib.rs",
+ r#"
+#[derive(Debug)]
+pub struct Foo {
+ foo: String,
+ yes: bool,
+}
+
+impl Foo {
+ pub fn new(foo: String) -> Self {
+ Self { foo, yes: true }
+ }
+
+ pub fn maybe(&self) {
+ if self.yes {
+ println!("{}", self.foo)
+ }
+ }
+}"#,
+ )
+ .build();
+
+ p.cargo("doc -Zunstable-options -Zrustdoc-scrape-examples --no-deps")
+ .masquerade_as_nightly_cargo(&["rustdoc-scrape-examples"])
+ .with_stderr_unordered(
+ "\
+[CHECKING] a v0.0.1 ([CWD]/crates/a)
+[CHECKING] foo v0.0.1 ([CWD])
+[SCRAPING] foo v0.0.1 ([CWD])
+[DOCUMENTING] foo v0.0.1 ([CWD])
+[FINISHED] [..]
+[GENERATED] [CWD]/target/doc/foo/index.html",
+ )
+ .run();
+
+ let doc_html = p.read_file("target/doc/foo/struct.Foo.html");
+ assert!(doc_html.contains("Examples found in repository"));
+}
+
#[cargo_test(nightly, reason = "rustdoc scrape examples flags are unstable")]
fn avoid_build_script_cycle() {
let p = project()