Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Rustin170506 committed Mar 9, 2023
1 parent 852f3b0 commit eb8be9d
Showing 1 changed file with 218 additions and 0 deletions.
218 changes: 218 additions & 0 deletions tests/testsuite/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,36 @@ fn doc_target() {
.is_file());
}

#[cargo_test]
fn doc_target_and_open() {
const TARGET: &str = "i686-unknown-linux-gnu";

let p = project()
.file(
"src/lib.rs",
"
/// test
pub fn foo() {}
",
)
.build();

p.cargo("doc --verbose --open --target")
.arg(TARGET)
.env("BROWSER", tools::echo())
.with_stderr_contains("[..] Documenting foo v0.0.1 ([..])")
.with_stderr_contains(&format!(
"[..] Opening [..]/target/{}/doc/foo/index.html",
TARGET
))
.run();
assert!(p.root().join(&format!("target/{}/doc", TARGET)).is_dir());
assert!(p
.root()
.join(&format!("target/{}/doc/foo/index.html", TARGET))
.is_file());
}

#[cargo_test]
fn target_specific_not_documented() {
let p = project()
Expand Down Expand Up @@ -1306,6 +1336,194 @@ fn doc_workspace_open_help_message() {
.run();
}

#[cargo_test(nightly, reason = "-Zper-package-target is unstable")]
fn doc_workspace_open_first_one_built_for_host() {
let p = project()
.file(
"Cargo.toml",
r#"
[workspace]
members = ["foo", "bar"]
"#,
)
.file("foo/Cargo.toml", &basic_manifest("foo", "0.1.0"))
.file("foo/src/lib.rs", "")
.file(
"bar/Cargo.toml",
r#"
cargo-features = ["per-package-target"]
[package]
name = "bar"
version = "0.1.0"
forced-target = "i686-unknown-linux-gnu"
"#,
)
.file("bar/src/lib.rs", "")
.build();

p.cargo("doc --workspace --open")
.masquerade_as_nightly_cargo(&["per-package-target"])
.env("BROWSER", tools::echo())
.with_stderr_contains("[..] Documenting bar v0.1.0 ([..])")
.with_stderr_contains("[..] Documenting foo v0.1.0 ([..])")
.with_stderr_contains("[..] Opening [..]/foo/index.html")
.run();
}

#[cargo_test(nightly, reason = "-Zper-package-target is unstable")]
fn doc_workspace_open_first_one_when_no_one_built_for_host() {
const TARGET: &str = "i686-unknown-linux-gnu";

let p = project()
.file(
"Cargo.toml",
r#"
[workspace]
members = ["foo", "bar"]
"#,
)
.file(
"foo/Cargo.toml",
&format!(
r#"
cargo-features = ["per-package-target"]
[package]
name = "foo"
version = "0.1.0"
forced-target = "{}"
"#,
TARGET
),
)
.file("foo/src/lib.rs", "")
.file(
"bar/Cargo.toml",
&format!(
r#"
cargo-features = ["per-package-target"]
[package]
name = "bar"
version = "0.1.0"
forced-target = "{}"
"#,
TARGET
),
)
.file("bar/src/lib.rs", "")
.build();

p.cargo("doc --workspace --open")
.masquerade_as_nightly_cargo(&["per-package-target"])
.env("BROWSER", tools::echo())
.with_stderr_contains("[..] Documenting bar v0.1.0 ([..])")
.with_stderr_contains("[..] Documenting foo v0.1.0 ([..])")
.with_stderr_contains(&format!(
"[..] Opening [..]/target/{}/doc/bar/index.html",
TARGET
))
.run();
}

#[cargo_test(nightly, reason = "-Zper-package-target is unstable")]
fn doc_workspace_open_first_one_built_for_target() {
const TARGET: &str = "i686-unknown-linux-gnu";

let p = project()
.file(
"Cargo.toml",
r#"
[workspace]
members = ["foo", "bar"]
"#,
)
.file("foo/Cargo.toml", &basic_manifest("foo", "0.1.0"))
.file("foo/src/lib.rs", "")
.file(
"bar/Cargo.toml",
&format!(
r#"
cargo-features = ["per-package-target"]
[package]
name = "bar"
version = "0.1.0"
forced-target = "{}"
"#,
TARGET
),
)
.file("bar/src/lib.rs", "")
.build();

p.cargo("doc --workspace --open --target")
.arg(TARGET)
.masquerade_as_nightly_cargo(&["per-package-target"])
.env("BROWSER", tools::echo())
.with_stderr_contains("[..] Documenting bar v0.1.0 ([..])")
.with_stderr_contains("[..] Documenting foo v0.1.0 ([..])")
.with_stderr_contains(&format!(
"[..] Opening [..]/target/{}/doc/bar/index.html",
TARGET
))
.run();
}

#[cargo_test(nightly, reason = "-Zper-package-target is unstable")]
fn doc_workspace_open_first_one_when_no_one_built_for_target() {
const TARGET: &str = "i686-unknown-linux-gnu";

let p = project()
.file(
"Cargo.toml",
r#"
[workspace]
members = ["foo", "bar"]
"#,
)
.file(
"foo/Cargo.toml",
&format!(
r#"
cargo-features = ["per-package-target"]
[package]
name = "foo"
version = "0.1.0"
forced-target = "{}"
"#,
TARGET
),
)
.file("foo/src/lib.rs", "")
.file(
"bar/Cargo.toml",
&format!(
r#"
cargo-features = ["per-package-target"]
[package]
name = "bar"
version = "0.1.0"
forced-target = "{}"
"#,
TARGET
),
)
.file("bar/src/lib.rs", "")
.build();

// We don't build for host, so we should open the first one built for TARGET.
let host_target = rustc_host();
p.cargo("doc --workspace --open --target")
.arg(host_target)
.masquerade_as_nightly_cargo(&["per-package-target"])
.env("BROWSER", tools::echo())
.with_stderr_contains("[..] Documenting bar v0.1.0 ([..])")
.with_stderr_contains("[..] Documenting foo v0.1.0 ([..])")
.with_stderr_contains(&format!(
"[..] Opening [..]/target/{}/doc/bar/index.html",
TARGET
))
.run();
}

#[cargo_test(nightly, reason = "-Zextern-html-root-url is unstable")]
fn doc_extern_map_local() {
let p = project()
Expand Down

0 comments on commit eb8be9d

Please sign in to comment.