2019-11-25 02:42:45 +00:00
|
|
|
//! Tests for setting custom rustdoc flags.
|
|
|
|
|
2019-09-12 17:14:29 +00:00
|
|
|
use cargo_test_support::project;
|
2023-12-23 05:37:43 +00:00
|
|
|
use cargo_test_support::rustc_host;
|
|
|
|
use cargo_test_support::rustc_host_env;
|
2024-06-18 15:59:37 +00:00
|
|
|
use cargo_test_support::str;
|
2016-06-20 16:12:28 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-06-20 16:12:28 +00:00
|
|
|
fn parses_env() {
|
2018-08-28 09:20:03 +00:00
|
|
|
let p = project().file("src/lib.rs", "").build();
|
2016-06-20 16:12:28 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("doc -v")
|
|
|
|
.env("RUSTDOCFLAGS", "--cfg=foo")
|
2024-06-18 15:59:37 +00:00
|
|
|
.with_stderr_data(str![[r#"
|
|
|
|
...
|
|
|
|
[RUNNING] `rustdoc [..] --cfg=foo[..]`
|
|
|
|
...
|
|
|
|
"#]])
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
2016-06-20 16:12:28 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-06-20 16:12:28 +00:00
|
|
|
fn parses_config() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2016-06-20 16:12:28 +00:00
|
|
|
.file("src/lib.rs", "")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
2024-01-26 19:40:46 +00:00
|
|
|
".cargo/config.toml",
|
2018-03-14 15:17:44 +00:00
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[build]
|
|
|
|
rustdocflags = ["--cfg", "foo"]
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2016-06-20 16:12:28 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("doc -v")
|
2024-06-18 15:59:37 +00:00
|
|
|
.with_stderr_data(str![[r#"
|
|
|
|
...
|
|
|
|
[RUNNING] `rustdoc [..] --cfg foo [..]`
|
|
|
|
...
|
|
|
|
"#]])
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
2016-06-20 16:12:28 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-06-20 16:12:28 +00:00
|
|
|
fn bad_flags() {
|
2018-08-28 09:20:03 +00:00
|
|
|
let p = project().file("src/lib.rs", "").build();
|
2016-06-20 16:12:28 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("doc")
|
|
|
|
.env("RUSTDOCFLAGS", "--bogus")
|
|
|
|
.with_status(101)
|
2024-06-18 15:59:37 +00:00
|
|
|
.with_stderr_data(str![[r#"
|
|
|
|
...
|
|
|
|
[ERROR] Unrecognized option: 'bogus'
|
|
|
|
...
|
|
|
|
"#]])
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
2016-06-20 16:12:28 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-06-20 16:12:28 +00:00
|
|
|
fn rerun() {
|
2018-08-28 09:20:03 +00:00
|
|
|
let p = project().file("src/lib.rs", "").build();
|
2016-06-20 16:12:28 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("doc").env("RUSTDOCFLAGS", "--cfg=foo").run();
|
|
|
|
p.cargo("doc")
|
|
|
|
.env("RUSTDOCFLAGS", "--cfg=foo")
|
2024-06-18 15:59:37 +00:00
|
|
|
.with_stderr_data(str![[r#"
|
|
|
|
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
|
|
|
|
[GENERATED] [ROOT]/foo/target/doc/foo/index.html
|
|
|
|
|
|
|
|
"#]])
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
|
|
|
p.cargo("doc")
|
|
|
|
.env("RUSTDOCFLAGS", "--cfg=bar")
|
2024-06-18 15:59:37 +00:00
|
|
|
.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
|
|
|
|
|
|
|
|
"#]])
|
2018-12-08 11:19:47 +00:00
|
|
|
.run();
|
2016-06-20 16:12:28 +00:00
|
|
|
}
|
2017-11-22 13:49:10 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2017-11-22 13:49:10 +00:00
|
|
|
fn rustdocflags_passed_to_rustdoc_through_cargo_test() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
//! ```
|
|
|
|
//! assert!(cfg!(do_not_choke));
|
|
|
|
//! ```
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2017-11-22 13:49:10 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("test --doc")
|
|
|
|
.env("RUSTDOCFLAGS", "--cfg do_not_choke")
|
|
|
|
.run();
|
2017-11-22 13:49:10 +00:00
|
|
|
}
|
2017-12-07 14:13:46 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2017-12-07 14:13:46 +00:00
|
|
|
fn rustdocflags_passed_to_rustdoc_through_cargo_test_only_once() {
|
2018-08-28 09:20:03 +00:00
|
|
|
let p = project().file("src/lib.rs", "").build();
|
2017-12-07 14:13:46 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("test --doc")
|
|
|
|
.env("RUSTDOCFLAGS", "--markdown-no-toc")
|
|
|
|
.run();
|
2017-12-07 14:13:46 +00:00
|
|
|
}
|
2019-02-23 08:07:59 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2019-02-23 08:07:59 +00:00
|
|
|
fn rustdocflags_misspelled() {
|
|
|
|
let p = project().file("src/main.rs", "fn main() { }").build();
|
|
|
|
|
|
|
|
p.cargo("doc")
|
|
|
|
.env("RUSTDOC_FLAGS", "foo")
|
2024-06-18 15:59:37 +00:00
|
|
|
.with_stderr_data(str![[r#"
|
|
|
|
[WARNING] Cargo does not read `RUSTDOC_FLAGS` environment variable. Did you mean `RUSTDOCFLAGS`?
|
|
|
|
...
|
|
|
|
"#]])
|
2019-02-23 08:07:59 +00:00
|
|
|
.run();
|
|
|
|
}
|
2020-09-15 21:22:19 +00:00
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn whitespace() {
|
|
|
|
// Checks behavior of different whitespace characters.
|
|
|
|
let p = project().file("src/lib.rs", "").build();
|
|
|
|
|
|
|
|
// "too many operands"
|
|
|
|
p.cargo("doc")
|
|
|
|
.env("RUSTDOCFLAGS", "--crate-version this has spaces")
|
2024-06-18 15:59:37 +00:00
|
|
|
.with_stderr_data(str![[r#"
|
|
|
|
...
|
|
|
|
[ERROR] could not document `foo`
|
|
|
|
...
|
|
|
|
"#]])
|
2020-09-15 21:22:19 +00:00
|
|
|
.with_status(101)
|
|
|
|
.run();
|
|
|
|
|
|
|
|
p.cargo("doc")
|
2022-04-10 13:16:12 +00:00
|
|
|
.env_remove("__CARGO_TEST_FORCE_ARGFILE") // Not applicable for argfile.
|
2020-09-15 21:22:19 +00:00
|
|
|
.env(
|
|
|
|
"RUSTDOCFLAGS",
|
2023-10-10 17:13:16 +00:00
|
|
|
"--crate-version 1111\n2222\t3333\u{00a0}4444",
|
2020-09-15 21:22:19 +00:00
|
|
|
)
|
|
|
|
.run();
|
|
|
|
|
|
|
|
let contents = p.read_file("target/doc/foo/index.html");
|
2023-10-10 17:13:16 +00:00
|
|
|
assert!(contents.contains("1111"));
|
|
|
|
assert!(contents.contains("2222"));
|
|
|
|
assert!(contents.contains("3333"));
|
|
|
|
assert!(contents.contains("4444"));
|
2020-09-15 21:22:19 +00:00
|
|
|
}
|
2022-11-01 14:56:20 +00:00
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn not_affected_by_target_rustflags() {
|
|
|
|
let cfg = if cfg!(windows) { "windows" } else { "unix" };
|
|
|
|
let p = project()
|
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.file(
|
2024-01-26 19:40:46 +00:00
|
|
|
".cargo/config.toml",
|
2022-11-01 14:56:20 +00:00
|
|
|
&format!(
|
|
|
|
r#"
|
|
|
|
[target.'cfg({cfg})']
|
|
|
|
rustflags = ["-D", "missing-docs"]
|
|
|
|
|
|
|
|
[build]
|
|
|
|
rustdocflags = ["--cfg", "foo"]
|
|
|
|
"#,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
.build();
|
|
|
|
|
|
|
|
// `cargo build` should fail due to missing docs.
|
|
|
|
p.cargo("build -v")
|
|
|
|
.with_status(101)
|
2024-06-18 15:59:37 +00:00
|
|
|
.with_stderr_data(str![[r#"
|
|
|
|
...
|
|
|
|
[RUNNING] `rustc [..] -D missing-docs`
|
|
|
|
...
|
|
|
|
"#]])
|
2022-11-01 14:56:20 +00:00
|
|
|
.run();
|
|
|
|
|
2022-11-01 14:55:03 +00:00
|
|
|
// `cargo doc` shouldn't fail.
|
2022-11-01 14:56:20 +00:00
|
|
|
p.cargo("doc -v")
|
2024-06-18 15:59:37 +00:00
|
|
|
.with_stderr_data(str![[r#"
|
|
|
|
...
|
|
|
|
[RUNNING] `rustdoc [..] --cfg foo[..]`
|
|
|
|
...
|
|
|
|
"#]])
|
2022-11-01 14:56:20 +00:00
|
|
|
.run();
|
|
|
|
}
|
2023-12-23 05:37:43 +00:00
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn target_triple_rustdocflags_works() {
|
|
|
|
let host = rustc_host();
|
|
|
|
let host_env = rustc_host_env();
|
|
|
|
let p = project().file("src/lib.rs", "").build();
|
|
|
|
|
|
|
|
// target.triple.rustdocflags in env works
|
|
|
|
p.cargo("doc -v")
|
|
|
|
.env(
|
|
|
|
&format!("CARGO_TARGET_{host_env}_RUSTDOCFLAGS"),
|
|
|
|
"--cfg=foo",
|
|
|
|
)
|
2024-06-18 15:59:37 +00:00
|
|
|
.with_stderr_data(str![[r#"
|
|
|
|
...
|
|
|
|
[RUNNING] `rustdoc[..]--cfg[..]foo[..]`
|
|
|
|
...
|
|
|
|
"#]])
|
2023-12-23 05:37:43 +00:00
|
|
|
.run();
|
|
|
|
|
2023-12-23 05:39:32 +00:00
|
|
|
// target.triple.rustdocflags in config works
|
2023-12-23 05:37:43 +00:00
|
|
|
p.cargo("doc -v")
|
|
|
|
.arg("--config")
|
|
|
|
.arg(format!("target.{host}.rustdocflags=['--cfg', 'foo']"))
|
2024-06-18 15:59:37 +00:00
|
|
|
.with_stderr_data(str![[r#"
|
|
|
|
...
|
|
|
|
[RUNNING] `rustdoc [..] --cfg foo [..]`
|
|
|
|
...
|
|
|
|
"#]])
|
2023-12-23 05:37:43 +00:00
|
|
|
.run();
|
|
|
|
}
|
2023-12-24 03:55:55 +00:00
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn target_triple_rustdocflags_works_through_cargo_test() {
|
|
|
|
let host = rustc_host();
|
|
|
|
let host_env = rustc_host_env();
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
|
|
|
//! ```
|
|
|
|
//! assert!(cfg!(foo));
|
|
|
|
//! ```
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.build();
|
|
|
|
|
|
|
|
// target.triple.rustdocflags in env works
|
|
|
|
p.cargo("test --doc -v")
|
|
|
|
.env(
|
|
|
|
&format!("CARGO_TARGET_{host_env}_RUSTDOCFLAGS"),
|
|
|
|
"--cfg=foo",
|
|
|
|
)
|
2024-06-18 15:59:37 +00:00
|
|
|
.with_stderr_data(str![[r#"
|
|
|
|
...
|
|
|
|
[RUNNING] `rustdoc[..]--test[..]--cfg[..]foo[..]`
|
|
|
|
|
|
|
|
"#]])
|
|
|
|
.with_stdout_data(str![[r#"
|
|
|
|
|
2023-12-24 03:55:55 +00:00
|
|
|
running 1 test
|
|
|
|
test src/lib.rs - (line 2) ... ok
|
|
|
|
|
2024-06-18 15:59:37 +00:00
|
|
|
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in [ELAPSED]s
|
|
|
|
|
|
|
|
|
|
|
|
"#]])
|
2023-12-24 03:55:55 +00:00
|
|
|
.run();
|
|
|
|
|
|
|
|
// target.triple.rustdocflags in config works
|
|
|
|
p.cargo("test --doc -v")
|
|
|
|
.arg("--config")
|
|
|
|
.arg(format!("target.{host}.rustdocflags=['--cfg', 'foo']"))
|
2024-06-18 15:59:37 +00:00
|
|
|
.with_stderr_data(str![[r#"
|
|
|
|
...
|
|
|
|
[RUNNING] `rustdoc[..]--test[..]--cfg[..]foo[..]`
|
|
|
|
|
|
|
|
"#]])
|
|
|
|
.with_stdout_data(str![[r#"
|
|
|
|
|
2023-12-24 03:55:55 +00:00
|
|
|
running 1 test
|
|
|
|
test src/lib.rs - (line 2) ... ok
|
|
|
|
|
2024-06-18 15:59:37 +00:00
|
|
|
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in [ELAPSED]s
|
|
|
|
|
|
|
|
|
|
|
|
"#]])
|
2023-12-24 03:55:55 +00:00
|
|
|
.run();
|
|
|
|
}
|