Skip to content

Commit 63bdd29

Browse files
add tests for doc coverage
1 parent 3ce19b4 commit 63bdd29

File tree

14 files changed

+251
-0
lines changed

14 files changed

+251
-0
lines changed

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

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// compile-flags:-Z unstable-options --show-coverage
2+
// compile-pass
3+
4+
#![feature(extern_types)]
5+
6+
//! Make sure to have some docs on your crate root
7+
8+
/// This struct is documented, but its fields are not.
9+
///
10+
/// However, one field is private, so it shouldn't show in the total.
11+
pub struct SomeStruct {
12+
pub some_field: usize,
13+
other_field: usize,
14+
}
15+
16+
impl SomeStruct {
17+
/// Method with docs
18+
pub fn this_fn(&self) {}
19+
20+
// Method without docs
21+
pub fn other_method(&self) {}
22+
}
23+
24+
// struct without docs
25+
pub struct OtherStruct;
26+
27+
// function with no docs
28+
pub fn some_fn() {}
29+
30+
/// Function with docs
31+
pub fn other_fn() {}
32+
33+
pub enum SomeEnum {
34+
/// Some of these variants are documented...
35+
VarOne,
36+
/// ...but some of them are not.
37+
VarTwo,
38+
// (like this one)
39+
VarThree,
40+
}
41+
42+
/// There's a macro here, too
43+
#[macro_export]
44+
macro_rules! some_macro {
45+
() => {};
46+
}
47+
48+
extern {
49+
pub type ExternType;
50+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
+---------------------------+------------+------------+------------+
2+
| Item Type | Documented | Total | Percentage |
3+
+---------------------------+------------+------------+------------+
4+
| Modules | 1 | 1 | 100.0% |
5+
| Functions | 1 | 2 | 50.0% |
6+
| Structs | 1 | 2 | 50.0% |
7+
| Struct Fields | 0 | 1 | 0.0% |
8+
| Enums | 0 | 1 | 0.0% |
9+
| Enum Variants | 2 | 3 | 66.7% |
10+
| Methods | 1 | 2 | 50.0% |
11+
| Macros | 1 | 1 | 100.0% |
12+
| Extern Types | 0 | 1 | 0.0% |
13+
+---------------------------+------------+------------+------------+
14+
| Total | 7 | 14 | 50.0% |
15+
+---------------------------+------------+------------+------------+

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// compile-flags:-Z unstable-options --show-coverage
2+
// compile-pass
3+
4+
// an empty crate still has one item to document: the crate root
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
+---------------------------+------------+------------+------------+
2+
| Item Type | Documented | Total | Percentage |
3+
+---------------------------+------------+------------+------------+
4+
| Modules | 0 | 1 | 0.0% |
5+
+---------------------------+------------+------------+------------+
6+
| Total | 0 | 1 | 0.0% |
7+
+---------------------------+------------+------------+------------+

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// compile-flags:-Z unstable-options --show-coverage
2+
// compile-pass
3+
4+
//! (remember the crate root is still a module)
5+
6+
/// so check out this enum here
7+
pub enum ThisEnum {
8+
/// this variant has some weird stuff going on
9+
VarOne {
10+
/// like, it has some named fields inside
11+
field_one: usize,
12+
// (these show up as struct fields)
13+
field_two: usize,
14+
},
15+
/// here's another variant for you
16+
VarTwo(String),
17+
// but not all of them need to be documented as thoroughly
18+
VarThree,
19+
}
20+
21+
/// uninhabited enums? sure, let's throw one of those around
22+
pub enum OtherEnum {}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
+---------------------------+------------+------------+------------+
2+
| Item Type | Documented | Total | Percentage |
3+
+---------------------------+------------+------------+------------+
4+
| Modules | 1 | 1 | 100.0% |
5+
| Struct Fields | 1 | 2 | 50.0% |
6+
| Enums | 2 | 2 | 100.0% |
7+
| Enum Variants | 2 | 3 | 66.7% |
8+
+---------------------------+------------+------------+------------+
9+
| Total | 6 | 8 | 75.0% |
10+
+---------------------------+------------+------------+------------+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// compile-flags:-Z unstable-options --show-coverage
2+
// compile-pass
3+
4+
#![feature(doc_keyword)]
5+
6+
//! the features only used in std also have entries in the table, so make sure those get pulled out
7+
//! properly as well
8+
9+
/// woo, check it out, we can write our own primitive docs lol
10+
#[doc(primitive="unit")]
11+
mod prim_unit {}
12+
13+
/// keywords? sure, pile them on
14+
#[doc(keyword="where")]
15+
mod where_keyword {}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
+---------------------------+------------+------------+------------+
2+
| Item Type | Documented | Total | Percentage |
3+
+---------------------------+------------+------------+------------+
4+
| Modules | 1 | 1 | 100.0% |
5+
| Primitives | 1 | 1 | 100.0% |
6+
| Keywords | 1 | 1 | 100.0% |
7+
+---------------------------+------------+------------+------------+
8+
| Total | 3 | 3 | 100.0% |
9+
+---------------------------+------------+------------+------------+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// compile-flags:-Z unstable-options --show-coverage --document-private-items
2+
// compile-pass
3+
4+
#![allow(unused)]
5+
6+
//! when `--document-private-items` is passed, nothing is safe. everything must have docs or your
7+
//! score will suffer the consequences
8+
9+
mod this_mod {
10+
fn private_fn() {}
11+
}
12+
13+
/// See, our public items have docs!
14+
pub struct SomeStruct {
15+
/// Look, all perfectly documented!
16+
pub field: usize,
17+
other: usize,
18+
}
19+
20+
/// Nothing shady going on here. Just a bunch of well-documented code. (cough)
21+
pub fn public_fn() {}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
+---------------------------+------------+------------+------------+
2+
| Item Type | Documented | Total | Percentage |
3+
+---------------------------+------------+------------+------------+
4+
| Modules | 1 | 2 | 50.0% |
5+
| Functions | 1 | 2 | 50.0% |
6+
| Structs | 1 | 1 | 100.0% |
7+
| Struct Fields | 1 | 2 | 50.0% |
8+
+---------------------------+------------+------------+------------+
9+
| Total | 4 | 7 | 57.1% |
10+
+---------------------------+------------+------------+------------+

0 commit comments

Comments
 (0)