From d8bf778124bc1a4f8e635d91775f396fb60390f4 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 7 Mar 2024 09:20:42 -0600 Subject: [PATCH 1/3] test(docs): Verify generated output --- tests/testsuite/doc.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/testsuite/doc.rs b/tests/testsuite/doc.rs index 36793dfc460..c27ed4ce32c 100644 --- a/tests/testsuite/doc.rs +++ b/tests/testsuite/doc.rs @@ -1186,9 +1186,11 @@ fn doc_all_workspace() { // The order in which bar is compiled or documented is not deterministic p.cargo("doc --workspace") - .with_stderr_contains("[..] Documenting bar v0.1.0 ([..])") - .with_stderr_contains("[..] Checking bar v0.1.0 ([..])") - .with_stderr_contains("[..] Documenting foo v0.1.0 ([..])") + .with_stderr_contains("[DOCUMENTING] bar v0.1.0 ([..])") + .with_stderr_contains("[CHECKING] bar v0.1.0 ([..])") + .with_stderr_contains("[DOCUMENTING] foo v0.1.0 ([..])") + .with_stderr_contains("[GENERATED] [CWD]/target/doc/bar/index.html") + .with_stderr_contains("[GENERATED] [CWD]/target/doc/foo/index.html") .run(); } From 7ffa09a296d5930042449e2193bdc3c36106970d Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 7 Mar 2024 09:22:12 -0600 Subject: [PATCH 2/3] test(docs): Show verbose behavior --- tests/testsuite/doc.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tests/testsuite/doc.rs b/tests/testsuite/doc.rs index c27ed4ce32c..e1dde038a54 100644 --- a/tests/testsuite/doc.rs +++ b/tests/testsuite/doc.rs @@ -1194,6 +1194,38 @@ fn doc_all_workspace() { .run(); } +#[cargo_test] +fn doc_all_workspace_verbose() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.1.0" + edition = "2015" + + [dependencies] + bar = { path = "bar" } + + [workspace] + "#, + ) + .file("src/main.rs", "fn main() {}") + .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0")) + .file("bar/src/lib.rs", "pub fn bar() {}") + .build(); + + // The order in which bar is compiled or documented is not deterministic + p.cargo("doc --workspace -v") + .with_stderr_contains("[DOCUMENTING] bar v0.1.0 ([..])") + .with_stderr_contains("[CHECKING] bar v0.1.0 ([..])") + .with_stderr_contains("[DOCUMENTING] foo v0.1.0 ([..])") + .with_stderr_contains("[GENERATED] [CWD]/target/doc/bar/index.html") + .with_stderr_contains("[GENERATED] [CWD]/target/doc/foo/index.html") + .run(); +} + #[cargo_test] fn doc_all_virtual_manifest() { let p = project() From 7bc6044fe44b3ad2211f4038675a44b35e064699 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 7 Mar 2024 09:34:34 -0600 Subject: [PATCH 3/3] fix(doc): Collapse down Generated statuses without --verbose Fixes #13336 --- src/cargo/ops/cargo_doc.rs | 34 ++++++++++++++++++++++++++++++++-- tests/testsuite/collisions.rs | 3 +-- tests/testsuite/doc.rs | 9 +++------ 3 files changed, 36 insertions(+), 10 deletions(-) diff --git a/src/cargo/ops/cargo_doc.rs b/src/cargo/ops/cargo_doc.rs index d5e41561bec..a9bdf3cab6c 100644 --- a/src/cargo/ops/cargo_doc.rs +++ b/src/cargo/ops/cargo_doc.rs @@ -1,5 +1,5 @@ use crate::core::compiler::{Compilation, CompileKind}; -use crate::core::{Shell, Workspace}; +use crate::core::{shell::Verbosity, Shell, Workspace}; use crate::ops; use crate::util::context::{GlobalContext, PathAndArgs}; use crate::util::CargoResult; @@ -77,7 +77,7 @@ pub fn doc(ws: &Workspace<'_>, options: &DocOptions) -> CargoResult<()> { )?; open_docs(&path, &mut shell, config_browser, ws.gctx())?; } - } else { + } else if ws.gctx().shell().verbosity() == Verbosity::Verbose { for name in &compilation.root_crate_names { for kind in &options.compile_opts.build_config.requested_kinds { let path = @@ -92,6 +92,36 @@ pub fn doc(ws: &Workspace<'_>, options: &DocOptions) -> CargoResult<()> { } } } + } else { + let mut output = compilation.root_crate_names.iter().flat_map(|name| { + options + .compile_opts + .build_config + .requested_kinds + .iter() + .map(|kind| path_by_output_format(&compilation, kind, name, &options.output_format)) + .filter(|path| path.exists()) + }); + if let Some(first_path) = output.next() { + let remaining = output.count(); + let remaining = match remaining { + 0 => "".to_owned(), + 1 => " and 1 other file".to_owned(), + n => format!(" and {n} other files"), + }; + + let mut shell = ws.gctx().shell(); + let link = shell.err_file_hyperlink(&first_path); + shell.status( + "Generated", + format!( + "{}{}{}{remaining}", + link.open(), + first_path.display(), + link.close() + ), + )?; + } } Ok(()) diff --git a/tests/testsuite/collisions.rs b/tests/testsuite/collisions.rs index e47744d7f48..d8b7472e1cb 100644 --- a/tests/testsuite/collisions.rs +++ b/tests/testsuite/collisions.rs @@ -561,8 +561,7 @@ the same path; see . [DOCUMENTING] foo-macro v1.0.0 [..] [DOCUMENTING] abc v1.0.0 [..] [FINISHED] [..] -[GENERATED] [CWD]/target/doc/abc/index.html -[GENERATED] [CWD]/target/doc/foo_macro/index.html +[GENERATED] [CWD]/target/doc/abc/index.html and 1 other file ") .run(); } diff --git a/tests/testsuite/doc.rs b/tests/testsuite/doc.rs index e1dde038a54..85998874964 100644 --- a/tests/testsuite/doc.rs +++ b/tests/testsuite/doc.rs @@ -309,8 +309,7 @@ the same path; see . [DOCUMENTING] bar v0.1.0 ([ROOT]/foo/bar) [DOCUMENTING] foo v0.1.0 ([ROOT]/foo/foo) [FINISHED] [..] -[GENERATED] [CWD]/target/doc/foo_lib/index.html -[GENERATED] [CWD]/target/doc/foo_lib/index.html +[GENERATED] [CWD]/target/doc/foo_lib/index.html and 1 other file ", ) .run(); @@ -658,8 +657,7 @@ fn doc_lib_bin_example_same_name_documents_examples_when_requested() { [CHECKING] foo v0.0.1 ([CWD]) [DOCUMENTING] foo v0.0.1 ([CWD]) [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..] -[GENERATED] [CWD]/target/doc/ex1/index.html -[GENERATED] [CWD]/target/doc/ex2/index.html +[GENERATED] [CWD]/target/doc/ex1/index.html and 1 other file ", ) .run(); @@ -1189,8 +1187,7 @@ fn doc_all_workspace() { .with_stderr_contains("[DOCUMENTING] bar v0.1.0 ([..])") .with_stderr_contains("[CHECKING] bar v0.1.0 ([..])") .with_stderr_contains("[DOCUMENTING] foo v0.1.0 ([..])") - .with_stderr_contains("[GENERATED] [CWD]/target/doc/bar/index.html") - .with_stderr_contains("[GENERATED] [CWD]/target/doc/foo/index.html") + .with_stderr_contains("[GENERATED] [CWD]/target/doc/bar/index.html and 1 other file") .run(); }