2019-11-25 02:42:45 +00:00
|
|
|
//! Tests for the `cargo rustdoc` command.
|
|
|
|
|
2020-07-18 15:37:04 +00:00
|
|
|
use cargo_test_support::{basic_manifest, cross_compile, project};
|
2015-09-09 08:46:43 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn rustdoc_simple() {
|
2018-08-28 09:20:03 +00:00
|
|
|
let p = project().file("src/lib.rs", "").build();
|
2015-09-09 08:46:43 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("rustdoc -v")
|
2018-09-03 09:38:29 +00:00
|
|
|
.with_stderr(
|
2018-03-14 15:17:44 +00:00
|
|
|
"\
|
2018-09-08 02:42:26 +00:00
|
|
|
[DOCUMENTING] foo v0.0.1 ([CWD])
|
2019-09-12 17:38:10 +00:00
|
|
|
[RUNNING] `rustdoc [..]--crate-name foo src/lib.rs [..]\
|
2018-09-08 02:42:26 +00:00
|
|
|
-o [CWD]/target/doc \
|
2019-07-17 19:41:27 +00:00
|
|
|
[..] \
|
2020-07-18 15:37:04 +00:00
|
|
|
-L dependency=[CWD]/target/debug/deps [..]`
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2023-10-19 15:40:49 +00:00
|
|
|
[GENERATED] [CWD]/target/doc/foo/index.html
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-09-09 08:46:43 +00:00
|
|
|
|
2023-06-10 18:22:12 +00:00
|
|
|
#[cargo_test]
|
|
|
|
fn rustdoc_simple_html() {
|
|
|
|
let p = project().file("src/lib.rs", "").build();
|
|
|
|
|
|
|
|
p.cargo("rustdoc --output-format html --open -v")
|
|
|
|
.with_status(101)
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
|
|
|
error: the `--output-format` flag is unstable, and only available on the nightly channel of Cargo, but this is the `stable` channel
|
|
|
|
[..]
|
|
|
|
See https://github.com/rust-lang/cargo/issues/12103 for more information about the `--output-format` flag.
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test(nightly, reason = "--output-format is unstable")]
|
|
|
|
fn rustdoc_simple_json() {
|
|
|
|
let p = project().file("src/lib.rs", "").build();
|
|
|
|
|
|
|
|
p.cargo("rustdoc -Z unstable-options --output-format json -v")
|
|
|
|
.masquerade_as_nightly_cargo(&["rustdoc-output-format"])
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
|
|
|
[DOCUMENTING] foo v0.0.1 ([CWD])
|
|
|
|
[RUNNING] `rustdoc [..]--crate-name foo [..]-o [CWD]/target/doc [..]--output-format=json[..]
|
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2024-01-19 00:42:48 +00:00
|
|
|
[GENERATED] [CWD]/target/doc/foo.json
|
2023-06-10 18:22:12 +00:00
|
|
|
",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
assert!(p.root().join("target/doc/foo.json").is_file());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn rustdoc_invalid_output_format() {
|
|
|
|
let p = project().file("src/lib.rs", "").build();
|
|
|
|
|
|
|
|
p.cargo("rustdoc -Z unstable-options --output-format pdf -v")
|
|
|
|
.masquerade_as_nightly_cargo(&["rustdoc-output-format"])
|
|
|
|
.with_status(1)
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
|
|
|
error: invalid value 'pdf' for '--output-format <FMT>'
|
|
|
|
[possible values: html, json]
|
|
|
|
|
|
|
|
For more information, try '--help'.
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn rustdoc_json_stable() {
|
|
|
|
let p = project().file("src/lib.rs", "").build();
|
|
|
|
|
|
|
|
p.cargo("rustdoc -Z unstable-options --output-format json -v")
|
|
|
|
.with_status(101)
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
|
|
|
error: the `-Z` flag is only accepted on the nightly channel of Cargo, but this is the `stable` channel
|
|
|
|
[..]
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn rustdoc_json_without_unstable_options() {
|
|
|
|
let p = project().file("src/lib.rs", "").build();
|
|
|
|
|
|
|
|
p.cargo("rustdoc --output-format json -v")
|
|
|
|
.masquerade_as_nightly_cargo(&["rustdoc-output-format"])
|
|
|
|
.with_status(101)
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
|
|
|
error: the `--output-format` flag is unstable, pass `-Z unstable-options` to enable it
|
|
|
|
[..]
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn rustdoc_args() {
|
2018-08-28 09:20:03 +00:00
|
|
|
let p = project().file("src/lib.rs", "").build();
|
2015-09-09 08:46:43 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("rustdoc -v -- --cfg=foo")
|
2018-09-03 09:38:29 +00:00
|
|
|
.with_stderr(
|
2018-03-14 15:17:44 +00:00
|
|
|
"\
|
2018-09-08 02:42:26 +00:00
|
|
|
[DOCUMENTING] foo v0.0.1 ([CWD])
|
2019-09-12 17:38:10 +00:00
|
|
|
[RUNNING] `rustdoc [..]--crate-name foo src/lib.rs [..]\
|
2018-09-08 02:42:26 +00:00
|
|
|
-o [CWD]/target/doc \
|
2019-07-17 19:41:27 +00:00
|
|
|
[..] \
|
2017-08-30 14:50:40 +00:00
|
|
|
--cfg=foo \
|
2021-10-13 02:33:23 +00:00
|
|
|
-C metadata=[..] \
|
2020-07-18 15:37:04 +00:00
|
|
|
-L dependency=[CWD]/target/debug/deps [..]`
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2023-10-19 15:40:49 +00:00
|
|
|
[GENERATED] [CWD]/target/doc/foo/index.html
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-09-09 08:46:43 +00:00
|
|
|
|
2020-07-04 02:09:31 +00:00
|
|
|
#[cargo_test]
|
|
|
|
fn rustdoc_binary_args_passed() {
|
|
|
|
let p = project().file("src/main.rs", "").build();
|
|
|
|
|
|
|
|
p.cargo("rustdoc -v")
|
|
|
|
.arg("--")
|
2020-07-04 19:04:44 +00:00
|
|
|
.arg("--markdown-no-toc")
|
|
|
|
.with_stderr_contains("[RUNNING] `rustdoc [..] --markdown-no-toc[..]`")
|
2020-07-04 02:09:31 +00:00
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn rustdoc_foo_with_bar_dependency() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let foo = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dependencies.bar]
|
|
|
|
path = "../bar"
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("src/lib.rs", "extern crate bar; pub fn foo() {}")
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2018-08-28 09:20:03 +00:00
|
|
|
let _bar = project()
|
|
|
|
.at("bar")
|
2018-07-24 22:35:01 +00:00
|
|
|
.file("Cargo.toml", &basic_manifest("bar", "0.0.1"))
|
2018-07-25 00:30:32 +00:00
|
|
|
.file("src/lib.rs", "pub fn baz() {}")
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2015-09-09 08:46:43 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
foo.cargo("rustdoc -v -- --cfg=foo")
|
2018-09-03 09:38:29 +00:00
|
|
|
.with_stderr(
|
2018-03-14 15:17:44 +00:00
|
|
|
"\
|
2018-04-19 18:19:11 +00:00
|
|
|
[CHECKING] bar v0.0.1 ([..])
|
2018-08-02 09:18:48 +00:00
|
|
|
[RUNNING] `rustc [..]bar/src/lib.rs [..]`
|
2018-09-08 02:42:26 +00:00
|
|
|
[DOCUMENTING] foo v0.0.1 ([CWD])
|
2019-09-12 17:38:10 +00:00
|
|
|
[RUNNING] `rustdoc [..]--crate-name foo src/lib.rs [..]\
|
2018-09-08 02:42:26 +00:00
|
|
|
-o [CWD]/target/doc \
|
2019-07-17 19:41:27 +00:00
|
|
|
[..] \
|
2017-08-30 14:50:40 +00:00
|
|
|
--cfg=foo \
|
2021-10-13 02:33:23 +00:00
|
|
|
-C metadata=[..] \
|
2018-09-08 02:42:26 +00:00
|
|
|
-L dependency=[CWD]/target/debug/deps \
|
2015-09-09 08:46:43 +00:00
|
|
|
--extern [..]`
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2023-10-19 15:40:49 +00:00
|
|
|
[GENERATED] [CWD]/target/doc/foo/index.html
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-09-09 08:46:43 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn rustdoc_only_bar_dependency() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let foo = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dependencies.bar]
|
|
|
|
path = "../bar"
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("src/main.rs", "extern crate bar; fn main() { bar::baz() }")
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2018-08-28 09:20:03 +00:00
|
|
|
let _bar = project()
|
|
|
|
.at("bar")
|
2018-07-24 22:35:01 +00:00
|
|
|
.file("Cargo.toml", &basic_manifest("bar", "0.0.1"))
|
2018-07-25 00:30:32 +00:00
|
|
|
.file("src/lib.rs", "pub fn baz() {}")
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2015-09-09 08:46:43 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
foo.cargo("rustdoc -v -p bar -- --cfg=foo")
|
2018-09-03 09:38:29 +00:00
|
|
|
.with_stderr(
|
2018-03-14 15:17:44 +00:00
|
|
|
"\
|
2016-05-11 16:55:43 +00:00
|
|
|
[DOCUMENTING] bar v0.0.1 ([..])
|
2019-09-12 17:38:10 +00:00
|
|
|
[RUNNING] `rustdoc [..]--crate-name bar [..]bar/src/lib.rs [..]\
|
2018-09-08 02:42:26 +00:00
|
|
|
-o [CWD]/target/doc \
|
2019-07-17 19:41:27 +00:00
|
|
|
[..] \
|
2017-08-30 14:50:40 +00:00
|
|
|
--cfg=foo \
|
2021-10-13 02:33:23 +00:00
|
|
|
-C metadata=[..] \
|
2020-07-18 15:37:04 +00:00
|
|
|
-L dependency=[CWD]/target/debug/deps [..]`
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2023-10-19 15:40:49 +00:00
|
|
|
[GENERATED] [CWD]/target/doc/bar/index.html
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-09-09 08:46:43 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2017-10-16 16:30:57 +00:00
|
|
|
fn rustdoc_same_name_documents_lib() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-07-25 00:30:32 +00:00
|
|
|
.file("src/main.rs", "fn main() {}")
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/lib.rs", r#" "#)
|
|
|
|
.build();
|
2015-09-09 08:46:43 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("rustdoc -v -- --cfg=foo")
|
2018-09-03 09:38:29 +00:00
|
|
|
.with_stderr(
|
2018-03-14 15:17:44 +00:00
|
|
|
"\
|
2017-10-16 16:30:57 +00:00
|
|
|
[DOCUMENTING] foo v0.0.1 ([..])
|
2019-09-12 17:38:10 +00:00
|
|
|
[RUNNING] `rustdoc [..]--crate-name foo src/lib.rs [..]\
|
2018-09-08 02:42:26 +00:00
|
|
|
-o [CWD]/target/doc \
|
2019-07-17 19:41:27 +00:00
|
|
|
[..] \
|
2017-10-16 16:30:57 +00:00
|
|
|
--cfg=foo \
|
2021-10-13 02:33:23 +00:00
|
|
|
-C metadata=[..] \
|
2020-07-18 15:37:04 +00:00
|
|
|
-L dependency=[CWD]/target/debug/deps [..]`
|
2017-10-16 16:30:57 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2023-10-19 15:40:49 +00:00
|
|
|
[GENERATED] [CWD]/target/doc/foo/index.html
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2018-03-27 22:56:46 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-03-27 22:56:46 +00:00
|
|
|
fn features() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-27 22:56:46 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[features]
|
|
|
|
quux = []
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("src/lib.rs", "")
|
2018-03-27 22:56:46 +00:00
|
|
|
.build();
|
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("rustdoc --verbose --features quux")
|
|
|
|
.with_stderr_contains("[..]feature=[..]quux[..]")
|
|
|
|
.run();
|
2018-03-27 22:56:46 +00:00
|
|
|
}
|
2018-05-28 14:27:52 +00:00
|
|
|
|
2019-09-12 17:38:10 +00:00
|
|
|
#[cargo_test]
|
|
|
|
fn proc_macro_crate_type() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2019-09-12 17:38:10 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[lib]
|
|
|
|
proc-macro = true
|
2019-09-12 17:38:10 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
"#,
|
2019-09-12 17:38:10 +00:00
|
|
|
)
|
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("rustdoc --verbose")
|
|
|
|
.with_stderr_contains(
|
|
|
|
"\
|
|
|
|
[RUNNING] `rustdoc --crate-type proc-macro [..]`
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-05-28 14:27:52 +00:00
|
|
|
fn rustdoc_target() {
|
2020-07-18 15:37:04 +00:00
|
|
|
if cross_compile::disabled() {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
let p = project().file("src/lib.rs", "").build();
|
2018-05-28 14:27:52 +00:00
|
|
|
|
2020-07-18 15:37:04 +00:00
|
|
|
p.cargo("rustdoc --verbose --target")
|
|
|
|
.arg(cross_compile::alternate())
|
|
|
|
.with_stderr(format!(
|
2018-08-28 09:20:03 +00:00
|
|
|
"\
|
2018-07-24 13:01:56 +00:00
|
|
|
[DOCUMENTING] foo v0.0.1 ([..])
|
2019-09-12 17:38:10 +00:00
|
|
|
[RUNNING] `rustdoc [..]--crate-name foo src/lib.rs [..]\
|
2020-07-18 15:37:04 +00:00
|
|
|
--target {target} \
|
|
|
|
-o [CWD]/target/{target}/doc \
|
2019-07-17 19:41:27 +00:00
|
|
|
[..] \
|
2020-07-18 15:37:04 +00:00
|
|
|
-L dependency=[CWD]/target/{target}/debug/deps \
|
|
|
|
-L dependency=[CWD]/target/debug/deps[..]`
|
2023-10-19 15:40:49 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
|
|
|
[GENERATED] [CWD]/target/[..]/doc/foo/index.html",
|
2020-07-18 15:37:04 +00:00
|
|
|
target = cross_compile::alternate()
|
|
|
|
))
|
2018-12-08 11:19:47 +00:00
|
|
|
.run();
|
2018-05-28 14:27:52 +00:00
|
|
|
}
|
2020-10-04 15:28:22 +00:00
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn fail_with_glob() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2020-10-09 23:44:57 +00:00
|
|
|
[workspace]
|
|
|
|
members = ["bar"]
|
|
|
|
"#,
|
2020-10-04 15:28:22 +00:00
|
|
|
)
|
|
|
|
.file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0"))
|
|
|
|
.file("bar/src/lib.rs", "pub fn bar() { break_the_build(); }")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("rustdoc -p '*z'")
|
|
|
|
.with_status(101)
|
|
|
|
.with_stderr("[ERROR] Glob patterns on package selection are not supported.")
|
|
|
|
.run();
|
|
|
|
}
|