add tests for doc coverage
This commit is contained in:
parent
3ce19b4a2c
commit
63bdd29ef4
14 changed files with 251 additions and 0 deletions
50
src/test/rustdoc-ui/coverage/basic.rs
Normal file
50
src/test/rustdoc-ui/coverage/basic.rs
Normal file
|
@ -0,0 +1,50 @@
|
|||
// compile-flags:-Z unstable-options --show-coverage
|
||||
// compile-pass
|
||||
|
||||
#![feature(extern_types)]
|
||||
|
||||
//! Make sure to have some docs on your crate root
|
||||
|
||||
/// This struct is documented, but its fields are not.
|
||||
///
|
||||
/// However, one field is private, so it shouldn't show in the total.
|
||||
pub struct SomeStruct {
|
||||
pub some_field: usize,
|
||||
other_field: usize,
|
||||
}
|
||||
|
||||
impl SomeStruct {
|
||||
/// Method with docs
|
||||
pub fn this_fn(&self) {}
|
||||
|
||||
// Method without docs
|
||||
pub fn other_method(&self) {}
|
||||
}
|
||||
|
||||
// struct without docs
|
||||
pub struct OtherStruct;
|
||||
|
||||
// function with no docs
|
||||
pub fn some_fn() {}
|
||||
|
||||
/// Function with docs
|
||||
pub fn other_fn() {}
|
||||
|
||||
pub enum SomeEnum {
|
||||
/// Some of these variants are documented...
|
||||
VarOne,
|
||||
/// ...but some of them are not.
|
||||
VarTwo,
|
||||
// (like this one)
|
||||
VarThree,
|
||||
}
|
||||
|
||||
/// There's a macro here, too
|
||||
#[macro_export]
|
||||
macro_rules! some_macro {
|
||||
() => {};
|
||||
}
|
||||
|
||||
extern {
|
||||
pub type ExternType;
|
||||
}
|
15
src/test/rustdoc-ui/coverage/basic.stdout
Normal file
15
src/test/rustdoc-ui/coverage/basic.stdout
Normal file
|
@ -0,0 +1,15 @@
|
|||
+---------------------------+------------+------------+------------+
|
||||
| Item Type | Documented | Total | Percentage |
|
||||
+---------------------------+------------+------------+------------+
|
||||
| Modules | 1 | 1 | 100.0% |
|
||||
| Functions | 1 | 2 | 50.0% |
|
||||
| Structs | 1 | 2 | 50.0% |
|
||||
| Struct Fields | 0 | 1 | 0.0% |
|
||||
| Enums | 0 | 1 | 0.0% |
|
||||
| Enum Variants | 2 | 3 | 66.7% |
|
||||
| Methods | 1 | 2 | 50.0% |
|
||||
| Macros | 1 | 1 | 100.0% |
|
||||
| Extern Types | 0 | 1 | 0.0% |
|
||||
+---------------------------+------------+------------+------------+
|
||||
| Total | 7 | 14 | 50.0% |
|
||||
+---------------------------+------------+------------+------------+
|
4
src/test/rustdoc-ui/coverage/empty.rs
Normal file
4
src/test/rustdoc-ui/coverage/empty.rs
Normal file
|
@ -0,0 +1,4 @@
|
|||
// compile-flags:-Z unstable-options --show-coverage
|
||||
// compile-pass
|
||||
|
||||
// an empty crate still has one item to document: the crate root
|
7
src/test/rustdoc-ui/coverage/empty.stdout
Normal file
7
src/test/rustdoc-ui/coverage/empty.stdout
Normal file
|
@ -0,0 +1,7 @@
|
|||
+---------------------------+------------+------------+------------+
|
||||
| Item Type | Documented | Total | Percentage |
|
||||
+---------------------------+------------+------------+------------+
|
||||
| Modules | 0 | 1 | 0.0% |
|
||||
+---------------------------+------------+------------+------------+
|
||||
| Total | 0 | 1 | 0.0% |
|
||||
+---------------------------+------------+------------+------------+
|
22
src/test/rustdoc-ui/coverage/enums.rs
Normal file
22
src/test/rustdoc-ui/coverage/enums.rs
Normal file
|
@ -0,0 +1,22 @@
|
|||
// compile-flags:-Z unstable-options --show-coverage
|
||||
// compile-pass
|
||||
|
||||
//! (remember the crate root is still a module)
|
||||
|
||||
/// so check out this enum here
|
||||
pub enum ThisEnum {
|
||||
/// this variant has some weird stuff going on
|
||||
VarOne {
|
||||
/// like, it has some named fields inside
|
||||
field_one: usize,
|
||||
// (these show up as struct fields)
|
||||
field_two: usize,
|
||||
},
|
||||
/// here's another variant for you
|
||||
VarTwo(String),
|
||||
// but not all of them need to be documented as thoroughly
|
||||
VarThree,
|
||||
}
|
||||
|
||||
/// uninhabited enums? sure, let's throw one of those around
|
||||
pub enum OtherEnum {}
|
10
src/test/rustdoc-ui/coverage/enums.stdout
Normal file
10
src/test/rustdoc-ui/coverage/enums.stdout
Normal file
|
@ -0,0 +1,10 @@
|
|||
+---------------------------+------------+------------+------------+
|
||||
| Item Type | Documented | Total | Percentage |
|
||||
+---------------------------+------------+------------+------------+
|
||||
| Modules | 1 | 1 | 100.0% |
|
||||
| Struct Fields | 1 | 2 | 50.0% |
|
||||
| Enums | 2 | 2 | 100.0% |
|
||||
| Enum Variants | 2 | 3 | 66.7% |
|
||||
+---------------------------+------------+------------+------------+
|
||||
| Total | 6 | 8 | 75.0% |
|
||||
+---------------------------+------------+------------+------------+
|
15
src/test/rustdoc-ui/coverage/exotic.rs
Normal file
15
src/test/rustdoc-ui/coverage/exotic.rs
Normal file
|
@ -0,0 +1,15 @@
|
|||
// compile-flags:-Z unstable-options --show-coverage
|
||||
// compile-pass
|
||||
|
||||
#![feature(doc_keyword)]
|
||||
|
||||
//! the features only used in std also have entries in the table, so make sure those get pulled out
|
||||
//! properly as well
|
||||
|
||||
/// woo, check it out, we can write our own primitive docs lol
|
||||
#[doc(primitive="unit")]
|
||||
mod prim_unit {}
|
||||
|
||||
/// keywords? sure, pile them on
|
||||
#[doc(keyword="where")]
|
||||
mod where_keyword {}
|
9
src/test/rustdoc-ui/coverage/exotic.stdout
Normal file
9
src/test/rustdoc-ui/coverage/exotic.stdout
Normal file
|
@ -0,0 +1,9 @@
|
|||
+---------------------------+------------+------------+------------+
|
||||
| Item Type | Documented | Total | Percentage |
|
||||
+---------------------------+------------+------------+------------+
|
||||
| Modules | 1 | 1 | 100.0% |
|
||||
| Primitives | 1 | 1 | 100.0% |
|
||||
| Keywords | 1 | 1 | 100.0% |
|
||||
+---------------------------+------------+------------+------------+
|
||||
| Total | 3 | 3 | 100.0% |
|
||||
+---------------------------+------------+------------+------------+
|
21
src/test/rustdoc-ui/coverage/private.rs
Normal file
21
src/test/rustdoc-ui/coverage/private.rs
Normal file
|
@ -0,0 +1,21 @@
|
|||
// compile-flags:-Z unstable-options --show-coverage --document-private-items
|
||||
// compile-pass
|
||||
|
||||
#![allow(unused)]
|
||||
|
||||
//! when `--document-private-items` is passed, nothing is safe. everything must have docs or your
|
||||
//! score will suffer the consequences
|
||||
|
||||
mod this_mod {
|
||||
fn private_fn() {}
|
||||
}
|
||||
|
||||
/// See, our public items have docs!
|
||||
pub struct SomeStruct {
|
||||
/// Look, all perfectly documented!
|
||||
pub field: usize,
|
||||
other: usize,
|
||||
}
|
||||
|
||||
/// Nothing shady going on here. Just a bunch of well-documented code. (cough)
|
||||
pub fn public_fn() {}
|
10
src/test/rustdoc-ui/coverage/private.stdout
Normal file
10
src/test/rustdoc-ui/coverage/private.stdout
Normal file
|
@ -0,0 +1,10 @@
|
|||
+---------------------------+------------+------------+------------+
|
||||
| Item Type | Documented | Total | Percentage |
|
||||
+---------------------------+------------+------------+------------+
|
||||
| Modules | 1 | 2 | 50.0% |
|
||||
| Functions | 1 | 2 | 50.0% |
|
||||
| Structs | 1 | 1 | 100.0% |
|
||||
| Struct Fields | 1 | 2 | 50.0% |
|
||||
+---------------------------+------------+------------+------------+
|
||||
| Total | 4 | 7 | 57.1% |
|
||||
+---------------------------+------------+------------+------------+
|
23
src/test/rustdoc-ui/coverage/statics-consts.rs
Normal file
23
src/test/rustdoc-ui/coverage/statics-consts.rs
Normal file
|
@ -0,0 +1,23 @@
|
|||
// compile-flags:-Z unstable-options --show-coverage
|
||||
// compile-pass
|
||||
|
||||
//! gotta make sure we can count statics and consts correctly, too
|
||||
|
||||
/// static like electricity, right?
|
||||
pub static THIS_STATIC: usize = 0;
|
||||
|
||||
/// (it's not electricity, is it)
|
||||
pub const THIS_CONST: usize = 1;
|
||||
|
||||
/// associated consts show up separately, but let's throw them in as well
|
||||
pub trait SomeTrait {
|
||||
/// just like that, yeah
|
||||
const ASSOC_CONST: usize;
|
||||
}
|
||||
|
||||
pub struct SomeStruct;
|
||||
|
||||
impl SomeStruct {
|
||||
/// wait, structs can have them too, can't forget those
|
||||
pub const ASSOC_CONST: usize = 100;
|
||||
}
|
12
src/test/rustdoc-ui/coverage/statics-consts.stdout
Normal file
12
src/test/rustdoc-ui/coverage/statics-consts.stdout
Normal file
|
@ -0,0 +1,12 @@
|
|||
+---------------------------+------------+------------+------------+
|
||||
| Item Type | Documented | Total | Percentage |
|
||||
+---------------------------+------------+------------+------------+
|
||||
| Modules | 1 | 1 | 100.0% |
|
||||
| Structs | 0 | 1 | 0.0% |
|
||||
| Traits | 1 | 1 | 100.0% |
|
||||
| Associated Constants | 2 | 2 | 100.0% |
|
||||
| Statics | 1 | 1 | 100.0% |
|
||||
| Constants | 1 | 1 | 100.0% |
|
||||
+---------------------------+------------+------------+------------+
|
||||
| Total | 6 | 7 | 85.7% |
|
||||
+---------------------------+------------+------------+------------+
|
37
src/test/rustdoc-ui/coverage/traits.rs
Normal file
37
src/test/rustdoc-ui/coverage/traits.rs
Normal file
|
@ -0,0 +1,37 @@
|
|||
// compile-flags:-Z unstable-options --show-coverage
|
||||
// compile-pass
|
||||
|
||||
#![feature(trait_alias)]
|
||||
|
||||
/// look at this trait right here
|
||||
pub trait ThisTrait {
|
||||
/// that's a trait all right
|
||||
fn right_here(&self);
|
||||
|
||||
/// even the provided functions show up as trait methods
|
||||
fn aww_yeah(&self) {}
|
||||
|
||||
/// gotta check those associated types, they're slippery
|
||||
type SomeType;
|
||||
}
|
||||
|
||||
/// so what happens if we take some struct...
|
||||
pub struct SomeStruct;
|
||||
|
||||
/// ...and slap this trait on it?
|
||||
impl ThisTrait for SomeStruct {
|
||||
/// what we get is a perfect combo!
|
||||
fn right_here(&self) {}
|
||||
|
||||
type SomeType = String;
|
||||
}
|
||||
|
||||
/// but what about those aliases? i hear they're pretty exotic
|
||||
pub trait MyAlias = ThisTrait + Send + Sync;
|
||||
|
||||
// FIXME(58624): once rustdoc can process existential types, we need to make sure they're counted
|
||||
// /// woah, getting all existential in here
|
||||
// pub existential type ThisExists: ThisTrait;
|
||||
//
|
||||
// /// why don't we get a little more concrete
|
||||
// pub fn defines() -> ThisExists { SomeStruct {} }
|
16
src/test/rustdoc-ui/coverage/traits.stdout
Normal file
16
src/test/rustdoc-ui/coverage/traits.stdout
Normal file
|
@ -0,0 +1,16 @@
|
|||
+---------------------------+------------+------------+------------+
|
||||
| Item Type | Documented | Total | Percentage |
|
||||
+---------------------------+------------+------------+------------+
|
||||
| Modules | 0 | 1 | 0.0% |
|
||||
| Structs | 1 | 1 | 100.0% |
|
||||
| Traits | 1 | 1 | 100.0% |
|
||||
| Trait Methods | 2 | 2 | 100.0% |
|
||||
| Associated Types | 1 | 1 | 100.0% |
|
||||
| Trait Aliases | 1 | 1 | 100.0% |
|
||||
+---------------------------+------------+------------+------------+
|
||||
| Total (non trait impls) | 6 | 7 | 85.7% |
|
||||
+---------------------------+------------+------------+------------+
|
||||
| Trait Impl Items | 2 | 3 | 66.7% |
|
||||
+---------------------------+------------+------------+------------+
|
||||
| Total | 8 | 10 | 80.0% |
|
||||
+---------------------------+------------+------------+------------+
|
Loading…
Reference in a new issue