From: Carol (Nichols || Goulding) Date: Mon, 16 Oct 2017 20:05:47 +0000 (-0400) Subject: Add more tests about documenting lib vs bins with the same name X-Git-Tag: archive/raspbian/0.35.0-2+rpi1~3^2^2^2^2^2^2^2~22^2~5^2~31^2 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=e98b9dbec8342a552c93ca23332d949880d1ecc7;p=cargo.git Add more tests about documenting lib vs bins with the same name --- diff --git a/tests/doc.rs b/tests/doc.rs index c61428bef..32379c37b 100644 --- a/tests/doc.rs +++ b/tests/doc.rs @@ -369,7 +369,7 @@ fn doc_lib_bin_same_name_documents_lib() { assert_that(p.cargo("doc"), execs().with_status(0).with_stderr(&format!("\ -[..] foo v0.0.1 ({dir}) +[DOCUMENTING] foo v0.0.1 ({dir}) [FINISHED] dev [unoptimized + debuginfo] target(s) in [..] ", dir = path2url(p.root())))); assert_that(&p.root().join("target/doc"), existing_dir()); @@ -381,6 +381,116 @@ fn doc_lib_bin_same_name_documents_lib() { assert!(!doc_html.contains("Binary")); } +#[test] +fn doc_lib_bin_same_name_documents_lib_when_requested() { + let p = project("foo") + .file("Cargo.toml", r#" + [package] + name = "foo" + version = "0.0.1" + authors = [] + "#) + .file("src/main.rs", r#" + //! Binary documentation + extern crate foo; + fn main() { + foo::foo(); + } + "#) + .file("src/lib.rs", r#" + //! Library documentation + pub fn foo() {} + "#) + .build(); + + assert_that(p.cargo("doc").arg("--lib"), + execs().with_status(0).with_stderr(&format!("\ +[DOCUMENTING] foo v0.0.1 ({dir}) +[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +", dir = path2url(p.root())))); + assert_that(&p.root().join("target/doc"), existing_dir()); + let doc_file = p.root().join("target/doc/foo/index.html"); + assert_that(&doc_file, existing_file()); + let mut doc_html = String::new(); + File::open(&doc_file).unwrap().read_to_string(&mut doc_html).unwrap(); + assert!(doc_html.contains("Library")); + assert!(!doc_html.contains("Binary")); +} + +#[test] +fn doc_lib_bin_same_name_documents_named_bin_when_requested() { + let p = project("foo") + .file("Cargo.toml", r#" + [package] + name = "foo" + version = "0.0.1" + authors = [] + "#) + .file("src/main.rs", r#" + //! Binary documentation + extern crate foo; + fn main() { + foo::foo(); + } + "#) + .file("src/lib.rs", r#" + //! Library documentation + pub fn foo() {} + "#) + .build(); + + assert_that(p.cargo("doc").arg("--bin").arg("foo"), + execs().with_status(0).with_stderr(&format!("\ +[COMPILING] foo v0.0.1 ({dir}) +[DOCUMENTING] foo v0.0.1 ({dir}) +[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +", dir = path2url(p.root())))); + assert_that(&p.root().join("target/doc"), existing_dir()); + let doc_file = p.root().join("target/doc/foo/index.html"); + assert_that(&doc_file, existing_file()); + let mut doc_html = String::new(); + File::open(&doc_file).unwrap().read_to_string(&mut doc_html).unwrap(); + assert!(!doc_html.contains("Library")); + assert!(doc_html.contains("Binary")); +} + +#[test] +fn doc_lib_bin_same_name_documents_bins_when_requested() { + let p = project("foo") + .file("Cargo.toml", r#" + [package] + name = "foo" + version = "0.0.1" + authors = [] + "#) + .file("src/main.rs", r#" + //! Binary documentation + extern crate foo; + fn main() { + foo::foo(); + } + "#) + .file("src/lib.rs", r#" + //! Library documentation + pub fn foo() {} + "#) + .build(); + + assert_that(p.cargo("doc").arg("--bins"), + execs().with_status(0).with_stderr(&format!("\ +[COMPILING] foo v0.0.1 ({dir}) +[DOCUMENTING] foo v0.0.1 ({dir}) +[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +", dir = path2url(p.root())))); + assert_that(&p.root().join("target/doc"), existing_dir()); + let doc_file = p.root().join("target/doc/foo/index.html"); + assert_that(&doc_file, existing_file()); + let mut doc_html = String::new(); + File::open(&doc_file).unwrap().read_to_string(&mut doc_html).unwrap(); + assert!(!doc_html.contains("Library")); + assert!(doc_html.contains("Binary")); +} + #[test] fn doc_dash_p() { let p = project("foo")