]> git.lizzy.rs Git - rust.git/commitdiff
Update how doc examples are counted
authorGuillaume Gomez <guillaume1.gomez@gmail.com>
Thu, 20 Aug 2020 19:15:02 +0000 (21:15 +0200)
committerGuillaume Gomez <guillaume1.gomez@gmail.com>
Thu, 20 Aug 2020 19:26:57 +0000 (21:26 +0200)
12 files changed:
src/librustdoc/passes/calculate_doc_coverage.rs
src/test/rustdoc-ui/coverage/basic.stdout
src/test/rustdoc-ui/coverage/doc-examples-json.rs [new file with mode: 0644]
src/test/rustdoc-ui/coverage/doc-examples-json.stdout [new file with mode: 0644]
src/test/rustdoc-ui/coverage/doc-examples.stdout
src/test/rustdoc-ui/coverage/empty.stdout
src/test/rustdoc-ui/coverage/enums.stdout
src/test/rustdoc-ui/coverage/exotic.stdout
src/test/rustdoc-ui/coverage/json.stdout
src/test/rustdoc-ui/coverage/private.stdout
src/test/rustdoc-ui/coverage/statics-consts.stdout
src/test/rustdoc-ui/coverage/traits.stdout

index 93a271b81fb512d5dafb675293cf74dcba5c70e5..1bdd337dabecb4feb9ddacac2d2fb6e893bb8580 100644 (file)
@@ -47,11 +47,11 @@ fn count_item(
         if has_docs {
             self.with_docs += 1;
         }
-        if should_have_doc_examples {
+        if should_have_doc_examples || has_doc_example {
+            self.total_examples += 1;
+        }
+        if has_doc_example {
             self.with_examples += 1;
-            if has_doc_example {
-                self.with_examples += 1;
-            }
         }
     }
 
@@ -246,20 +246,18 @@ fn fold_item(&mut self, i: clean::Item) -> Option<clean::Item> {
                     | clean::StaticItem(_)
                     | clean::ConstantItem(_)
                 );
-                if should_have_doc_examples {
-                    find_testable_code(
-                        &i.attrs
-                            .doc_strings
-                            .iter()
-                            .map(|d| d.as_str())
-                            .collect::<Vec<_>>()
-                            .join("\n"),
-                        &mut tests,
-                        ErrorCodes::No,
-                        false,
-                        None,
-                    );
-                }
+                find_testable_code(
+                    &i.attrs
+                        .doc_strings
+                        .iter()
+                        .map(|d| d.as_str())
+                        .collect::<Vec<_>>()
+                        .join("\n"),
+                    &mut tests,
+                    ErrorCodes::No,
+                    false,
+                    None,
+                );
 
                 let has_doc_example = tests.found_tests != 0;
                 debug!("counting {:?} {:?} in {}", i.type_(), i.name, i.source.filename);
index 3a869016505b127986860fae088b14dd737d3518..3c602b3da4c7c8952347566f6acb16fbcf7ebea4 100644 (file)
@@ -1,6 +1,7 @@
 +-------------------------------------+------------+------------+------------+------------+
 | File                                | Documented | Percentage |   Examples | Percentage |
 +-------------------------------------+------------+------------+------------+------------+
+| ...est/rustdoc-ui/coverage/basic.rs |          7 |      50.0% |          0 |       0.0% |
 +-------------------------------------+------------+------------+------------+------------+
-| Total                               |          0 |       0.0% |          0 |       0.0% |
+| Total                               |          7 |      50.0% |          0 |       0.0% |
 +-------------------------------------+------------+------------+------------+------------+
diff --git a/src/test/rustdoc-ui/coverage/doc-examples-json.rs b/src/test/rustdoc-ui/coverage/doc-examples-json.rs
new file mode 100644 (file)
index 0000000..1da1813
--- /dev/null
@@ -0,0 +1,13 @@
+// check-pass
+// compile-flags:-Z unstable-options --output-format json --show-coverage
+
+// This check ensures that only one doc example is counted since they're "optional" on
+// certain items.
+
+/// ```
+/// let x = 12;
+/// ```
+pub const Foo: u32 = 0;
+
+/// doc
+pub const Bar: u32 = 0;
diff --git a/src/test/rustdoc-ui/coverage/doc-examples-json.stdout b/src/test/rustdoc-ui/coverage/doc-examples-json.stdout
new file mode 100644 (file)
index 0000000..92f5855
--- /dev/null
@@ -0,0 +1 @@
+{"$DIR/doc-examples-json.rs":{"total":3,"with_docs":2,"total_examples":2,"with_examples":1}}
index 3a869016505b127986860fae088b14dd737d3518..10ed13c9ff566c76d169649cc58949d7031dd442 100644 (file)
@@ -1,6 +1,7 @@
 +-------------------------------------+------------+------------+------------+------------+
 | File                                | Documented | Percentage |   Examples | Percentage |
 +-------------------------------------+------------+------------+------------+------------+
+| ...tdoc-ui/coverage/doc-examples.rs |          4 |     100.0% |          2 |      50.0% |
 +-------------------------------------+------------+------------+------------+------------+
-| Total                               |          0 |       0.0% |          0 |       0.0% |
+| Total                               |          4 |     100.0% |          2 |      50.0% |
 +-------------------------------------+------------+------------+------------+------------+
index 3a869016505b127986860fae088b14dd737d3518..890a7d56e162d09bb8e0cc933a75d261cc634a26 100644 (file)
@@ -1,6 +1,7 @@
 +-------------------------------------+------------+------------+------------+------------+
 | File                                | Documented | Percentage |   Examples | Percentage |
 +-------------------------------------+------------+------------+------------+------------+
+| ...est/rustdoc-ui/coverage/empty.rs |          0 |       0.0% |          0 |       0.0% |
 +-------------------------------------+------------+------------+------------+------------+
 | Total                               |          0 |       0.0% |          0 |       0.0% |
 +-------------------------------------+------------+------------+------------+------------+
index 3a869016505b127986860fae088b14dd737d3518..64c012c1f66e3dfea1eea7a743511b78a08e0f5f 100644 (file)
@@ -1,6 +1,7 @@
 +-------------------------------------+------------+------------+------------+------------+
 | File                                | Documented | Percentage |   Examples | Percentage |
 +-------------------------------------+------------+------------+------------+------------+
+| ...est/rustdoc-ui/coverage/enums.rs |          6 |      75.0% |          0 |       0.0% |
 +-------------------------------------+------------+------------+------------+------------+
-| Total                               |          0 |       0.0% |          0 |       0.0% |
+| Total                               |          6 |      75.0% |          0 |       0.0% |
 +-------------------------------------+------------+------------+------------+------------+
index 3a869016505b127986860fae088b14dd737d3518..e282ff128437513e3a88564d4c564db7ce263d8c 100644 (file)
@@ -1,6 +1,8 @@
 +-------------------------------------+------------+------------+------------+------------+
 | File                                | Documented | Percentage |   Examples | Percentage |
 +-------------------------------------+------------+------------+------------+------------+
+| ...st/rustdoc-ui/coverage/exotic.rs |          1 |     100.0% |          0 |       0.0% |
+| <anon>                              |          2 |     100.0% |          0 |       0.0% |
 +-------------------------------------+------------+------------+------------+------------+
-| Total                               |          0 |       0.0% |          0 |       0.0% |
+| Total                               |          3 |     100.0% |          0 |       0.0% |
 +-------------------------------------+------------+------------+------------+------------+
index 6218b5fe07a4e7a8641cf7206773987b4e6df31f..c2be73ce3edd7c14b99a46e3445948ed27187041 100644 (file)
@@ -1 +1 @@
-{"$DIR/json.rs":{"total":17,"with_docs":12,"total_examples":0,"with_examples":11}}
+{"$DIR/json.rs":{"total":17,"with_docs":12,"total_examples":15,"with_examples":6}}
index 3a869016505b127986860fae088b14dd737d3518..37a0f5187b5122fc745e20f6a195db081dd36a43 100644 (file)
@@ -1,6 +1,7 @@
 +-------------------------------------+------------+------------+------------+------------+
 | File                                | Documented | Percentage |   Examples | Percentage |
 +-------------------------------------+------------+------------+------------+------------+
+| ...t/rustdoc-ui/coverage/private.rs |          4 |      57.1% |          0 |       0.0% |
 +-------------------------------------+------------+------------+------------+------------+
-| Total                               |          0 |       0.0% |          0 |       0.0% |
+| Total                               |          4 |      57.1% |          0 |       0.0% |
 +-------------------------------------+------------+------------+------------+------------+
index 3a869016505b127986860fae088b14dd737d3518..dbea3a3ea23cf5f98a59f1611d89ed805545b647 100644 (file)
@@ -1,6 +1,7 @@
 +-------------------------------------+------------+------------+------------+------------+
 | File                                | Documented | Percentage |   Examples | Percentage |
 +-------------------------------------+------------+------------+------------+------------+
+| ...oc-ui/coverage/statics-consts.rs |          6 |      85.7% |          0 |       0.0% |
 +-------------------------------------+------------+------------+------------+------------+
-| Total                               |          0 |       0.0% |          0 |       0.0% |
+| Total                               |          6 |      85.7% |          0 |       0.0% |
 +-------------------------------------+------------+------------+------------+------------+
index 3a869016505b127986860fae088b14dd737d3518..e04d48b4980c4c299859b70d16bee676c0745c4e 100644 (file)
@@ -1,6 +1,7 @@
 +-------------------------------------+------------+------------+------------+------------+
 | File                                | Documented | Percentage |   Examples | Percentage |
 +-------------------------------------+------------+------------+------------+------------+
+| ...st/rustdoc-ui/coverage/traits.rs |          6 |      85.7% |          0 |       0.0% |
 +-------------------------------------+------------+------------+------------+------------+
-| Total                               |          0 |       0.0% |          0 |       0.0% |
+| Total                               |          6 |      85.7% |          0 |       0.0% |
 +-------------------------------------+------------+------------+------------+------------+