1
1
//! Tests for the `cargo doc` command with `-Zrustdoc-scrape-examples`.
2
2
3
- #![ allow( deprecated) ]
4
-
3
+ use cargo_test_support:: prelude:: * ;
5
4
use cargo_test_support:: project;
5
+ use cargo_test_support:: str;
6
6
7
7
#[ cargo_test( nightly, reason = "rustdoc scrape examples flags are unstable" ) ]
8
8
fn basic ( ) {
@@ -23,24 +23,23 @@ fn basic() {
23
23
24
24
p. cargo ( "doc -Zunstable-options -Zrustdoc-scrape-examples" )
25
25
. masquerade_as_nightly_cargo ( & [ "rustdoc-scrape-examples" ] )
26
- . with_stderr (
27
- "\
28
- [CHECKING] foo v0.0.1 ([CWD])
29
- [SCRAPING] foo v0.0.1 ([CWD])
30
- [DOCUMENTING] foo v0.0.1 ([CWD])
31
- [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]
32
- [GENERATED] [CWD]/target/doc/foo/index.html
33
- " ,
34
- )
26
+ . with_stderr_data ( str![ [ r#"
27
+ [CHECKING] foo v0.0.1 ([ROOT]/foo)
28
+ [SCRAPING] foo v0.0.1 ([ROOT]/foo)
29
+ [DOCUMENTING] foo v0.0.1 ([ROOT]/foo)
30
+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
31
+ [GENERATED] [ROOT]/foo/target/doc/foo/index.html
32
+
33
+ "# ] ] )
35
34
. run ( ) ;
36
35
37
36
p. cargo ( "doc -Zunstable-options -Z rustdoc-scrape-examples" )
38
37
. masquerade_as_nightly_cargo ( & [ "rustdoc-scrape-examples" ] )
39
- . with_stderr (
40
- "[FINISHED] [..]
41
- [GENERATED] [CWD] /target/doc/foo/index.html
42
- " ,
43
- )
38
+ . with_stderr_data ( str! [ [ r#"
39
+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
40
+ [GENERATED] [ROOT]/foo /target/doc/foo/index.html
41
+
42
+ "# ] ] )
44
43
. run ( ) ;
45
44
46
45
let doc_html = p. read_file ( "target/doc/foo/fn.foo.html" ) ;
@@ -115,15 +114,18 @@ impl Foo {
115
114
116
115
p. cargo ( "doc -Zunstable-options -Zrustdoc-scrape-examples --no-deps" )
117
116
. masquerade_as_nightly_cargo ( & [ "rustdoc-scrape-examples" ] )
118
- . with_stderr_unordered (
119
- " \
117
+ . with_stderr_data (
118
+ str! [ [ r#"
120
119
[LOCKING] 2 packages to latest compatible versions
121
- [CHECKING] a v0.0.1 ([CWD]/crates/a)
122
- [CHECKING] foo v0.0.1 ([CWD])
123
- [SCRAPING] foo v0.0.1 ([CWD])
124
- [DOCUMENTING] foo v0.0.1 ([CWD])
125
- [FINISHED] [..]
126
- [GENERATED] [CWD]/target/doc/foo/index.html" ,
120
+ [CHECKING] a v0.0.1 ([ROOT]/foo/crates/a)
121
+ [CHECKING] foo v0.0.1 ([ROOT]/foo)
122
+ [SCRAPING] foo v0.0.1 ([ROOT]/foo)
123
+ [DOCUMENTING] foo v0.0.1 ([ROOT]/foo)
124
+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
125
+ [GENERATED] [ROOT]/foo/target/doc/foo/index.html
126
+
127
+ "# ] ]
128
+ . unordered ( ) ,
127
129
)
128
130
. run ( ) ;
129
131
@@ -402,25 +404,23 @@ fn cache() {
402
404
403
405
p. cargo ( "doc -Zunstable-options -Zrustdoc-scrape-examples" )
404
406
. masquerade_as_nightly_cargo ( & [ "rustdoc-scrape-examples" ] )
405
- . with_stderr (
406
- "\
407
- [CHECKING] foo v0.0.1 ([CWD])
408
- [SCRAPING] foo v0.0.1 ([CWD])
409
- [DOCUMENTING] foo v0.0.1 ([CWD])
410
- [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]
411
- [GENERATED] [CWD]/target/doc/foo/index.html
412
- " ,
413
- )
407
+ . with_stderr_data ( str![ [ r#"
408
+ [CHECKING] foo v0.0.1 ([ROOT]/foo)
409
+ [SCRAPING] foo v0.0.1 ([ROOT]/foo)
410
+ [DOCUMENTING] foo v0.0.1 ([ROOT]/foo)
411
+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
412
+ [GENERATED] [ROOT]/foo/target/doc/foo/index.html
413
+
414
+ "# ] ] )
414
415
. run ( ) ;
415
416
416
417
p. cargo ( "doc -Zunstable-options -Zrustdoc-scrape-examples" )
417
418
. masquerade_as_nightly_cargo ( & [ "rustdoc-scrape-examples" ] )
418
- . with_stderr (
419
- "\
420
- [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]
421
- [GENERATED] [CWD]/target/doc/foo/index.html
422
- " ,
423
- )
419
+ . with_stderr_data ( str![ [ r#"
420
+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
421
+ [GENERATED] [ROOT]/foo/target/doc/foo/index.html
422
+
423
+ "# ] ] )
424
424
. run ( ) ;
425
425
}
426
426
@@ -444,27 +444,26 @@ fn no_fail_bad_lib() {
444
444
445
445
p. cargo ( "doc -Zunstable-options -Z rustdoc-scrape-examples" )
446
446
. masquerade_as_nightly_cargo ( & [ "rustdoc-scrape-examples" ] )
447
- . with_stderr_unordered (
448
- "\
449
- [CHECKING] foo v0.0.1 ([CWD])
450
- [SCRAPING] foo v0.0.1 ([CWD])
451
- warning: failed to check lib in package `foo` as a prerequisite for scraping examples from: example \" ex\" , example \" ex2\"
447
+ . with_stderr_data ( str![ [ r#"
448
+ [CHECKING] foo v0.0.1 ([ROOT]/foo)
449
+ [SCRAPING] foo v0.0.1 ([ROOT]/foo)
450
+ [WARNING] failed to check lib in package `foo` as a prerequisite for scraping examples from: example "ex", example "ex2"
452
451
Try running with `--verbose` to see the error message.
453
452
If an example should not be scanned, then consider adding `doc-scrape-examples = false` to its `[[example]]` definition in Cargo.toml
454
- warning: `foo` (lib) generated 1 warning
455
- warning: failed to scan example \ " ex\ " in package `foo` for example code usage
453
+ [WARNING] `foo` (lib) generated 1 warning
454
+ [WARNING] failed to scan example "ex" in package `foo` for example code usage
456
455
Try running with `--verbose` to see the error message.
457
456
If an example should not be scanned, then consider adding `doc-scrape-examples = false` to its `[[example]]` definition in Cargo.toml
458
- warning: `foo` (example \ " ex\ " ) generated 1 warning
459
- warning: failed to scan example \ " ex2\ " in package `foo` for example code usage
457
+ [WARNING] `foo` (example "ex") generated 1 warning
458
+ [WARNING] failed to scan example "ex2" in package `foo` for example code usage
460
459
Try running with `--verbose` to see the error message.
461
460
If an example should not be scanned, then consider adding `doc-scrape-examples = false` to its `[[example]]` definition in Cargo.toml
462
- warning: `foo` (example \ " ex2\ " ) generated 1 warning
463
- [DOCUMENTING] foo v0.0.1 ([CWD] )
464
- [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]
465
- [GENERATED] [CWD] /target/doc/foo/index.html
466
- " ,
467
- )
461
+ [WARNING] `foo` (example "ex2") generated 1 warning
462
+ [DOCUMENTING] foo v0.0.1 ([ROOT]/foo )
463
+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
464
+ [GENERATED] [ROOT]/foo /target/doc/foo/index.html
465
+
466
+ "# ] ] . unordered ( ) )
468
467
. run ( ) ;
469
468
}
470
469
@@ -489,14 +488,22 @@ fn fail_bad_build_script() {
489
488
// `cargo doc` fails
490
489
p. cargo ( "doc" )
491
490
. with_status ( 101 )
492
- . with_stderr_contains ( "[..]You shall not pass[..]" )
491
+ . with_stderr_data ( str![ [ r#"
492
+ ...
493
+ [..]You shall not pass[..]
494
+ ...
495
+ "# ] ] )
493
496
. run ( ) ;
494
497
495
498
// scrape examples should fail whenever `cargo doc` fails.
496
499
p. cargo ( "doc -Zunstable-options -Z rustdoc-scrape-examples" )
497
500
. masquerade_as_nightly_cargo ( & [ "rustdoc-scrape-examples" ] )
498
501
. with_status ( 101 )
499
- . with_stderr_contains ( "[..]You shall not pass[..]" )
502
+ . with_stderr_data ( str![ [ r#"
503
+ ...
504
+ [..]You shall not pass[..]
505
+ ...
506
+ "# ] ] )
500
507
. run ( ) ;
501
508
}
502
509
@@ -520,43 +527,44 @@ fn no_fail_bad_example() {
520
527
521
528
p. cargo ( "doc -Zunstable-options -Z rustdoc-scrape-examples" )
522
529
. masquerade_as_nightly_cargo ( & [ "rustdoc-scrape-examples" ] )
523
- . with_stderr (
524
- "\
525
- [CHECKING] foo v0.0.1 ([CWD])
526
- [SCRAPING] foo v0.0.1 ([CWD])
527
- warning: failed to scan example \" ex1\" in package `foo` for example code usage
530
+ . with_stderr_data ( str![ [ r#"
531
+ [CHECKING] foo v0.0.1 ([ROOT]/foo)
532
+ [SCRAPING] foo v0.0.1 ([ROOT]/foo)
533
+ [WARNING] failed to scan example "ex1" in package `foo` for example code usage
528
534
Try running with `--verbose` to see the error message.
529
535
If an example should not be scanned, then consider adding `doc-scrape-examples = false` to its `[[example]]` definition in Cargo.toml
530
- warning: `foo` (example \ " ex1\ " ) generated 1 warning
531
- [DOCUMENTING] foo v0.0.1 ([CWD] )
532
- [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]
533
- [GENERATED] [CWD] /target/doc/foo/index.html
534
- " ,
535
- )
536
+ [WARNING] `foo` (example "ex1") generated 1 warning
537
+ [DOCUMENTING] foo v0.0.1 ([ROOT]/foo )
538
+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
539
+ [GENERATED] [ROOT]/foo /target/doc/foo/index.html
540
+
541
+ "# ] ] )
536
542
. run ( ) ;
537
543
538
544
p. cargo ( "clean" ) . run ( ) ;
539
545
540
546
p. cargo ( "doc -v -Zunstable-options -Z rustdoc-scrape-examples" )
541
547
. masquerade_as_nightly_cargo ( & [ "rustdoc-scrape-examples" ] )
542
- . with_stderr_unordered (
543
- " \
544
- [CHECKING] foo v0.0.1 ([CWD] )
548
+ . with_stderr_data (
549
+ str! [ [ r#"
550
+ [CHECKING] foo v0.0.1 ([ROOT]/foo )
545
551
[RUNNING] `rustc --crate-name foo[..]
546
- [SCRAPING] foo v0.0.1 ([CWD] )
552
+ [SCRAPING] foo v0.0.1 ([ROOT]/foo )
547
553
[RUNNING] `rustdoc[..] --crate-name ex1[..]
548
554
[RUNNING] `rustdoc[..] --crate-name ex2[..]
549
555
[RUNNING] `rustdoc[..] --crate-name foo[..]
550
- error: expected one of `!` or `::`, found `NOT`
556
+ [ERROR] expected one of `!` or `::`, found `NOT`
551
557
--> examples/ex1.rs:1:6
552
558
|
553
559
1 | DOES NOT COMPILE
554
560
| ^^^ expected one of `!` or `::`
555
561
556
- [DOCUMENTING] foo v0.0.1 ([CWD])
557
- [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]
558
- [GENERATED] [CWD]/target/doc/foo/index.html
559
- " ,
562
+ [DOCUMENTING] foo v0.0.1 ([ROOT]/foo)
563
+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
564
+ [GENERATED] [ROOT]/foo/target/doc/foo/index.html
565
+
566
+ "# ] ]
567
+ . unordered ( ) ,
560
568
)
561
569
. run ( ) ;
562
570
@@ -603,32 +611,33 @@ fn no_scrape_with_dev_deps() {
603
611
// should be raised.
604
612
p. cargo ( "doc -Zunstable-options -Z rustdoc-scrape-examples" )
605
613
. masquerade_as_nightly_cargo ( & [ "rustdoc-scrape-examples" ] )
606
- . with_stderr (
607
- "\
614
+ . with_stderr_data ( str![ [ r#"
608
615
[LOCKING] 2 packages to latest compatible versions
609
- warning: Rustdoc did not scrape the following examples because they require dev-dependencies: ex
616
+ [WARNING] Rustdoc did not scrape the following examples because they require dev-dependencies: ex
610
617
If you want Rustdoc to scrape these examples, then add `doc-scrape-examples = true`
611
618
to the [[example]] target configuration of at least one example.
612
- [DOCUMENTING] foo v0.0.1 ([CWD] )
613
- [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]
614
- [GENERATED] [CWD] /target/doc/foo/index.html
615
- " ,
616
- )
619
+ [DOCUMENTING] foo v0.0.1 ([ROOT]/foo )
620
+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
621
+ [GENERATED] [ROOT]/foo /target/doc/foo/index.html
622
+
623
+ "# ] ] )
617
624
. run ( ) ;
618
625
619
626
// If --examples is provided, then the example is scanned.
620
627
p. cargo ( "doc --examples -Zunstable-options -Z rustdoc-scrape-examples" )
621
628
. masquerade_as_nightly_cargo ( & [ "rustdoc-scrape-examples" ] )
622
- . with_stderr_unordered (
623
- "\
624
- [CHECKING] a v0.0.1 ([CWD]/a)
625
- [CHECKING] foo v0.0.1 ([CWD])
626
- [DOCUMENTING] a v0.0.1 ([CWD]/a)
627
- [SCRAPING] foo v0.0.1 ([CWD])
628
- [DOCUMENTING] foo v0.0.1 ([CWD])
629
- [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]
630
- [GENERATED] [CWD]/target/doc/ex/index.html
631
- " ,
629
+ . with_stderr_data (
630
+ str![ [ r#"
631
+ [CHECKING] a v0.0.1 ([ROOT]/foo/a)
632
+ [CHECKING] foo v0.0.1 ([ROOT]/foo)
633
+ [DOCUMENTING] a v0.0.1 ([ROOT]/foo/a)
634
+ [SCRAPING] foo v0.0.1 ([ROOT]/foo)
635
+ [DOCUMENTING] foo v0.0.1 ([ROOT]/foo)
636
+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
637
+ [GENERATED] [ROOT]/foo/target/doc/ex/index.html
638
+
639
+ "# ] ]
640
+ . unordered ( ) ,
632
641
)
633
642
. run ( ) ;
634
643
}
@@ -671,16 +680,18 @@ fn use_dev_deps_if_explicitly_enabled() {
671
680
// If --examples is not provided, then the example is never scanned.
672
681
p. cargo ( "doc -Zunstable-options -Z rustdoc-scrape-examples" )
673
682
. masquerade_as_nightly_cargo ( & [ "rustdoc-scrape-examples" ] )
674
- . with_stderr_unordered (
675
- " \
683
+ . with_stderr_data (
684
+ str! [ [ r#"
676
685
[LOCKING] 2 packages to latest compatible versions
677
- [CHECKING] foo v0.0.1 ([CWD] )
678
- [CHECKING] a v0.0.1 ([CWD]/a )
679
- [SCRAPING] foo v0.0.1 ([CWD] )
680
- [DOCUMENTING] foo v0.0.1 ([CWD] )
686
+ [CHECKING] a v0.0.1 ([ROOT]/foo/a )
687
+ [CHECKING] foo v0.0.1 ([ROOT]/foo )
688
+ [SCRAPING] foo v0.0.1 ([ROOT]/foo )
689
+ [DOCUMENTING] foo v0.0.1 ([ROOT]/foo )
681
690
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]
682
- [GENERATED] [CWD]/target/doc/foo/index.html
683
- " ,
691
+ [GENERATED] [ROOT]/foo/target/doc/foo/index.html
692
+
693
+ "# ] ]
694
+ . unordered ( ) ,
684
695
)
685
696
. run ( ) ;
686
697
}
0 commit comments