Skip to content

Commit 8b038eb

Browse files
committed
test: migrate docscrape to snapbox
1 parent 8a997bf commit 8b038eb

File tree

1 file changed

+113
-102
lines changed

1 file changed

+113
-102
lines changed

tests/testsuite/docscrape.rs

Lines changed: 113 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
//! Tests for the `cargo doc` command with `-Zrustdoc-scrape-examples`.
22
3-
#![allow(deprecated)]
4-
3+
use cargo_test_support::prelude::*;
54
use cargo_test_support::project;
5+
use cargo_test_support::str;
66

77
#[cargo_test(nightly, reason = "rustdoc scrape examples flags are unstable")]
88
fn basic() {
@@ -23,24 +23,23 @@ fn basic() {
2323

2424
p.cargo("doc -Zunstable-options -Zrustdoc-scrape-examples")
2525
.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+
"#]])
3534
.run();
3635

3736
p.cargo("doc -Zunstable-options -Z rustdoc-scrape-examples")
3837
.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+
"#]])
4443
.run();
4544

4645
let doc_html = p.read_file("target/doc/foo/fn.foo.html");
@@ -115,15 +114,18 @@ impl Foo {
115114

116115
p.cargo("doc -Zunstable-options -Zrustdoc-scrape-examples --no-deps")
117116
.masquerade_as_nightly_cargo(&["rustdoc-scrape-examples"])
118-
.with_stderr_unordered(
119-
"\
117+
.with_stderr_data(
118+
str![[r#"
120119
[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(),
127129
)
128130
.run();
129131

@@ -402,25 +404,23 @@ fn cache() {
402404

403405
p.cargo("doc -Zunstable-options -Zrustdoc-scrape-examples")
404406
.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+
"#]])
414415
.run();
415416

416417
p.cargo("doc -Zunstable-options -Zrustdoc-scrape-examples")
417418
.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+
"#]])
424424
.run();
425425
}
426426

@@ -444,27 +444,26 @@ fn no_fail_bad_lib() {
444444

445445
p.cargo("doc -Zunstable-options -Z rustdoc-scrape-examples")
446446
.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"
452451
Try running with `--verbose` to see the error message.
453452
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
456455
Try running with `--verbose` to see the error message.
457456
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
460459
Try running with `--verbose` to see the error message.
461460
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())
468467
.run();
469468
}
470469

@@ -489,14 +488,22 @@ fn fail_bad_build_script() {
489488
// `cargo doc` fails
490489
p.cargo("doc")
491490
.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+
"#]])
493496
.run();
494497

495498
// scrape examples should fail whenever `cargo doc` fails.
496499
p.cargo("doc -Zunstable-options -Z rustdoc-scrape-examples")
497500
.masquerade_as_nightly_cargo(&["rustdoc-scrape-examples"])
498501
.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+
"#]])
500507
.run();
501508
}
502509

@@ -520,43 +527,44 @@ fn no_fail_bad_example() {
520527

521528
p.cargo("doc -Zunstable-options -Z rustdoc-scrape-examples")
522529
.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
528534
Try running with `--verbose` to see the error message.
529535
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+
"#]])
536542
.run();
537543

538544
p.cargo("clean").run();
539545

540546
p.cargo("doc -v -Zunstable-options -Z rustdoc-scrape-examples")
541547
.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)
545551
[RUNNING] `rustc --crate-name foo[..]
546-
[SCRAPING] foo v0.0.1 ([CWD])
552+
[SCRAPING] foo v0.0.1 ([ROOT]/foo)
547553
[RUNNING] `rustdoc[..] --crate-name ex1[..]
548554
[RUNNING] `rustdoc[..] --crate-name ex2[..]
549555
[RUNNING] `rustdoc[..] --crate-name foo[..]
550-
error: expected one of `!` or `::`, found `NOT`
556+
[ERROR] expected one of `!` or `::`, found `NOT`
551557
--> examples/ex1.rs:1:6
552558
|
553559
1 | DOES NOT COMPILE
554560
| ^^^ expected one of `!` or `::`
555561
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(),
560568
)
561569
.run();
562570

@@ -603,32 +611,33 @@ fn no_scrape_with_dev_deps() {
603611
// should be raised.
604612
p.cargo("doc -Zunstable-options -Z rustdoc-scrape-examples")
605613
.masquerade_as_nightly_cargo(&["rustdoc-scrape-examples"])
606-
.with_stderr(
607-
"\
614+
.with_stderr_data(str![[r#"
608615
[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
610617
If you want Rustdoc to scrape these examples, then add `doc-scrape-examples = true`
611618
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+
"#]])
617624
.run();
618625

619626
// If --examples is provided, then the example is scanned.
620627
p.cargo("doc --examples -Zunstable-options -Z rustdoc-scrape-examples")
621628
.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(),
632641
)
633642
.run();
634643
}
@@ -671,16 +680,18 @@ fn use_dev_deps_if_explicitly_enabled() {
671680
// If --examples is not provided, then the example is never scanned.
672681
p.cargo("doc -Zunstable-options -Z rustdoc-scrape-examples")
673682
.masquerade_as_nightly_cargo(&["rustdoc-scrape-examples"])
674-
.with_stderr_unordered(
675-
"\
683+
.with_stderr_data(
684+
str![[r#"
676685
[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)
681690
[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(),
684695
)
685696
.run();
686697
}

0 commit comments

Comments
 (0)