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;
- }
}
}
| 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);
+-------------------------------------+------------+------------+------------+------------+
| 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% |
+-------------------------------------+------------+------------+------------+------------+
--- /dev/null
+// 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;
--- /dev/null
+{"$DIR/doc-examples-json.rs":{"total":3,"with_docs":2,"total_examples":2,"with_examples":1}}
+-------------------------------------+------------+------------+------------+------------+
| 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% |
+-------------------------------------+------------+------------+------------+------------+
+-------------------------------------+------------+------------+------------+------------+
| File | Documented | Percentage | Examples | Percentage |
+-------------------------------------+------------+------------+------------+------------+
+| ...est/rustdoc-ui/coverage/empty.rs | 0 | 0.0% | 0 | 0.0% |
+-------------------------------------+------------+------------+------------+------------+
| Total | 0 | 0.0% | 0 | 0.0% |
+-------------------------------------+------------+------------+------------+------------+
+-------------------------------------+------------+------------+------------+------------+
| 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% |
+-------------------------------------+------------+------------+------------+------------+
+-------------------------------------+------------+------------+------------+------------+
| 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% |
+-------------------------------------+------------+------------+------------+------------+
-{"$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}}
+-------------------------------------+------------+------------+------------+------------+
| 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% |
+-------------------------------------+------------+------------+------------+------------+
+-------------------------------------+------------+------------+------------+------------+
| 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% |
+-------------------------------------+------------+------------+------------+------------+
+-------------------------------------+------------+------------+------------+------------+
| 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% |
+-------------------------------------+------------+------------+------------+------------+