From 33e06345aaff3a8061eda66007900d29d75b37a2 Mon Sep 17 00:00:00 2001 From: eth3lbert Date: Tue, 18 Jun 2024 23:59:37 +0800 Subject: [PATCH] test: migrate rustdocflags to snapbox --- tests/testsuite/rustdocflags.rs | 133 +++++++++++++++++++++++--------- 1 file changed, 96 insertions(+), 37 deletions(-) diff --git a/tests/testsuite/rustdocflags.rs b/tests/testsuite/rustdocflags.rs index 7afc8e78bb2e..462052fdf63b 100644 --- a/tests/testsuite/rustdocflags.rs +++ b/tests/testsuite/rustdocflags.rs @@ -1,10 +1,9 @@ //! Tests for setting custom rustdoc flags. -#![allow(deprecated)] - use cargo_test_support::project; use cargo_test_support::rustc_host; use cargo_test_support::rustc_host_env; +use cargo_test_support::str; #[cargo_test] fn parses_env() { @@ -12,7 +11,13 @@ fn parses_env() { p.cargo("doc -v") .env("RUSTDOCFLAGS", "--cfg=foo") - .with_stderr_contains("[RUNNING] `rustdoc [..] --cfg=foo[..]`") + .with_stderr_data(str![[r#" +[DOCUMENTING] foo v0.0.1 ([ROOT]/foo) +[RUNNING] `rustdoc [..] --cfg=foo [..]` +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s +[GENERATED] [ROOT]/foo/target/doc/foo/index.html + +"#]]) .run(); } @@ -30,7 +35,13 @@ fn parses_config() { .build(); p.cargo("doc -v") - .with_stderr_contains("[RUNNING] `rustdoc [..] --cfg foo[..]`") + .with_stderr_data(str![[r#" +[DOCUMENTING] foo v0.0.1 ([ROOT]/foo) +[RUNNING] `rustdoc [..] --cfg foo [..]` +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s +[GENERATED] [ROOT]/foo/target/doc/foo/index.html + +"#]]) .run(); } @@ -41,7 +52,13 @@ fn bad_flags() { p.cargo("doc") .env("RUSTDOCFLAGS", "--bogus") .with_status(101) - .with_stderr_contains("[..]bogus[..]") + .with_stderr_data(str![[r#" +[DOCUMENTING] foo v0.0.1 ([ROOT]/foo) +[ERROR] Unrecognized option: 'bogus' + +[ERROR] could not document `foo` + +"#]]) .run(); } @@ -52,20 +69,20 @@ fn rerun() { p.cargo("doc").env("RUSTDOCFLAGS", "--cfg=foo").run(); p.cargo("doc") .env("RUSTDOCFLAGS", "--cfg=foo") - .with_stderr( - "[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..] -[GENERATED] [CWD]/target/doc/foo/index.html", - ) + .with_stderr_data(str![[r#" +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s +[GENERATED] [ROOT]/foo/target/doc/foo/index.html + +"#]]) .run(); p.cargo("doc") .env("RUSTDOCFLAGS", "--cfg=bar") - .with_stderr( - "\ -[DOCUMENTING] foo v0.0.1 ([..]) -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..] -[GENERATED] [CWD]/target/doc/foo/index.html -", - ) + .with_stderr_data(str![[r#" +[DOCUMENTING] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s +[GENERATED] [ROOT]/foo/target/doc/foo/index.html + +"#]]) .run(); } @@ -102,7 +119,13 @@ fn rustdocflags_misspelled() { p.cargo("doc") .env("RUSTDOC_FLAGS", "foo") - .with_stderr_contains("[WARNING] Cargo does not read `RUSTDOC_FLAGS` environment variable. Did you mean `RUSTDOCFLAGS`?") + .with_stderr_data(str![[r#" +[WARNING] Cargo does not read `RUSTDOC_FLAGS` environment variable. Did you mean `RUSTDOCFLAGS`? +[DOCUMENTING] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s +[GENERATED] [ROOT]/foo/target/doc/foo/index.html + +"#]]) .run(); } @@ -114,7 +137,13 @@ fn whitespace() { // "too many operands" p.cargo("doc") .env("RUSTDOCFLAGS", "--crate-version this has spaces") - .with_stderr_contains("[ERROR] could not document `foo`") + .with_stderr_data(str![[r#" +[DOCUMENTING] foo v0.0.1 ([ROOT]/foo) +[ERROR] too many file operands + +[ERROR] could not document `foo` + +"#]]) .with_status(101) .run(); @@ -155,12 +184,30 @@ fn not_affected_by_target_rustflags() { // `cargo build` should fail due to missing docs. p.cargo("build -v") .with_status(101) - .with_stderr_contains("[RUNNING] `rustc [..] -D missing-docs[..]`") + .with_stderr_data(str![[r#" +[COMPILING] foo v0.0.1 ([ROOT]/foo) +[RUNNING] `rustc [..] -D missing-docs` +[ERROR] missing documentation for the crate + | + = [NOTE] requested on the command line with `-D missing-docs` + +[ERROR] could not compile `foo` (lib) due to 1 previous error + +Caused by: + process didn't exit successfully: `rustc [..] -D missing-docs` ([EXIT_STATUS]: 1) + +"#]]) .run(); // `cargo doc` shouldn't fail. p.cargo("doc -v") - .with_stderr_contains("[RUNNING] `rustdoc [..] --cfg foo[..]`") + .with_stderr_data(str![[r#" +[DOCUMENTING] foo v0.0.1 ([ROOT]/foo) +[RUNNING] `rustdoc [..] --cfg foo [..]` +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s +[GENERATED] [ROOT]/foo/target/doc/foo/index.html + +"#]]) .run(); } @@ -176,14 +223,27 @@ fn target_triple_rustdocflags_works() { &format!("CARGO_TARGET_{host_env}_RUSTDOCFLAGS"), "--cfg=foo", ) - .with_stderr_contains("[RUNNING] `rustdoc[..]--cfg[..]foo[..]`") + .with_stderr_data(str![[r#" +[DOCUMENTING] foo v0.0.1 ([ROOT]/foo) +[RUNNING] `rustdoc [..] --cfg=foo [..]` +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s +[GENERATED] [ROOT]/foo/target/doc/foo/index.html + +"#]]) .run(); // target.triple.rustdocflags in config works p.cargo("doc -v") .arg("--config") .arg(format!("target.{host}.rustdocflags=['--cfg', 'foo']")) - .with_stderr_contains("[RUNNING] `rustdoc[..]--cfg[..]foo[..]`") + .with_stderr_data(str![[r#" +[DIRTY] foo v0.0.1 ([ROOT]/foo): the rustflags changed +[DOCUMENTING] foo v0.0.1 ([ROOT]/foo) +[RUNNING] `rustdoc [..] --cfg foo [..]` +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s +[GENERATED] [ROOT]/foo/target/doc/foo/index.html + +"#]]) .run(); } @@ -208,27 +268,26 @@ fn target_triple_rustdocflags_works_through_cargo_test() { &format!("CARGO_TARGET_{host_env}_RUSTDOCFLAGS"), "--cfg=foo", ) - .with_stderr_contains("[RUNNING] `rustdoc[..]--test[..]--cfg[..]foo[..]`") - .with_stdout_contains( - "\ -running 1 test -test src/lib.rs - (line 2) ... ok - -test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out[..]", - ) + .with_stderr_data(str![[r#" +[COMPILING] foo v0.0.1 ([ROOT]/foo) +[RUNNING] `rustc [..]` +[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s +[DOCTEST] foo +[RUNNING] `rustdoc [..] --test src/lib.rs [..] --cfg=foo [..]` + +"#]]) .run(); // target.triple.rustdocflags in config works p.cargo("test --doc -v") .arg("--config") .arg(format!("target.{host}.rustdocflags=['--cfg', 'foo']")) - .with_stderr_contains("[RUNNING] `rustdoc[..]--test[..]--cfg[..]foo[..]`") - .with_stdout_contains( - "\ -running 1 test -test src/lib.rs - (line 2) ... ok + .with_stderr_data(str![[r#" +[FRESH] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s +[DOCTEST] foo +[RUNNING] `rustdoc [..] --test src/lib.rs [..] --cfg foo [..]` -test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out[..]", - ) +"#]]) .run(); }