cargo/tests/testsuite/rustdoc.rs

231 lines
5.5 KiB
Rust
Raw Normal View History

2018-07-24 22:35:01 +00:00
use support::{basic_manifest, execs, project};
use support::hamcrest::assert_that;
#[test]
fn rustdoc_simple() {
let p = project()
.file("src/lib.rs", r#" "#)
.build();
2018-03-14 15:17:44 +00:00
assert_that(
p.cargo("rustdoc").arg("-v"),
execs().with_status(0).with_stderr(format!(
"\
[DOCUMENTING] foo v0.0.1 ({url})
2016-11-30 20:05:23 +00:00
[RUNNING] `rustdoc --crate-name foo src[/]lib.rs \
2016-11-06 04:53:21 +00:00
-o {dir}[/]target[/]doc \
-L dependency={dir}[/]target[/]debug[/]deps`
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
2018-03-14 15:17:44 +00:00
",
dir = p.root().display(),
url = p.url()
)),
);
}
#[test]
fn rustdoc_args() {
let p = project()
.file("src/lib.rs", r#" "#)
.build();
2018-03-14 15:17:44 +00:00
assert_that(
p.cargo("rustdoc").arg("-v").arg("--").arg("--cfg=foo"),
execs().with_status(0).with_stderr(format!(
"\
[DOCUMENTING] foo v0.0.1 ({url})
2016-11-30 20:05:23 +00:00
[RUNNING] `rustdoc --crate-name foo src[/]lib.rs \
2016-11-06 04:53:21 +00:00
-o {dir}[/]target[/]doc \
--cfg=foo \
2016-11-06 04:53:21 +00:00
-L dependency={dir}[/]target[/]debug[/]deps`
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
2018-03-14 15:17:44 +00:00
",
dir = p.root().display(),
url = p.url()
)),
);
}
#[test]
fn rustdoc_foo_with_bar_dependency() {
let foo = project()
2018-03-14 15:17:44 +00:00
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.0.1"
authors = []
[dependencies.bar]
path = "../bar"
2018-03-14 15:17:44 +00:00
"#,
)
.file(
"src/lib.rs",
r#"
extern crate bar;
pub fn foo() {}
2018-03-14 15:17:44 +00:00
"#,
)
.build();
let _bar = project().at("bar")
2018-07-24 22:35:01 +00:00
.file("Cargo.toml", &basic_manifest("bar", "0.0.1"))
2018-03-14 15:17:44 +00:00
.file(
"src/lib.rs",
r#"
pub fn baz() {}
2018-03-14 15:17:44 +00:00
"#,
)
.build();
2018-03-14 15:17:44 +00:00
assert_that(
foo.cargo("rustdoc").arg("-v").arg("--").arg("--cfg=foo"),
execs().with_status(0).with_stderr(format!(
"\
2018-04-19 18:19:11 +00:00
[CHECKING] bar v0.0.1 ([..])
2016-11-06 04:53:21 +00:00
[RUNNING] `rustc [..]bar[/]src[/]lib.rs [..]`
[DOCUMENTING] foo v0.0.1 ({url})
2016-11-30 20:05:23 +00:00
[RUNNING] `rustdoc --crate-name foo src[/]lib.rs \
2016-11-06 04:53:21 +00:00
-o {dir}[/]target[/]doc \
--cfg=foo \
2016-11-06 04:53:21 +00:00
-L dependency={dir}[/]target[/]debug[/]deps \
--extern [..]`
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
2018-03-14 15:17:44 +00:00
",
dir = foo.root().display(),
url = foo.url()
)),
);
}
#[test]
fn rustdoc_only_bar_dependency() {
let foo = project()
2018-03-14 15:17:44 +00:00
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.0.1"
authors = []
[dependencies.bar]
path = "../bar"
2018-03-14 15:17:44 +00:00
"#,
)
.file(
"src/main.rs",
r#"
extern crate bar;
fn main() {
bar::baz()
}
2018-03-14 15:17:44 +00:00
"#,
)
.build();
let _bar = project().at("bar")
2018-07-24 22:35:01 +00:00
.file("Cargo.toml", &basic_manifest("bar", "0.0.1"))
2018-03-14 15:17:44 +00:00
.file(
"src/lib.rs",
r#"
pub fn baz() {}
2018-03-14 15:17:44 +00:00
"#,
)
.build();
2018-03-14 15:17:44 +00:00
assert_that(
foo.cargo("rustdoc")
.arg("-v")
.arg("-p")
.arg("bar")
.arg("--")
.arg("--cfg=foo"),
execs().with_status(0).with_stderr(format!(
"\
[DOCUMENTING] bar v0.0.1 ([..])
2016-11-30 20:05:23 +00:00
[RUNNING] `rustdoc --crate-name bar [..]bar[/]src[/]lib.rs \
2016-11-06 04:53:21 +00:00
-o {dir}[/]target[/]doc \
--cfg=foo \
2016-11-06 04:53:21 +00:00
-L dependency={dir}[/]target[/]debug[/]deps`
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
2018-03-14 15:17:44 +00:00
",
dir = foo.root().display()
)),
);
}
#[test]
fn rustdoc_same_name_documents_lib() {
let p = project()
2018-03-14 15:17:44 +00:00
.file(
"src/main.rs",
r#"
fn main() {}
2018-03-14 15:17:44 +00:00
"#,
)
.file("src/lib.rs", r#" "#)
.build();
2018-03-14 15:17:44 +00:00
assert_that(
p.cargo("rustdoc").arg("-v").arg("--").arg("--cfg=foo"),
execs().with_status(0).with_stderr(format!(
"\
[DOCUMENTING] foo v0.0.1 ([..])
[RUNNING] `rustdoc --crate-name foo src[/]lib.rs \
-o {dir}[/]target[/]doc \
--cfg=foo \
-L dependency={dir}[/]target[/]debug[/]deps`
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
2018-03-14 15:17:44 +00:00
",
dir = p.root().display()
)),
);
}
#[test]
fn features() {
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.0.1"
authors = []
[features]
quux = []
"#,
)
.file("src/lib.rs", "")
.build();
assert_that(
p.cargo("rustdoc --verbose --features quux"),
execs()
.with_status(0)
.with_stderr_contains("[..]feature=[..]quux[..]"),
);
}
#[test]
#[cfg(all(target_arch = "x86_64", target_os = "linux"))]
fn rustdoc_target() {
let p = project()
.file("src/lib.rs", "")
.build();
assert_that(
p.cargo("rustdoc --verbose --target x86_64-unknown-linux-gnu"),
execs().with_status(0).with_stderr("\
2018-07-24 13:01:56 +00:00
[DOCUMENTING] foo v0.0.1 ([..])
[RUNNING] `rustdoc --crate-name foo src[/]lib.rs \
--target x86_64-unknown-linux-gnu \
-o [..]foo[/]target[/]x86_64-unknown-linux-gnu[/]doc \
-L dependency=[..]foo[/]target[/]x86_64-unknown-linux-gnu[/]debug[/]deps \
-L dependency=[..]foo[/]target[/]debug[/]deps`
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]"),
);
}