Skip to content

Commit 9c254c1

Browse files
Update how doc examples are counted
1 parent 631c806 commit 9c254c1

File tree

12 files changed

+47
-26
lines changed

12 files changed

+47
-26
lines changed

src/librustdoc/passes/calculate_doc_coverage.rs

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ impl ItemCount {
4747
if has_docs {
4848
self.with_docs += 1;
4949
}
50-
if should_have_doc_examples {
50+
if should_have_doc_examples || has_doc_example {
51+
self.total_examples += 1;
52+
}
53+
if has_doc_example {
5154
self.with_examples += 1;
52-
if has_doc_example {
53-
self.with_examples += 1;
54-
}
5555
}
5656
}
5757

@@ -246,20 +246,18 @@ impl fold::DocFolder for CoverageCalculator {
246246
| clean::StaticItem(_)
247247
| clean::ConstantItem(_)
248248
);
249-
if should_have_doc_examples {
250-
find_testable_code(
251-
&i.attrs
252-
.doc_strings
253-
.iter()
254-
.map(|d| d.as_str())
255-
.collect::<Vec<_>>()
256-
.join("\n"),
257-
&mut tests,
258-
ErrorCodes::No,
259-
false,
260-
None,
261-
);
262-
}
249+
find_testable_code(
250+
&i.attrs
251+
.doc_strings
252+
.iter()
253+
.map(|d| d.as_str())
254+
.collect::<Vec<_>>()
255+
.join("\n"),
256+
&mut tests,
257+
ErrorCodes::No,
258+
false,
259+
None,
260+
);
263261

264262
let has_doc_example = tests.found_tests != 0;
265263
debug!("counting {:?} {:?} in {}", i.type_(), i.name, i.source.filename);
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
+-------------------------------------+------------+------------+------------+------------+
22
| File | Documented | Percentage | Examples | Percentage |
33
+-------------------------------------+------------+------------+------------+------------+
4+
| ...est/rustdoc-ui/coverage/basic.rs | 7 | 50.0% | 0 | 0.0% |
45
+-------------------------------------+------------+------------+------------+------------+
5-
| Total | 0 | 0.0% | 0 | 0.0% |
6+
| Total | 7 | 50.0% | 0 | 0.0% |
67
+-------------------------------------+------------+------------+------------+------------+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// check-pass
2+
// compile-flags:-Z unstable-options --output-format json --show-coverage
3+
4+
// This check ensures that only one doc example is counted since they're "optional" on
5+
// certain items.
6+
7+
/// ```
8+
/// let x = 12;
9+
/// ```
10+
pub const Foo: u32 = 0;
11+
12+
/// doc
13+
pub const Bar: u32 = 0;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"$DIR/doc-examples-json.rs":{"total":3,"with_docs":2,"total_examples":2,"with_examples":1}}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
+-------------------------------------+------------+------------+------------+------------+
22
| File | Documented | Percentage | Examples | Percentage |
33
+-------------------------------------+------------+------------+------------+------------+
4+
| ...tdoc-ui/coverage/doc-examples.rs | 4 | 100.0% | 2 | 50.0% |
45
+-------------------------------------+------------+------------+------------+------------+
5-
| Total | 0 | 0.0% | 0 | 0.0% |
6+
| Total | 4 | 100.0% | 2 | 50.0% |
67
+-------------------------------------+------------+------------+------------+------------+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
+-------------------------------------+------------+------------+------------+------------+
22
| File | Documented | Percentage | Examples | Percentage |
33
+-------------------------------------+------------+------------+------------+------------+
4+
| ...est/rustdoc-ui/coverage/empty.rs | 0 | 0.0% | 0 | 0.0% |
45
+-------------------------------------+------------+------------+------------+------------+
56
| Total | 0 | 0.0% | 0 | 0.0% |
67
+-------------------------------------+------------+------------+------------+------------+
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
+-------------------------------------+------------+------------+------------+------------+
22
| File | Documented | Percentage | Examples | Percentage |
33
+-------------------------------------+------------+------------+------------+------------+
4+
| ...est/rustdoc-ui/coverage/enums.rs | 6 | 75.0% | 0 | 0.0% |
45
+-------------------------------------+------------+------------+------------+------------+
5-
| Total | 0 | 0.0% | 0 | 0.0% |
6+
| Total | 6 | 75.0% | 0 | 0.0% |
67
+-------------------------------------+------------+------------+------------+------------+
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
+-------------------------------------+------------+------------+------------+------------+
22
| File | Documented | Percentage | Examples | Percentage |
33
+-------------------------------------+------------+------------+------------+------------+
4+
| ...st/rustdoc-ui/coverage/exotic.rs | 1 | 100.0% | 0 | 0.0% |
5+
| <anon> | 2 | 100.0% | 0 | 0.0% |
46
+-------------------------------------+------------+------------+------------+------------+
5-
| Total | 0 | 0.0% | 0 | 0.0% |
7+
| Total | 3 | 100.0% | 0 | 0.0% |
68
+-------------------------------------+------------+------------+------------+------------+
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"$DIR/json.rs":{"total":17,"with_docs":12,"total_examples":0,"with_examples":11}}
1+
{"$DIR/json.rs":{"total":17,"with_docs":12,"total_examples":15,"with_examples":6}}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
+-------------------------------------+------------+------------+------------+------------+
22
| File | Documented | Percentage | Examples | Percentage |
33
+-------------------------------------+------------+------------+------------+------------+
4+
| ...t/rustdoc-ui/coverage/private.rs | 4 | 57.1% | 0 | 0.0% |
45
+-------------------------------------+------------+------------+------------+------------+
5-
| Total | 0 | 0.0% | 0 | 0.0% |
6+
| Total | 4 | 57.1% | 0 | 0.0% |
67
+-------------------------------------+------------+------------+------------+------------+
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
+-------------------------------------+------------+------------+------------+------------+
22
| File | Documented | Percentage | Examples | Percentage |
33
+-------------------------------------+------------+------------+------------+------------+
4+
| ...oc-ui/coverage/statics-consts.rs | 6 | 85.7% | 0 | 0.0% |
45
+-------------------------------------+------------+------------+------------+------------+
5-
| Total | 0 | 0.0% | 0 | 0.0% |
6+
| Total | 6 | 85.7% | 0 | 0.0% |
67
+-------------------------------------+------------+------------+------------+------------+
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
+-------------------------------------+------------+------------+------------+------------+
22
| File | Documented | Percentage | Examples | Percentage |
33
+-------------------------------------+------------+------------+------------+------------+
4+
| ...st/rustdoc-ui/coverage/traits.rs | 6 | 85.7% | 0 | 0.0% |
45
+-------------------------------------+------------+------------+------------+------------+
5-
| Total | 0 | 0.0% | 0 | 0.0% |
6+
| Total | 6 | 85.7% | 0 | 0.0% |
67
+-------------------------------------+------------+------------+------------+------------+

0 commit comments

Comments
 (0)