Update how doc examples are counted
This commit is contained in:
parent
631c80659d
commit
9c254c18d6
@ -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);
|
||||
|
@ -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% |
|
||||
+-------------------------------------+------------+------------+------------+------------+
|
||||
|
13
src/test/rustdoc-ui/coverage/doc-examples-json.rs
Normal file
13
src/test/rustdoc-ui/coverage/doc-examples-json.rs
Normal file
@ -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;
|
1
src/test/rustdoc-ui/coverage/doc-examples-json.stdout
Normal file
1
src/test/rustdoc-ui/coverage/doc-examples-json.stdout
Normal file
@ -0,0 +1 @@
|
||||
{"$DIR/doc-examples-json.rs":{"total":3,"with_docs":2,"total_examples":2,"with_examples":1}}
|
@ -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% |
|
||||
+-------------------------------------+------------+------------+------------+------------+
|
||||
|
@ -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% |
|
||||
+-------------------------------------+------------+------------+------------+------------+
|
||||
|
@ -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% |
|
||||
+-------------------------------------+------------+------------+------------+------------+
|
||||
|
@ -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% |
|
||||
+-------------------------------------+------------+------------+------------+------------+
|
||||
|
@ -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}}
|
||||
|
@ -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% |
|
||||
+-------------------------------------+------------+------------+------------+------------+
|
||||
|
@ -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% |
|
||||
+-------------------------------------+------------+------------+------------+------------+
|
||||
|
@ -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% |
|
||||
+-------------------------------------+------------+------------+------------+------------+
|
||||
|
Loading…
Reference in New Issue
Block a user