@@ -513,6 +513,108 @@ fn doc_lib_bin_same_name_documents_bins_when_requested() {
513
513
assert ! ( doc_html. contains( "Binary" ) ) ;
514
514
}
515
515
516
+ #[ cargo_test]
517
+ fn doc_lib_bin_example_same_name_documents_named_example_when_requested ( ) {
518
+ let p = project ( )
519
+ . file (
520
+ "src/main.rs" ,
521
+ r#"
522
+ //! Binary documentation
523
+ extern crate foo;
524
+ fn main() {
525
+ foo::foo();
526
+ }
527
+ "# ,
528
+ )
529
+ . file (
530
+ "src/lib.rs" ,
531
+ r#"
532
+ //! Library documentation
533
+ pub fn foo() {}
534
+ "# ,
535
+ )
536
+ . file (
537
+ "examples/ex1.rs" ,
538
+ r#"
539
+ //! Example1 documentation
540
+ pub fn x() { f(); }
541
+ "# ,
542
+ )
543
+ . build ( ) ;
544
+
545
+ p. cargo ( "doc --example ex1" )
546
+ . with_stderr (
547
+ "\
548
+ [CHECKING] foo v0.0.1 ([CWD])
549
+ [DOCUMENTING] foo v0.0.1 ([CWD])
550
+ [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]" ,
551
+ )
552
+ . run ( ) ;
553
+
554
+ let doc_html = p. read_file ( "target/doc/ex1/index.html" ) ;
555
+ assert ! ( !doc_html. contains( "Library" ) ) ;
556
+ assert ! ( !doc_html. contains( "Binary" ) ) ;
557
+ assert ! ( doc_html. contains( "Example1" ) ) ;
558
+ }
559
+
560
+ #[ cargo_test]
561
+ fn doc_lib_bin_example_same_name_documents_examples_when_requested ( ) {
562
+ let p = project ( )
563
+ . file (
564
+ "src/main.rs" ,
565
+ r#"
566
+ //! Binary documentation
567
+ extern crate foo;
568
+ fn main() {
569
+ foo::foo();
570
+ }
571
+ "# ,
572
+ )
573
+ . file (
574
+ "src/lib.rs" ,
575
+ r#"
576
+ //! Library documentation
577
+ pub fn foo() {}
578
+ "# ,
579
+ )
580
+ . file (
581
+ "examples/ex1.rs" ,
582
+ r#"
583
+ //! Example1 documentation
584
+ pub fn example1() { f(); }
585
+ "# ,
586
+ )
587
+ . file (
588
+ "examples/ex2.rs" ,
589
+ r#"
590
+ //! Example2 documentation
591
+ pub fn example2() { f(); }
592
+ "# ,
593
+ )
594
+ . build ( ) ;
595
+
596
+ p. cargo ( "doc --examples" )
597
+ . with_stderr (
598
+ "\
599
+ [CHECKING] foo v0.0.1 ([CWD])
600
+ [DOCUMENTING] foo v0.0.1 ([CWD])
601
+ [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]" ,
602
+ )
603
+ . run ( ) ;
604
+
605
+ let example_doc_html_1 = p. read_file ( "target/doc/ex1/index.html" ) ;
606
+ let example_doc_html_2 = p. read_file ( "target/doc/ex2/index.html" ) ;
607
+
608
+ assert ! ( !example_doc_html_1. contains( "Library" ) ) ;
609
+ assert ! ( !example_doc_html_1. contains( "Binary" ) ) ;
610
+
611
+ assert ! ( !example_doc_html_2. contains( "Library" ) ) ;
612
+ assert ! ( !example_doc_html_2. contains( "Binary" ) ) ;
613
+
614
+ assert ! ( example_doc_html_1. contains( "Example1" ) ) ;
615
+ assert ! ( example_doc_html_2. contains( "Example2" ) ) ;
616
+ }
617
+
516
618
#[ cargo_test]
517
619
fn doc_dash_p ( ) {
518
620
let p = project ( )
0 commit comments