@@ -48,6 +48,84 @@ fn basic() {
48
48
assert ! ( p. build_dir( ) . join( "doc/src/ex/ex.rs.html" ) . exists( ) ) ;
49
49
}
50
50
51
+ // This test ensures that even if there is no `[workspace]` in the top-level `Cargo.toml` file, the
52
+ // dependencies will get their examples scraped and that they appear in the generated documentation.
53
+ #[ cargo_test( nightly, reason = "-Zrustdoc-scrape-examples is unstable" ) ]
54
+ fn scrape_examples_for_non_workspace_reexports ( ) {
55
+ let p = project ( )
56
+ . file (
57
+ "Cargo.toml" ,
58
+ r#"
59
+ [package]
60
+ name = "foo"
61
+ version = "0.0.1"
62
+ edition = "2021"
63
+ authors = []
64
+
65
+ [dependencies]
66
+ a = { path = "crates/a" }
67
+ "# ,
68
+ )
69
+ . file ( "src/lib.rs" , "pub use a::*;" )
70
+ // Example
71
+ . file (
72
+ "examples/one.rs" ,
73
+ r#"use foo::*;
74
+ fn main() {
75
+ let foo = Foo::new("yes".into());
76
+ foo.maybe();
77
+ }"# ,
78
+ )
79
+ // `a` crate
80
+ . file (
81
+ "crates/a/Cargo.toml" ,
82
+ r#"
83
+ [package]
84
+ name = "a"
85
+ version = "0.0.1"
86
+ authors = []
87
+ "# ,
88
+ )
89
+ . file (
90
+ "crates/a/src/lib.rs" ,
91
+ r#"
92
+ #[derive(Debug)]
93
+ pub struct Foo {
94
+ foo: String,
95
+ yes: bool,
96
+ }
97
+
98
+ impl Foo {
99
+ pub fn new(foo: String) -> Self {
100
+ Self { foo, yes: true }
101
+ }
102
+
103
+ pub fn maybe(&self) {
104
+ if self.yes {
105
+ println!("{}", self.foo)
106
+ }
107
+ }
108
+ }"# ,
109
+ )
110
+ . build ( ) ;
111
+
112
+ p. cargo ( "doc -Zunstable-options -Zrustdoc-scrape-examples --no-deps" )
113
+ . masquerade_as_nightly_cargo ( & [ "rustdoc-scrape-examples" ] )
114
+ . with_stderr_unordered (
115
+ "\
116
+ [CHECKING] a v0.0.1 ([CWD]/crates/a)
117
+ [CHECKING] foo v0.0.1 ([CWD])
118
+ [SCRAPING] foo v0.0.1 ([CWD])
119
+ [DOCUMENTING] foo v0.0.1 ([CWD])
120
+ [FINISHED] [..]
121
+ [GENERATED] [CWD]/target/doc/foo/index.html" ,
122
+ )
123
+ . run ( ) ;
124
+
125
+ let doc_html = p. read_file ( "target/doc/foo/struct.Foo.html" ) ;
126
+ assert ! ( doc_html. contains( "Examples found in repository" ) ) ;
127
+ }
128
+
51
129
#[ cargo_test( nightly, reason = "rustdoc scrape examples flags are unstable" ) ]
52
130
fn avoid_build_script_cycle ( ) {
53
131
let p = project ( )
0 commit comments