2017-10-16 16:30:57 +00:00
|
|
|
use std::fs::{self, File};
|
|
|
|
use std::io::Read;
|
2018-08-28 09:20:03 +00:00
|
|
|
use std::str;
|
2015-09-08 17:39:15 +00:00
|
|
|
|
2019-09-12 17:14:29 +00:00
|
|
|
use cargo_test_support::paths::CargoPathExt;
|
|
|
|
use cargo_test_support::registry::Package;
|
|
|
|
use cargo_test_support::{basic_lib_manifest, basic_manifest, git, project};
|
|
|
|
use cargo_test_support::{is_nightly, rustc_host};
|
2014-07-22 15:06:36 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn simple() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-07-22 15:06:36 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2015-01-19 22:27:51 +00:00
|
|
|
build = "build.rs"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("build.rs", "fn main() {}")
|
2018-07-25 00:30:32 +00:00
|
|
|
.file("src/lib.rs", "pub fn foo() {}")
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2014-07-22 15:06:36 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("doc")
|
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
|
|
|
[..] foo v0.0.1 ([CWD])
|
|
|
|
[..] foo v0.0.1 ([CWD])
|
2017-01-18 19:37:52 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2014-07-22 15:06:36 +00:00
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.run();
|
2018-08-29 05:53:01 +00:00
|
|
|
assert!(p.root().join("target/doc").is_dir());
|
2018-08-29 06:11:10 +00:00
|
|
|
assert!(p.root().join("target/doc/foo/index.html").is_file());
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-07-22 15:06:36 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn doc_no_libs() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-07-22 15:06:36 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
2014-08-04 14:21:31 +00:00
|
|
|
[[bin]]
|
2014-07-22 15:06:36 +00:00
|
|
|
name = "foo"
|
2014-08-04 14:21:31 +00:00
|
|
|
doc = false
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("src/main.rs", "bad code")
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2014-07-22 15:06:36 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("doc").run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-07-22 15:06:36 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn doc_twice() {
|
2018-08-28 09:20:03 +00:00
|
|
|
let p = project().file("src/lib.rs", "pub fn foo() {}").build();
|
2014-07-22 15:06:36 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("doc")
|
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])
|
2017-01-18 19:37:52 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2014-07-22 15:06:36 +00:00
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.run();
|
2014-07-22 15:06:36 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("doc").with_stdout("").run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-07-22 15:06:36 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn doc_deps() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-07-22 15:06:36 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dependencies.bar]
|
|
|
|
path = "bar"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("src/lib.rs", "extern crate bar; pub fn foo() {}")
|
2018-07-24 22:35:01 +00:00
|
|
|
.file("bar/Cargo.toml", &basic_manifest("bar", "0.0.1"))
|
2018-07-25 00:30:32 +00:00
|
|
|
.file("bar/src/lib.rs", "pub fn bar() {}")
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2014-07-22 15:06:36 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("doc")
|
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
|
|
|
[..] bar v0.0.1 ([CWD]/bar)
|
|
|
|
[..] bar v0.0.1 ([CWD]/bar)
|
|
|
|
[DOCUMENTING] foo v0.0.1 ([CWD])
|
2017-01-18 19:37:52 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2014-07-22 15:06:36 +00:00
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.run();
|
2014-07-22 15:06:36 +00:00
|
|
|
|
2018-08-29 05:53:01 +00:00
|
|
|
assert!(p.root().join("target/doc").is_dir());
|
2018-08-29 06:11:10 +00:00
|
|
|
assert!(p.root().join("target/doc/foo/index.html").is_file());
|
|
|
|
assert!(p.root().join("target/doc/bar/index.html").is_file());
|
2014-07-29 03:09:07 +00:00
|
|
|
|
2018-04-18 01:46:44 +00:00
|
|
|
// Verify that it only emits rmeta for the dependency.
|
2019-03-26 20:21:05 +00:00
|
|
|
assert_eq!(p.glob("target/debug/**/*.rlib").count(), 0);
|
|
|
|
assert_eq!(p.glob("target/debug/deps/libbar-*.rmeta").count(), 1);
|
2018-04-18 01:46:44 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("doc")
|
2019-01-27 18:34:11 +00:00
|
|
|
.env("CARGO_LOG", "cargo::ops::cargo_rustc::fingerprint")
|
2018-08-28 09:20:03 +00:00
|
|
|
.with_stdout("")
|
|
|
|
.run();
|
2014-07-29 03:09:07 +00:00
|
|
|
|
2018-08-29 05:53:01 +00:00
|
|
|
assert!(p.root().join("target/doc").is_dir());
|
2018-08-29 06:11:10 +00:00
|
|
|
assert!(p.root().join("target/doc/foo/index.html").is_file());
|
|
|
|
assert!(p.root().join("target/doc/bar/index.html").is_file());
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-07-22 15:06:36 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn doc_no_deps() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-07-22 15:06:36 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dependencies.bar]
|
|
|
|
path = "bar"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("src/lib.rs", "extern crate bar; pub fn foo() {}")
|
2018-07-24 22:35:01 +00:00
|
|
|
.file("bar/Cargo.toml", &basic_manifest("bar", "0.0.1"))
|
2018-07-25 00:30:32 +00:00
|
|
|
.file("bar/src/lib.rs", "pub fn bar() {}")
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2014-07-22 15:06:36 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("doc --no-deps")
|
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
|
|
|
[CHECKING] bar v0.0.1 ([CWD]/bar)
|
|
|
|
[DOCUMENTING] foo v0.0.1 ([CWD])
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2014-07-22 15:06:36 +00:00
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.run();
|
2014-07-22 15:06:36 +00:00
|
|
|
|
2018-08-29 05:53:01 +00:00
|
|
|
assert!(p.root().join("target/doc").is_dir());
|
2018-08-29 06:11:10 +00:00
|
|
|
assert!(p.root().join("target/doc/foo/index.html").is_file());
|
|
|
|
assert!(!p.root().join("target/doc/bar/index.html").is_file());
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-07-22 15:06:36 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn doc_only_bin() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-07-22 15:06:36 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dependencies.bar]
|
|
|
|
path = "bar"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("src/main.rs", "extern crate bar; pub fn foo() {}")
|
2018-07-24 22:35:01 +00:00
|
|
|
.file("bar/Cargo.toml", &basic_manifest("bar", "0.0.1"))
|
2018-07-25 00:30:32 +00:00
|
|
|
.file("bar/src/lib.rs", "pub fn bar() {}")
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2014-07-22 15:06:36 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("doc -v").run();
|
2014-07-22 15:06:36 +00:00
|
|
|
|
2018-08-29 05:53:01 +00:00
|
|
|
assert!(p.root().join("target/doc").is_dir());
|
2018-08-29 06:11:10 +00:00
|
|
|
assert!(p.root().join("target/doc/bar/index.html").is_file());
|
|
|
|
assert!(p.root().join("target/doc/foo/index.html").is_file());
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-08-04 14:21:31 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2017-09-29 11:46:31 +00:00
|
|
|
fn doc_multiple_targets_same_name_lib() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-09-29 11:46:31 +00:00
|
|
|
[workspace]
|
|
|
|
members = ["foo", "bar"]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-08-28 09:20:03 +00:00
|
|
|
"foo/Cargo.toml",
|
2018-03-14 15:17:44 +00:00
|
|
|
r#"
|
2017-09-29 11:46:31 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
[lib]
|
|
|
|
name = "foo_lib"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("foo/src/lib.rs", "")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"bar/Cargo.toml",
|
|
|
|
r#"
|
2017-09-29 11:46:31 +00:00
|
|
|
[package]
|
|
|
|
name = "bar"
|
|
|
|
version = "0.1.0"
|
|
|
|
[lib]
|
|
|
|
name = "foo_lib"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("bar/src/lib.rs", "")
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2017-09-29 11:46:31 +00:00
|
|
|
|
2019-09-04 00:47:12 +00:00
|
|
|
p.cargo("doc --workspace")
|
2018-08-28 09:20:03 +00:00
|
|
|
.with_status(101)
|
|
|
|
.with_stderr_contains("[..] library `foo_lib` is specified [..]")
|
|
|
|
.with_stderr_contains("[..] `foo v0.1.0[..]` [..]")
|
|
|
|
.with_stderr_contains("[..] `bar v0.1.0[..]` [..]")
|
|
|
|
.run();
|
2017-09-29 11:46:31 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2017-09-29 11:46:31 +00:00
|
|
|
fn doc_multiple_targets_same_name() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-09-29 11:46:31 +00:00
|
|
|
[workspace]
|
|
|
|
members = ["foo", "bar"]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"foo/Cargo.toml",
|
|
|
|
r#"
|
2017-09-29 11:46:31 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
[[bin]]
|
|
|
|
name = "foo_lib"
|
2017-10-16 16:30:57 +00:00
|
|
|
path = "src/foo_lib.rs"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("foo/src/foo_lib.rs", "")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"bar/Cargo.toml",
|
|
|
|
r#"
|
2017-09-29 11:46:31 +00:00
|
|
|
[package]
|
|
|
|
name = "bar"
|
|
|
|
version = "0.1.0"
|
|
|
|
[lib]
|
|
|
|
name = "foo_lib"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("bar/src/lib.rs", "")
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2017-09-29 11:46:31 +00:00
|
|
|
|
2019-09-04 00:47:12 +00:00
|
|
|
p.cargo("doc --workspace")
|
2018-09-08 02:42:26 +00:00
|
|
|
.with_stderr_contains("[DOCUMENTING] foo v0.1.0 ([CWD]/foo)")
|
|
|
|
.with_stderr_contains("[DOCUMENTING] bar v0.1.0 ([CWD]/bar)")
|
2018-08-28 09:20:03 +00:00
|
|
|
.with_stderr_contains("[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]")
|
|
|
|
.run();
|
2018-08-29 05:53:01 +00:00
|
|
|
assert!(p.root().join("target/doc").is_dir());
|
2018-03-14 15:17:44 +00:00
|
|
|
let doc_file = p.root().join("target/doc/foo_lib/index.html");
|
2018-08-29 06:11:10 +00:00
|
|
|
assert!(doc_file.is_file());
|
2017-09-29 11:46:31 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2017-09-29 11:46:31 +00:00
|
|
|
fn doc_multiple_targets_same_name_bin() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-09-29 11:46:31 +00:00
|
|
|
[workspace]
|
|
|
|
members = ["foo", "bar"]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"foo/Cargo.toml",
|
|
|
|
r#"
|
2017-09-29 11:46:31 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
[[bin]]
|
|
|
|
name = "foo-cli"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("foo/src/foo-cli.rs", "")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"bar/Cargo.toml",
|
|
|
|
r#"
|
2017-09-29 11:46:31 +00:00
|
|
|
[package]
|
|
|
|
name = "bar"
|
|
|
|
version = "0.1.0"
|
|
|
|
[[bin]]
|
|
|
|
name = "foo-cli"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("bar/src/foo-cli.rs", "")
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2017-09-29 11:46:31 +00:00
|
|
|
|
2019-09-04 00:47:12 +00:00
|
|
|
p.cargo("doc --workspace")
|
2018-08-28 09:20:03 +00:00
|
|
|
.with_status(101)
|
|
|
|
.with_stderr_contains("[..] binary `foo_cli` is specified [..]")
|
|
|
|
.with_stderr_contains("[..] `foo v0.1.0[..]` [..]")
|
|
|
|
.with_stderr_contains("[..] `bar v0.1.0[..]` [..]")
|
|
|
|
.run();
|
2017-09-29 11:46:31 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2017-09-29 11:46:31 +00:00
|
|
|
fn doc_multiple_targets_same_name_undoced() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-09-29 11:46:31 +00:00
|
|
|
[workspace]
|
|
|
|
members = ["foo", "bar"]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"foo/Cargo.toml",
|
|
|
|
r#"
|
2017-09-29 11:46:31 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
[[bin]]
|
|
|
|
name = "foo-cli"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("foo/src/foo-cli.rs", "")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"bar/Cargo.toml",
|
|
|
|
r#"
|
2017-09-29 11:46:31 +00:00
|
|
|
[package]
|
|
|
|
name = "bar"
|
|
|
|
version = "0.1.0"
|
|
|
|
[[bin]]
|
|
|
|
name = "foo-cli"
|
|
|
|
doc = false
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("bar/src/foo-cli.rs", "")
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2017-09-29 11:46:31 +00:00
|
|
|
|
2019-09-04 00:47:12 +00:00
|
|
|
p.cargo("doc --workspace").run();
|
2017-09-29 11:46:31 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2017-10-16 16:30:57 +00:00
|
|
|
fn doc_lib_bin_same_name_documents_lib() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
r#"
|
2017-10-16 16:30:57 +00:00
|
|
|
//! Binary documentation
|
|
|
|
extern crate foo;
|
|
|
|
fn main() {
|
|
|
|
foo::foo();
|
|
|
|
}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2017-10-16 16:30:57 +00:00
|
|
|
//! Library documentation
|
|
|
|
pub fn foo() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2014-08-04 14:21:31 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("doc")
|
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])
|
2017-10-16 20:05:47 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.run();
|
2018-08-29 05:53:01 +00:00
|
|
|
assert!(p.root().join("target/doc").is_dir());
|
2017-10-16 20:05:47 +00:00
|
|
|
let doc_file = p.root().join("target/doc/foo/index.html");
|
2018-08-29 06:11:10 +00:00
|
|
|
assert!(doc_file.is_file());
|
2017-10-16 20:05:47 +00:00
|
|
|
let mut doc_html = String::new();
|
2018-03-14 15:17:44 +00:00
|
|
|
File::open(&doc_file)
|
|
|
|
.unwrap()
|
|
|
|
.read_to_string(&mut doc_html)
|
|
|
|
.unwrap();
|
2017-10-16 20:05:47 +00:00
|
|
|
assert!(doc_html.contains("Library"));
|
|
|
|
assert!(!doc_html.contains("Binary"));
|
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2017-10-16 20:05:47 +00:00
|
|
|
fn doc_lib_bin_same_name_documents_lib_when_requested() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
r#"
|
2017-10-16 20:05:47 +00:00
|
|
|
//! Binary documentation
|
|
|
|
extern crate foo;
|
|
|
|
fn main() {
|
|
|
|
foo::foo();
|
|
|
|
}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2017-10-16 20:05:47 +00:00
|
|
|
//! Library documentation
|
|
|
|
pub fn foo() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2017-10-16 20:05:47 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("doc --lib")
|
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])
|
2017-10-16 16:30:57 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.run();
|
2018-08-29 05:53:01 +00:00
|
|
|
assert!(p.root().join("target/doc").is_dir());
|
2017-10-16 16:30:57 +00:00
|
|
|
let doc_file = p.root().join("target/doc/foo/index.html");
|
2018-08-29 06:11:10 +00:00
|
|
|
assert!(doc_file.is_file());
|
2017-10-16 16:30:57 +00:00
|
|
|
let mut doc_html = String::new();
|
2018-03-14 15:17:44 +00:00
|
|
|
File::open(&doc_file)
|
|
|
|
.unwrap()
|
|
|
|
.read_to_string(&mut doc_html)
|
|
|
|
.unwrap();
|
2017-10-16 16:30:57 +00:00
|
|
|
assert!(doc_html.contains("Library"));
|
|
|
|
assert!(!doc_html.contains("Binary"));
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-11-25 05:34:05 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2017-10-16 20:05:47 +00:00
|
|
|
fn doc_lib_bin_same_name_documents_named_bin_when_requested() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
r#"
|
2017-10-16 20:05:47 +00:00
|
|
|
//! Binary documentation
|
|
|
|
extern crate foo;
|
|
|
|
fn main() {
|
|
|
|
foo::foo();
|
|
|
|
}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2017-10-16 20:05:47 +00:00
|
|
|
//! Library documentation
|
|
|
|
pub fn foo() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2017-10-16 20:05:47 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("doc --bin 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
|
|
|
[CHECKING] foo v0.0.1 ([CWD])
|
|
|
|
[DOCUMENTING] foo v0.0.1 ([CWD])
|
2017-10-16 20:05:47 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.run();
|
2018-08-29 05:53:01 +00:00
|
|
|
assert!(p.root().join("target/doc").is_dir());
|
2017-10-16 20:05:47 +00:00
|
|
|
let doc_file = p.root().join("target/doc/foo/index.html");
|
2018-08-29 06:11:10 +00:00
|
|
|
assert!(doc_file.is_file());
|
2017-10-16 20:05:47 +00:00
|
|
|
let mut doc_html = String::new();
|
2018-03-14 15:17:44 +00:00
|
|
|
File::open(&doc_file)
|
|
|
|
.unwrap()
|
|
|
|
.read_to_string(&mut doc_html)
|
|
|
|
.unwrap();
|
2017-10-16 20:05:47 +00:00
|
|
|
assert!(!doc_html.contains("Library"));
|
|
|
|
assert!(doc_html.contains("Binary"));
|
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2017-10-16 20:05:47 +00:00
|
|
|
fn doc_lib_bin_same_name_documents_bins_when_requested() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
r#"
|
2017-10-16 20:05:47 +00:00
|
|
|
//! Binary documentation
|
|
|
|
extern crate foo;
|
|
|
|
fn main() {
|
|
|
|
foo::foo();
|
|
|
|
}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2017-10-16 20:05:47 +00:00
|
|
|
//! Library documentation
|
|
|
|
pub fn foo() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2017-10-16 20:05:47 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("doc --bins")
|
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
|
|
|
[CHECKING] foo v0.0.1 ([CWD])
|
|
|
|
[DOCUMENTING] foo v0.0.1 ([CWD])
|
2017-10-16 20:05:47 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.run();
|
2018-08-29 05:53:01 +00:00
|
|
|
assert!(p.root().join("target/doc").is_dir());
|
2017-10-16 20:05:47 +00:00
|
|
|
let doc_file = p.root().join("target/doc/foo/index.html");
|
2018-08-29 06:11:10 +00:00
|
|
|
assert!(doc_file.is_file());
|
2017-10-16 20:05:47 +00:00
|
|
|
let mut doc_html = String::new();
|
2018-03-14 15:17:44 +00:00
|
|
|
File::open(&doc_file)
|
|
|
|
.unwrap()
|
|
|
|
.read_to_string(&mut doc_html)
|
|
|
|
.unwrap();
|
2017-10-16 20:05:47 +00:00
|
|
|
assert!(!doc_html.contains("Library"));
|
|
|
|
assert!(doc_html.contains("Binary"));
|
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn doc_dash_p() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-11-25 05:34:05 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dependencies.a]
|
|
|
|
path = "a"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("src/lib.rs", "extern crate a;")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"a/Cargo.toml",
|
|
|
|
r#"
|
2014-11-25 05:34:05 +00:00
|
|
|
[package]
|
|
|
|
name = "a"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dependencies.b]
|
|
|
|
path = "../b"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("a/src/lib.rs", "extern crate b;")
|
2018-07-24 22:35:01 +00:00
|
|
|
.file("b/Cargo.toml", &basic_manifest("b", "0.0.1"))
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("b/src/lib.rs", "")
|
|
|
|
.build();
|
2014-11-25 05:34:05 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("doc -p a")
|
|
|
|
.with_stderr(
|
2018-03-14 15:17:44 +00:00
|
|
|
"\
|
2018-09-08 02:42:26 +00:00
|
|
|
[..] b v0.0.1 ([CWD]/b)
|
|
|
|
[..] b v0.0.1 ([CWD]/b)
|
|
|
|
[DOCUMENTING] a v0.0.1 ([CWD]/a)
|
2017-01-18 19:37:52 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
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-03-25 19:51:23 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn doc_same_name() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2015-03-25 19:51:23 +00:00
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.file("src/bin/main.rs", "fn main() {}")
|
|
|
|
.file("examples/main.rs", "fn main() {}")
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("tests/main.rs", "fn main() {}")
|
|
|
|
.build();
|
2015-03-25 19:51:23 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("doc").run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-03-26 02:06:18 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn doc_target() {
|
2018-08-08 22:57:20 +00:00
|
|
|
const TARGET: &str = "arm-unknown-linux-gnueabihf";
|
2015-03-26 02:06:18 +00:00
|
|
|
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2018-10-16 09:52:48 +00:00
|
|
|
#![feature(no_core, lang_items)]
|
2015-08-03 17:04:22 +00:00
|
|
|
#![no_core]
|
2015-03-26 02:06:18 +00:00
|
|
|
|
2018-10-15 18:45:39 +00:00
|
|
|
#[lang = "sized"]
|
|
|
|
trait Sized {}
|
|
|
|
|
2015-03-26 02:06:18 +00:00
|
|
|
extern {
|
|
|
|
pub static A: u32;
|
|
|
|
}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2015-03-26 02:06:18 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("doc --verbose --target").arg(TARGET).run();
|
2018-08-29 05:53:01 +00:00
|
|
|
assert!(p.root().join(&format!("target/{}/doc", TARGET)).is_dir());
|
2018-12-08 11:19:47 +00:00
|
|
|
assert!(p
|
|
|
|
.root()
|
|
|
|
.join(&format!("target/{}/doc/foo/index.html", TARGET))
|
|
|
|
.is_file());
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-09-01 17:14:32 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn target_specific_not_documented() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2015-09-01 17:14:32 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[target.foo.dependencies]
|
|
|
|
a = { path = "a" }
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("src/lib.rs", "")
|
2018-07-24 22:35:01 +00:00
|
|
|
.file("a/Cargo.toml", &basic_manifest("a", "0.0.1"))
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("a/src/lib.rs", "not rust")
|
|
|
|
.build();
|
2015-09-01 17:14:32 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("doc").run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-09-04 17:33:11 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn output_not_captured() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2015-09-08 17:39:15 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
a = { path = "a" }
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("src/lib.rs", "")
|
2018-07-24 22:35:01 +00:00
|
|
|
.file("a/Cargo.toml", &basic_manifest("a", "0.0.1"))
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"a/src/lib.rs",
|
|
|
|
"
|
2015-09-08 17:39:15 +00:00
|
|
|
/// ```
|
|
|
|
/// ☃
|
|
|
|
/// ```
|
|
|
|
pub fn foo() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2015-09-08 17:39:15 +00:00
|
|
|
|
2018-08-28 22:11:30 +00:00
|
|
|
p.cargo("doc")
|
2018-09-14 21:06:17 +00:00
|
|
|
.without_status()
|
2019-01-17 18:15:14 +00:00
|
|
|
.with_stderr_contains("[..]☃")
|
|
|
|
.with_stderr_contains(r"[..]unknown start of token: \u{2603}")
|
2018-08-28 22:11:30 +00:00
|
|
|
.run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-09-08 17:39:15 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn target_specific_documented() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
&format!(
|
|
|
|
r#"
|
2015-09-04 17:33:11 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[target.foo.dependencies]
|
|
|
|
a = {{ path = "a" }}
|
|
|
|
[target.{}.dependencies]
|
|
|
|
a = {{ path = "a" }}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
rustc_host()
|
|
|
|
),
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"src/lib.rs",
|
|
|
|
"
|
2015-09-04 17:33:11 +00:00
|
|
|
extern crate a;
|
|
|
|
|
|
|
|
/// test
|
|
|
|
pub fn foo() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("a/Cargo.toml", &basic_manifest("a", "0.0.1"))
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"a/src/lib.rs",
|
|
|
|
"
|
2015-09-04 17:33:11 +00:00
|
|
|
/// test
|
|
|
|
pub fn foo() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2015-09-04 17:33:11 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("doc").run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-09-05 00:09:24 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn no_document_build_deps() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2015-09-05 00:30:59 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[build-dependencies]
|
|
|
|
a = { path = "a" }
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("src/lib.rs", "pub fn foo() {}")
|
2018-07-24 22:35:01 +00:00
|
|
|
.file("a/Cargo.toml", &basic_manifest("a", "0.0.1"))
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"a/src/lib.rs",
|
|
|
|
"
|
2015-09-05 00:30:59 +00:00
|
|
|
/// ```
|
|
|
|
/// ☃
|
|
|
|
/// ```
|
|
|
|
pub fn foo() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2015-09-05 00:30:59 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("doc").run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-09-05 00:30:59 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn doc_release() {
|
2018-08-28 09:20:03 +00:00
|
|
|
let p = project().file("src/lib.rs", "").build();
|
2015-09-05 00:09:24 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("build --release").run();
|
|
|
|
p.cargo("doc --release -v")
|
|
|
|
.with_stderr(
|
2018-03-14 15:17:44 +00:00
|
|
|
"\
|
2016-05-11 16:55:43 +00:00
|
|
|
[DOCUMENTING] foo v0.0.1 ([..])
|
2018-08-02 09:18:48 +00:00
|
|
|
[RUNNING] `rustdoc [..] src/lib.rs [..]`
|
2017-01-18 19:37:52 +00:00
|
|
|
[FINISHED] release [optimized] target(s) in [..]
|
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-07-16 20:35:40 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn doc_multiple_deps() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2015-07-16 20:35:40 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dependencies.bar]
|
|
|
|
path = "bar"
|
|
|
|
|
|
|
|
[dependencies.baz]
|
|
|
|
path = "baz"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("src/lib.rs", "extern crate bar; pub fn foo() {}")
|
2018-07-24 22:35:01 +00:00
|
|
|
.file("bar/Cargo.toml", &basic_manifest("bar", "0.0.1"))
|
2018-07-25 00:30:32 +00:00
|
|
|
.file("bar/src/lib.rs", "pub fn bar() {}")
|
2018-07-24 22:35:01 +00:00
|
|
|
.file("baz/Cargo.toml", &basic_manifest("baz", "0.0.1"))
|
2018-07-25 00:30:32 +00:00
|
|
|
.file("baz/src/lib.rs", "pub fn baz() {}")
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2015-07-16 20:35:40 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("doc -p bar -p baz -v").run();
|
2015-07-16 20:35:40 +00:00
|
|
|
|
2018-08-29 05:53:01 +00:00
|
|
|
assert!(p.root().join("target/doc").is_dir());
|
2018-08-29 06:11:10 +00:00
|
|
|
assert!(p.root().join("target/doc/bar/index.html").is_file());
|
|
|
|
assert!(p.root().join("target/doc/baz/index.html").is_file());
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-10-10 14:20:21 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn features() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2015-10-10 14:20:21 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dependencies.bar]
|
|
|
|
path = "bar"
|
|
|
|
|
|
|
|
[features]
|
|
|
|
foo = ["bar/bar"]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("src/lib.rs", r#"#[cfg(feature = "foo")] pub fn foo() {}"#)
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"bar/Cargo.toml",
|
|
|
|
r#"
|
2015-10-10 14:20:21 +00:00
|
|
|
[package]
|
|
|
|
name = "bar"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[features]
|
|
|
|
bar = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"bar/build.rs",
|
|
|
|
r#"
|
2015-10-10 14:20:21 +00:00
|
|
|
fn main() {
|
|
|
|
println!("cargo:rustc-cfg=bar");
|
|
|
|
}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-08-28 09:20:03 +00:00
|
|
|
"bar/src/lib.rs",
|
|
|
|
r#"#[cfg(feature = "bar")] pub fn bar() {}"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("doc --features foo").run();
|
2018-08-29 05:53:01 +00:00
|
|
|
assert!(p.root().join("target/doc").is_dir());
|
2018-08-29 06:11:10 +00:00
|
|
|
assert!(p.root().join("target/doc/foo/fn.foo.html").is_file());
|
|
|
|
assert!(p.root().join("target/doc/bar/fn.bar.html").is_file());
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2016-03-08 05:51:44 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn rerun_when_dir_removed() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2016-03-08 05:51:44 +00:00
|
|
|
/// dox
|
|
|
|
pub fn foo() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2017-02-15 14:16:41 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("doc").run();
|
2018-08-29 06:11:10 +00:00
|
|
|
assert!(p.root().join("target/doc/foo/index.html").is_file());
|
2016-03-08 05:51:44 +00:00
|
|
|
|
|
|
|
fs::remove_dir_all(p.root().join("target/doc/foo")).unwrap();
|
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("doc").run();
|
2018-08-29 06:11:10 +00:00
|
|
|
assert!(p.root().join("target/doc/foo/index.html").is_file());
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2016-04-14 17:32:35 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn document_only_lib() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2016-04-14 17:32:35 +00:00
|
|
|
/// dox
|
|
|
|
pub fn foo() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"src/bin/bar.rs",
|
|
|
|
r#"
|
2016-04-14 17:32:35 +00:00
|
|
|
/// ```
|
|
|
|
/// ☃
|
|
|
|
/// ```
|
|
|
|
pub fn foo() {}
|
|
|
|
fn main() { foo(); }
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("doc --lib").run();
|
2018-08-29 06:11:10 +00:00
|
|
|
assert!(p.root().join("target/doc/foo/index.html").is_file());
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2016-11-02 16:36:23 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-11-02 16:36:23 +00:00
|
|
|
fn plugins_no_use_target() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2016-11-02 16:36:23 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[lib]
|
|
|
|
proc-macro = true
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("src/lib.rs", "")
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("doc --target=x86_64-unknown-openbsd -v").run();
|
2016-11-02 16:36:23 +00:00
|
|
|
}
|
2017-01-08 11:59:02 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2017-01-08 11:59:02 +00:00
|
|
|
fn doc_all_workspace() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-01-08 11:59:02 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
bar = { path = "bar" }
|
|
|
|
|
|
|
|
[workspace]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
2018-07-24 22:35:01 +00:00
|
|
|
.file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0"))
|
2018-07-25 00:30:32 +00:00
|
|
|
.file("bar/src/lib.rs", "pub fn bar() {}")
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2017-01-08 11:59:02 +00:00
|
|
|
|
|
|
|
// The order in which bar is compiled or documented is not deterministic
|
2019-09-04 00:47:12 +00:00
|
|
|
p.cargo("doc --workspace")
|
2018-08-28 09:20:03 +00:00
|
|
|
.with_stderr_contains("[..] Documenting bar v0.1.0 ([..])")
|
|
|
|
.with_stderr_contains("[..] Checking bar v0.1.0 ([..])")
|
|
|
|
.with_stderr_contains("[..] Documenting foo v0.1.0 ([..])")
|
|
|
|
.run();
|
2017-01-08 11:59:02 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2017-01-08 11:59:02 +00:00
|
|
|
fn doc_all_virtual_manifest() {
|
2018-07-20 17:41:44 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-01-08 11:59:02 +00:00
|
|
|
[workspace]
|
2018-07-20 17:41:44 +00:00
|
|
|
members = ["bar", "baz"]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0"))
|
2018-07-25 00:30:32 +00:00
|
|
|
.file("bar/src/lib.rs", "pub fn bar() {}")
|
2018-07-24 22:35:01 +00:00
|
|
|
.file("baz/Cargo.toml", &basic_manifest("baz", "0.1.0"))
|
2018-07-25 00:30:32 +00:00
|
|
|
.file("baz/src/lib.rs", "pub fn baz() {}")
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2017-01-08 11:59:02 +00:00
|
|
|
|
2018-07-20 17:41:44 +00:00
|
|
|
// The order in which bar and baz are documented is not guaranteed
|
2019-09-04 00:47:12 +00:00
|
|
|
p.cargo("doc --workspace")
|
2018-08-28 09:20:03 +00:00
|
|
|
.with_stderr_contains("[..] Documenting baz v0.1.0 ([..])")
|
|
|
|
.with_stderr_contains("[..] Documenting bar v0.1.0 ([..])")
|
|
|
|
.run();
|
2017-01-08 11:59:02 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2017-05-26 21:00:45 +00:00
|
|
|
fn doc_virtual_manifest_all_implied() {
|
2018-07-20 17:41:44 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-05-26 21:00:45 +00:00
|
|
|
[workspace]
|
2018-07-20 17:41:44 +00:00
|
|
|
members = ["bar", "baz"]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0"))
|
2018-07-25 00:30:32 +00:00
|
|
|
.file("bar/src/lib.rs", "pub fn bar() {}")
|
2018-07-24 22:35:01 +00:00
|
|
|
.file("baz/Cargo.toml", &basic_manifest("baz", "0.1.0"))
|
2018-07-25 00:30:32 +00:00
|
|
|
.file("baz/src/lib.rs", "pub fn baz() {}")
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2017-05-26 21:00:45 +00:00
|
|
|
|
2018-07-20 17:41:44 +00:00
|
|
|
// The order in which bar and baz are documented is not guaranteed
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("doc")
|
|
|
|
.with_stderr_contains("[..] Documenting baz v0.1.0 ([..])")
|
|
|
|
.with_stderr_contains("[..] Documenting bar v0.1.0 ([..])")
|
|
|
|
.run();
|
2017-05-26 21:00:45 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2017-01-08 11:59:02 +00:00
|
|
|
fn doc_all_member_dependency_same_name() {
|
2018-07-20 17:41:44 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-01-08 11:59:02 +00:00
|
|
|
[workspace]
|
2018-07-20 17:41:44 +00:00
|
|
|
members = ["bar"]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-07-20 17:41:44 +00:00
|
|
|
"bar/Cargo.toml",
|
2018-03-14 15:17:44 +00:00
|
|
|
r#"
|
2017-01-08 11:59:02 +00:00
|
|
|
[project]
|
2018-07-20 17:41:44 +00:00
|
|
|
name = "bar"
|
2017-01-08 11:59:02 +00:00
|
|
|
version = "0.1.0"
|
|
|
|
|
|
|
|
[dependencies]
|
2018-07-20 17:41:44 +00:00
|
|
|
bar = "0.1.0"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("bar/src/lib.rs", "pub fn bar() {}")
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2017-01-08 11:59:02 +00:00
|
|
|
|
2018-07-20 17:41:44 +00:00
|
|
|
Package::new("bar", "0.1.0").publish();
|
2017-01-08 11:59:02 +00:00
|
|
|
|
2019-09-04 00:47:12 +00:00
|
|
|
p.cargo("doc --workspace")
|
2018-09-08 08:25:41 +00:00
|
|
|
.with_stderr_contains("[..] Updating `[..]` index")
|
2018-08-28 09:20:03 +00:00
|
|
|
.with_stderr_contains("[..] Documenting bar v0.1.0 ([..])")
|
|
|
|
.run();
|
2017-01-08 11:59:02 +00:00
|
|
|
}
|
2018-02-08 21:50:35 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2019-03-31 22:47:03 +00:00
|
|
|
#[cfg(not(any(target_os = "windows", target_os = "macos")))]
|
2018-02-08 21:50:35 +00:00
|
|
|
fn doc_workspace_open_help_message() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2018-02-08 21:50:35 +00:00
|
|
|
[workspace]
|
|
|
|
members = ["foo", "bar"]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("foo/Cargo.toml", &basic_manifest("foo", "0.1.0"))
|
2018-02-08 21:50:35 +00:00
|
|
|
.file("foo/src/lib.rs", "")
|
2018-07-24 22:35:01 +00:00
|
|
|
.file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0"))
|
2018-02-08 21:50:35 +00:00
|
|
|
.file("bar/src/lib.rs", "")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
// The order in which bar is compiled or documented is not deterministic
|
2019-09-04 00:47:12 +00:00
|
|
|
p.cargo("doc --workspace --open")
|
2019-03-31 22:47:03 +00:00
|
|
|
.env("BROWSER", "echo")
|
2018-08-28 09:20:03 +00:00
|
|
|
.with_stderr_contains("[..] Documenting bar v0.1.0 ([..])")
|
|
|
|
.with_stderr_contains("[..] Documenting foo v0.1.0 ([..])")
|
2019-03-31 22:47:03 +00:00
|
|
|
.with_stderr_contains("[..] Opening [..]/foo/index.html")
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
2018-02-08 21:50:35 +00:00
|
|
|
}
|
2018-04-05 12:39:50 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-05-29 10:34:27 +00:00
|
|
|
#[cfg(not(any(target_os = "windows", target_os = "macos")))]
|
2018-05-29 09:55:29 +00:00
|
|
|
fn doc_workspace_open_different_library_and_package_names() {
|
2018-07-20 14:25:51 +00:00
|
|
|
let p = project()
|
2018-05-29 09:55:29 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[workspace]
|
|
|
|
members = ["foo"]
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-05-29 09:55:29 +00:00
|
|
|
"foo/Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
[lib]
|
|
|
|
name = "foolib"
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("foo/src/lib.rs", "")
|
2018-05-29 09:55:29 +00:00
|
|
|
.build();
|
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("doc --open")
|
|
|
|
.env("BROWSER", "echo")
|
|
|
|
.with_stderr_contains("[..] Documenting foo v0.1.0 ([..])")
|
2018-09-08 02:42:26 +00:00
|
|
|
.with_stderr_contains("[..] [CWD]/target/doc/foolib/index.html")
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
2018-05-29 10:23:50 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-05-29 10:34:27 +00:00
|
|
|
#[cfg(not(any(target_os = "windows", target_os = "macos")))]
|
2018-05-29 10:23:50 +00:00
|
|
|
fn doc_workspace_open_binary() {
|
2018-07-20 14:25:51 +00:00
|
|
|
let p = project()
|
2018-05-29 10:23:50 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[workspace]
|
|
|
|
members = ["foo"]
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-05-29 10:23:50 +00:00
|
|
|
"foo/Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
[[bin]]
|
|
|
|
name = "foobin"
|
|
|
|
path = "src/main.rs"
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("foo/src/main.rs", "")
|
2018-05-29 10:23:50 +00:00
|
|
|
.build();
|
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("doc --open")
|
|
|
|
.env("BROWSER", "echo")
|
|
|
|
.with_stderr_contains("[..] Documenting foo v0.1.0 ([..])")
|
2018-09-08 02:42:26 +00:00
|
|
|
.with_stderr_contains("[..] Opening [CWD]/target/doc/foobin/index.html")
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
2018-05-29 10:23:50 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-05-29 10:34:27 +00:00
|
|
|
#[cfg(not(any(target_os = "windows", target_os = "macos")))]
|
2018-05-29 10:23:50 +00:00
|
|
|
fn doc_workspace_open_binary_and_library() {
|
2018-07-20 14:25:51 +00:00
|
|
|
let p = project()
|
2018-05-29 10:23:50 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[workspace]
|
|
|
|
members = ["foo"]
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-05-29 10:23:50 +00:00
|
|
|
"foo/Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
[lib]
|
|
|
|
name = "foolib"
|
|
|
|
[[bin]]
|
|
|
|
name = "foobin"
|
|
|
|
path = "src/main.rs"
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("foo/src/lib.rs", "")
|
2018-05-29 10:23:50 +00:00
|
|
|
.file("foo/src/main.rs", "")
|
|
|
|
.build();
|
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("doc --open")
|
|
|
|
.env("BROWSER", "echo")
|
|
|
|
.with_stderr_contains("[..] Documenting foo v0.1.0 ([..])")
|
2018-09-08 02:42:26 +00:00
|
|
|
.with_stderr_contains("[..] Opening [CWD]/target/doc/foolib/index.html")
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
2018-05-29 09:55:29 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-04-05 12:39:50 +00:00
|
|
|
fn doc_edition() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-04-05 12:39:50 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2018-05-03 16:14:25 +00:00
|
|
|
edition = "2018"
|
2018-04-05 12:39:50 +00:00
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("src/lib.rs", "")
|
2018-04-05 12:39:50 +00:00
|
|
|
.build();
|
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("doc -v")
|
2018-09-20 22:09:55 +00:00
|
|
|
.with_stderr_contains("[RUNNING] `rustdoc [..]--edition=2018[..]")
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
2018-07-31 13:49:33 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("test -v")
|
2018-09-20 22:09:55 +00:00
|
|
|
.with_stderr_contains("[RUNNING] `rustdoc [..]--edition=2018[..]")
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
2018-07-31 13:49:33 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-07-31 13:49:33 +00:00
|
|
|
fn doc_target_edition() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[lib]
|
|
|
|
edition = "2018"
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("src/lib.rs", "")
|
2018-07-31 13:49:33 +00:00
|
|
|
.build();
|
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("doc -v")
|
2018-09-20 20:55:09 +00:00
|
|
|
.with_stderr_contains("[RUNNING] `rustdoc [..]--edition=2018[..]")
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
2018-05-15 16:29:34 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("test -v")
|
2018-09-20 20:55:09 +00:00
|
|
|
.with_stderr_contains("[RUNNING] `rustdoc [..]--edition=2018[..]")
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
2018-04-05 12:39:50 +00:00
|
|
|
}
|
2018-04-15 12:56:22 +00:00
|
|
|
|
2018-04-15 13:00:36 +00:00
|
|
|
// Tests an issue where depending on different versions of the same crate depending on `cfg`s
|
|
|
|
// caused `cargo doc` to fail.
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-04-15 12:56:22 +00:00
|
|
|
fn issue_5345() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let foo = project()
|
2018-04-15 12:56:22 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[target.'cfg(all(windows, target_arch = "x86"))'.dependencies]
|
|
|
|
bar = "0.1"
|
|
|
|
|
|
|
|
[target.'cfg(not(all(windows, target_arch = "x86")))'.dependencies]
|
|
|
|
bar = "0.2"
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("src/lib.rs", "extern crate bar;")
|
2018-04-15 12:56:22 +00:00
|
|
|
.build();
|
|
|
|
Package::new("bar", "0.1.0").publish();
|
|
|
|
Package::new("bar", "0.2.0").publish();
|
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
foo.cargo("build").run();
|
|
|
|
foo.cargo("doc").run();
|
2018-04-15 12:56:22 +00:00
|
|
|
}
|
2018-07-15 18:10:01 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-07-15 18:10:01 +00:00
|
|
|
fn doc_private_items() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let foo = project()
|
2018-07-15 18:22:22 +00:00
|
|
|
.file("src/lib.rs", "mod private { fn private_item() {} }")
|
2018-07-15 18:10:01 +00:00
|
|
|
.build();
|
2018-08-28 09:20:03 +00:00
|
|
|
foo.cargo("doc --document-private-items").run();
|
2018-07-15 18:10:01 +00:00
|
|
|
|
2018-08-29 05:53:01 +00:00
|
|
|
assert!(foo.root().join("target/doc").is_dir());
|
2018-12-08 11:19:47 +00:00
|
|
|
assert!(foo
|
|
|
|
.root()
|
|
|
|
.join("target/doc/foo/private/index.html")
|
|
|
|
.is_file());
|
2018-07-15 18:10:01 +00:00
|
|
|
}
|
2018-07-21 05:25:02 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-09-13 13:19:35 +00:00
|
|
|
fn doc_private_ws() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[workspace]
|
|
|
|
members = ["a", "b"]
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("a/Cargo.toml", &basic_manifest("a", "0.0.1"))
|
2018-09-13 13:19:35 +00:00
|
|
|
.file("a/src/lib.rs", "fn p() {}")
|
|
|
|
.file("b/Cargo.toml", &basic_manifest("b", "0.0.1"))
|
|
|
|
.file("b/src/lib.rs", "fn p2() {}")
|
|
|
|
.file("b/src/main.rs", "fn main() {}")
|
|
|
|
.build();
|
2019-09-04 00:47:12 +00:00
|
|
|
p.cargo("doc --workspace --bins --lib --document-private-items -v")
|
2018-09-13 13:19:35 +00:00
|
|
|
.with_stderr_contains(
|
|
|
|
"[RUNNING] `rustdoc [..] a/src/lib.rs [..]--document-private-items[..]",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.with_stderr_contains(
|
2018-09-13 13:19:35 +00:00
|
|
|
"[RUNNING] `rustdoc [..] b/src/lib.rs [..]--document-private-items[..]",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.with_stderr_contains(
|
2018-09-13 13:19:35 +00:00
|
|
|
"[RUNNING] `rustdoc [..] b/src/main.rs [..]--document-private-items[..]",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.run();
|
2018-09-13 13:19:35 +00:00
|
|
|
}
|
|
|
|
|
2018-08-13 09:41:10 +00:00
|
|
|
const BAD_INTRA_LINK_LIB: &str = r#"
|
2018-08-09 22:43:34 +00:00
|
|
|
#![deny(intra_doc_link_resolution_failure)]
|
|
|
|
|
|
|
|
/// [bad_link]
|
|
|
|
pub fn foo() {}
|
|
|
|
"#;
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-07-21 05:25:02 +00:00
|
|
|
fn doc_cap_lints() {
|
|
|
|
if !is_nightly() {
|
2019-02-03 04:01:23 +00:00
|
|
|
// This can be removed once intra_doc_link_resolution_failure fails on stable.
|
2018-07-21 05:25:02 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
let a = git::new("a", |p| {
|
2018-08-09 22:43:34 +00:00
|
|
|
p.file("Cargo.toml", &basic_lib_manifest("a"))
|
|
|
|
.file("src/lib.rs", BAD_INTRA_LINK_LIB)
|
2019-08-13 05:25:36 +00:00
|
|
|
});
|
2018-07-21 05:25:02 +00:00
|
|
|
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
&format!(
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
a = {{ git = '{}' }}
|
|
|
|
"#,
|
|
|
|
a.url()
|
|
|
|
),
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("src/lib.rs", "")
|
2018-07-21 05:25:02 +00:00
|
|
|
.build();
|
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("doc")
|
|
|
|
.with_stderr_unordered(
|
2018-07-21 05:25:02 +00:00
|
|
|
"\
|
|
|
|
[UPDATING] git repository `[..]`
|
|
|
|
[DOCUMENTING] a v0.5.0 ([..])
|
|
|
|
[CHECKING] a v0.5.0 ([..])
|
|
|
|
[DOCUMENTING] foo v0.0.1 ([..])
|
|
|
|
[FINISHED] dev [..]
|
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.run();
|
2018-07-21 05:25:02 +00:00
|
|
|
|
|
|
|
p.root().join("target").rm_rf();
|
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("doc -vv")
|
|
|
|
.with_stderr_contains(
|
2018-07-21 05:25:02 +00:00
|
|
|
"\
|
|
|
|
[WARNING] `[bad_link]` cannot be resolved, ignoring it...
|
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.run();
|
2018-07-21 05:25:02 +00:00
|
|
|
}
|
2018-08-09 06:52:05 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-08-09 06:52:05 +00:00
|
|
|
fn doc_message_format() {
|
|
|
|
if !is_nightly() {
|
2019-02-03 04:01:23 +00:00
|
|
|
// This can be removed once intra_doc_link_resolution_failure fails on stable.
|
2018-08-09 06:52:05 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-08-09 22:43:34 +00:00
|
|
|
let p = project().file("src/lib.rs", BAD_INTRA_LINK_LIB).build();
|
2018-08-09 06:52:05 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("doc --message-format=json")
|
|
|
|
.with_status(101)
|
2019-03-06 18:49:24 +00:00
|
|
|
.with_json_contains_unordered(
|
2018-08-09 06:52:05 +00:00
|
|
|
r#"
|
|
|
|
{
|
|
|
|
"message": {
|
2018-08-09 22:43:34 +00:00
|
|
|
"children": "{...}",
|
|
|
|
"code": "{...}",
|
2018-08-09 06:52:05 +00:00
|
|
|
"level": "error",
|
|
|
|
"message": "[..]",
|
|
|
|
"rendered": "[..]",
|
|
|
|
"spans": "{...}"
|
|
|
|
},
|
|
|
|
"package_id": "foo [..]",
|
|
|
|
"reason": "compiler-message",
|
|
|
|
"target": "{...}"
|
|
|
|
}
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.run();
|
2018-08-09 06:52:05 +00:00
|
|
|
}
|
2018-08-10 07:44:36 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-08-10 07:44:36 +00:00
|
|
|
fn short_message_format() {
|
|
|
|
if !is_nightly() {
|
2019-02-03 04:01:23 +00:00
|
|
|
// This can be removed once intra_doc_link_resolution_failure fails on stable.
|
2018-08-10 07:44:36 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
let p = project().file("src/lib.rs", BAD_INTRA_LINK_LIB).build();
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("doc --message-format=short")
|
|
|
|
.with_status(101)
|
|
|
|
.with_stderr_contains(
|
2019-03-06 18:49:24 +00:00
|
|
|
"src/lib.rs:4:6: error: `[bad_link]` cannot be resolved, ignoring it...",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.run();
|
2018-08-10 07:44:36 +00:00
|
|
|
}
|
2019-06-08 21:18:51 +00:00
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn doc_example() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
edition = "2018"
|
|
|
|
|
|
|
|
[[example]]
|
|
|
|
crate-type = ["lib"]
|
|
|
|
name = "ex1"
|
|
|
|
doc = true
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/lib.rs", "pub fn f() {}")
|
|
|
|
.file(
|
|
|
|
"examples/ex1.rs",
|
|
|
|
r#"
|
|
|
|
use foo::f;
|
|
|
|
|
|
|
|
/// Example
|
|
|
|
pub fn x() { f(); }
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("doc").run();
|
|
|
|
assert!(p
|
|
|
|
.build_dir()
|
|
|
|
.join("doc")
|
|
|
|
.join("ex1")
|
|
|
|
.join("fn.x.html")
|
|
|
|
.exists());
|
|
|
|
}
|
2019-11-21 21:05:07 +00:00
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn bin_private_items() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
"
|
|
|
|
pub fn foo_pub() {}
|
|
|
|
fn foo_priv() {}
|
|
|
|
struct FooStruct;
|
|
|
|
enum FooEnum {}
|
|
|
|
trait FooTrait {}
|
|
|
|
type FooType = u32;
|
|
|
|
mod foo_mod {}
|
|
|
|
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("doc")
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
|
|
|
[DOCUMENTING] foo v0.0.1 ([CWD])
|
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
|
|
|
|
assert!(p.root().join("target/doc/foo/index.html").is_file());
|
|
|
|
assert!(p.root().join("target/doc/foo/fn.foo_pub.html").is_file());
|
|
|
|
assert!(p.root().join("target/doc/foo/fn.foo_priv.html").is_file());
|
|
|
|
assert!(p
|
|
|
|
.root()
|
|
|
|
.join("target/doc/foo/struct.FooStruct.html")
|
|
|
|
.is_file());
|
|
|
|
assert!(p.root().join("target/doc/foo/enum.FooEnum.html").is_file());
|
|
|
|
assert!(p
|
|
|
|
.root()
|
|
|
|
.join("target/doc/foo/trait.FooTrait.html")
|
|
|
|
.is_file());
|
|
|
|
assert!(p.root().join("target/doc/foo/type.FooType.html").is_file());
|
|
|
|
assert!(p.root().join("target/doc/foo/foo_mod/index.html").is_file());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn bin_private_items_deps() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dependencies.bar]
|
|
|
|
path = "bar"
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
"
|
|
|
|
fn foo_priv() {}
|
|
|
|
pub fn foo_pub() {}
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.file("bar/Cargo.toml", &basic_manifest("bar", "0.0.1"))
|
|
|
|
.file(
|
|
|
|
"bar/src/lib.rs",
|
|
|
|
"
|
|
|
|
#[allow(dead_code)]
|
|
|
|
fn bar_priv() {}
|
|
|
|
pub fn bar_pub() {}
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("doc")
|
|
|
|
.with_stderr_unordered(
|
|
|
|
"\
|
|
|
|
[DOCUMENTING] bar v0.0.1 ([..])
|
|
|
|
[CHECKING] bar v0.0.1 ([..])
|
|
|
|
[DOCUMENTING] foo v0.0.1 ([CWD])
|
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
|
|
|
|
assert!(p.root().join("target/doc/foo/index.html").is_file());
|
|
|
|
assert!(p.root().join("target/doc/foo/fn.foo_pub.html").is_file());
|
|
|
|
assert!(p.root().join("target/doc/foo/fn.foo_priv.html").is_file());
|
|
|
|
|
|
|
|
assert!(p.root().join("target/doc/bar/index.html").is_file());
|
|
|
|
assert!(p.root().join("target/doc/bar/fn.bar_pub.html").is_file());
|
|
|
|
assert!(!p.root().join("target/doc/bar/fn.bar_priv.html").exists());
|
|
|
|
}
|