about summary refs log tree commit diff
path: root/tests/rustdoc-ui
diff options
context:
space:
mode:
authorJubilee <workingjubilee@gmail.com>2024-11-04 20:40:47 -0800
committerGitHub <noreply@github.com>2024-11-04 20:40:47 -0800
commitb3fc9e6d6fb720aae421fa429c7cd6bab398eb2b (patch)
tree82b78af6ab922007f3ac12ecad782db64de00396 /tests/rustdoc-ui
parentf8ac0e71f879de7da4d5b2521f795ee4a0c9b941 (diff)
parent5dfbc0383d6e7ad27f0bdae5542109dafc9cd4f1 (diff)
downloadrust-b3fc9e6d6fb720aae421fa429c7cd6bab398eb2b.tar.gz
rust-b3fc9e6d6fb720aae421fa429c7cd6bab398eb2b.zip
Rollup merge of #132596 - GuillaumeGomez:show-coverage, r=notriddle
[rustdoc] Fix `--show-coverage` when JSON output format is used

I realized while looking on the docs.rs page of the `sysinfo` crate that the coverage numbers displayed were wrong:

![image](https://github.com/user-attachments/assets/264b2e25-6271-4ed1-8b35-e8bd4fd475c6)

I realized that it was because `--show-coverage --output-format=json` was relying on the same logic as the JSON output for the doc generation whereas it should not. I fixed it by changing the API for querying `is_json` a bit.

The underlying issue is that JSON output format is stripping reexports of items from private modules.

r? ``@notriddle``
Diffstat (limited to 'tests/rustdoc-ui')
-rw-r--r--tests/rustdoc-ui/show-coverage-json.rs13
-rw-r--r--tests/rustdoc-ui/show-coverage-json.stdout1
-rw-r--r--tests/rustdoc-ui/show-coverage.rs13
-rw-r--r--tests/rustdoc-ui/show-coverage.stdout7
4 files changed, 34 insertions, 0 deletions
diff --git a/tests/rustdoc-ui/show-coverage-json.rs b/tests/rustdoc-ui/show-coverage-json.rs
new file mode 100644
index 00000000000..3851e34fe35
--- /dev/null
+++ b/tests/rustdoc-ui/show-coverage-json.rs
@@ -0,0 +1,13 @@
+//@ compile-flags: -Z unstable-options --show-coverage --output-format=json
+//@ check-pass
+
+mod bar {
+    /// a
+    ///
+    /// ```
+    /// let x = 0;
+    /// ```
+    pub struct Foo;
+}
+
+pub use bar::Foo;
diff --git a/tests/rustdoc-ui/show-coverage-json.stdout b/tests/rustdoc-ui/show-coverage-json.stdout
new file mode 100644
index 00000000000..ed5b5a60212
--- /dev/null
+++ b/tests/rustdoc-ui/show-coverage-json.stdout
@@ -0,0 +1 @@
+{"$DIR/show-coverage-json.rs":{"total":2,"with_docs":1,"total_examples":2,"with_examples":1}}
diff --git a/tests/rustdoc-ui/show-coverage.rs b/tests/rustdoc-ui/show-coverage.rs
new file mode 100644
index 00000000000..00bb1606a82
--- /dev/null
+++ b/tests/rustdoc-ui/show-coverage.rs
@@ -0,0 +1,13 @@
+//@ compile-flags: -Z unstable-options --show-coverage
+//@ check-pass
+
+mod bar {
+    /// a
+    ///
+    /// ```
+    /// let x = 0;
+    /// ```
+    pub struct Foo;
+}
+
+pub use bar::Foo;
diff --git a/tests/rustdoc-ui/show-coverage.stdout b/tests/rustdoc-ui/show-coverage.stdout
new file mode 100644
index 00000000000..b3b7679771f
--- /dev/null
+++ b/tests/rustdoc-ui/show-coverage.stdout
@@ -0,0 +1,7 @@
++-------------------------------------+------------+------------+------------+------------+
+| File                                | Documented | Percentage |   Examples | Percentage |
++-------------------------------------+------------+------------+------------+------------+
+| ...ests/rustdoc-ui/show-coverage.rs |          1 |      50.0% |          1 |      50.0% |
++-------------------------------------+------------+------------+------------+------------+
+| Total                               |          1 |      50.0% |          1 |      50.0% |
++-------------------------------------+------------+------------+------------+------------+