@@ -196,7 +196,7 @@ fn configure_target() {
196
196
)
197
197
. build ( ) ;
198
198
199
- p. cargo ( "doc --lib --bins - Zunstable-options -Zrustdoc-scrape-examples" )
199
+ p. cargo ( "doc -Zunstable-options -Zrustdoc-scrape-examples" )
200
200
. masquerade_as_nightly_cargo ( & [ "rustdoc-scrape-examples" ] )
201
201
. run ( ) ;
202
202
@@ -519,3 +519,64 @@ fn use_dev_deps_if_explicitly_enabled() {
519
519
)
520
520
. run ( ) ;
521
521
}
522
+
523
+ #[ cargo_test( nightly, reason = "rustdoc scrape examples flags are unstable" ) ]
524
+ fn only_scrape_documented_targets ( ) {
525
+ // package bar has doc = false and should not be eligible for documtation.
526
+ let run_with_config = |config : & str , should_scrape : bool | {
527
+ let p = project ( )
528
+ . file (
529
+ "Cargo.toml" ,
530
+ & format ! (
531
+ r#"
532
+ [package]
533
+ name = "bar"
534
+ version = "0.0.1"
535
+ authors = []
536
+
537
+ [lib]
538
+ {config}
539
+
540
+ [workspace]
541
+ members = ["foo"]
542
+
543
+ [dependencies]
544
+ foo = {{ path = "foo" }}
545
+ "#
546
+ ) ,
547
+ )
548
+ . file ( "src/lib.rs" , "pub fn bar() { foo::foo(); }" )
549
+ . file (
550
+ "foo/Cargo.toml" ,
551
+ r#"
552
+ [package]
553
+ name = "foo"
554
+ version = "0.0.1"
555
+ authors = []
556
+ "# ,
557
+ )
558
+ . file ( "foo/src/lib.rs" , "pub fn foo() {}" )
559
+ . build ( ) ;
560
+
561
+ p. cargo ( "doc --workspace -Zunstable-options -Zrustdoc-scrape-examples" )
562
+ . masquerade_as_nightly_cargo ( & [ "rustdoc-scrape-examples" ] )
563
+ . run ( ) ;
564
+
565
+ let doc_html = p. read_file ( "target/doc/foo/fn.foo.html" ) ;
566
+ let example_found = doc_html. contains ( "Examples found in repository" ) ;
567
+ if should_scrape {
568
+ assert ! ( example_found) ;
569
+ } else {
570
+ assert ! ( !example_found) ;
571
+ }
572
+ } ;
573
+
574
+ // By default, bar should be scraped.
575
+ run_with_config ( "" , true ) ;
576
+ // If bar isn't supposed to be documented, then it is not eligible
577
+ // for scraping.
578
+ run_with_config ( "doc = false" , false ) ;
579
+ // But if the user explicitly says bar should be scraped, then it should
580
+ // be scraped.
581
+ run_with_config ( "doc = false\n doc-scrape-examples = true" , true ) ;
582
+ }
0 commit comments