Skip to content

Commit

Permalink
test: migrate rustdocflags to snapbox
Browse files Browse the repository at this point in the history
  • Loading branch information
eth3lbert committed Jun 18, 2024
1 parent ce493b0 commit 33e0634
Showing 1 changed file with 96 additions and 37 deletions.
133 changes: 96 additions & 37 deletions tests/testsuite/rustdocflags.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
//! 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() {
let p = project().file("src/lib.rs", "").build();

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();
}

Expand All @@ -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();
}

Expand All @@ -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();
}

Expand All @@ -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();
}

Expand Down Expand Up @@ -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();
}

Expand All @@ -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();

Expand Down Expand Up @@ -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();
}

Expand All @@ -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();
}

Expand All @@ -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();
}

0 comments on commit 33e0634

Please sign in to comment.