Skip to content

Commit 6fb7e02

Browse files
Update rustdoc coverage UI test
1 parent 3307ba8 commit 6fb7e02

File tree

3 files changed

+51
-7
lines changed

3 files changed

+51
-7
lines changed

src/librustdoc/passes/calculate_doc_coverage.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,12 @@ impl fold::DocFolder for CoverageCalculator {
249249
);
250250
if should_have_doc_examples {
251251
find_testable_code(
252-
&i.attrs.doc_strings.iter().map(|d| d.as_str()).collect::<Vec<_>>().join("\n"),
252+
&i.attrs
253+
.doc_strings
254+
.iter()
255+
.map(|d| d.as_str())
256+
.collect::<Vec<_>>()
257+
.join("\n"),
253258
&mut tests,
254259
ErrorCodes::No,
255260
false,
@@ -259,10 +264,11 @@ impl fold::DocFolder for CoverageCalculator {
259264

260265
let has_doc_example = tests.found_tests != 0;
261266
debug!("counting {:?} {:?} in {}", i.type_(), i.name, i.source.filename);
262-
self.items
263-
.entry(i.source.filename.clone())
264-
.or_default()
265-
.count_item(has_docs, has_doc_example, should_have_doc_examples);
267+
self.items.entry(i.source.filename.clone()).or_default().count_item(
268+
has_docs,
269+
has_doc_example,
270+
should_have_doc_examples,
271+
);
266272
}
267273
}
268274

src/test/rustdoc-ui/coverage/json.rs

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,54 @@ pub mod foo {
1212
pub struct X;
1313

1414
/// Bar
15+
///
16+
/// ```
17+
/// let x = 12;
18+
/// ```
1519
pub mod bar {
1620
/// bar
1721
pub struct Bar;
1822
/// X
19-
pub enum X { Y }
23+
pub enum X {
24+
/// ```
25+
/// let x = "should be ignored!";
26+
/// ```
27+
Y
28+
}
2029
}
2130

2231
/// yolo
32+
///
33+
/// ```text
34+
/// should not be counted as a code example!
35+
/// ```
2336
pub enum Yolo { X }
2437

38+
impl Yolo {
39+
/// ```
40+
/// let x = "should be ignored!";
41+
/// ```
42+
pub const Const: u32 = 0;
43+
}
44+
2545
pub struct Xo<T: Clone> {
46+
/// ```
47+
/// let x = "should be ignored!";
48+
/// ```
2649
x: T,
2750
}
51+
52+
/// ```
53+
/// let x = "should be ignored!";
54+
/// ```
55+
pub static StaticFoo: u32 = 0;
56+
57+
/// ```
58+
/// let x = "should be ignored!";
59+
/// ```
60+
pub const ConstFoo: u32 = 0;
61+
62+
/// ```
63+
/// let x = "should be ignored!";
64+
/// ```
65+
pub type TypeFoo = u32;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"$DIR/json.rs":{"total":13,"with_docs":7,"with_examples":0}}
1+
{"$DIR/json.rs":{"total":17,"with_docs":12,"total_examples":10,"with_examples":1}}

0 commit comments

Comments
 (0)