]> git.lizzy.rs Git - rust.git/commitdiff
add tests for doc coverage
authorQuietMisdreavus <grey@quietmisdreavus.net>
Thu, 21 Feb 2019 22:02:56 +0000 (16:02 -0600)
committerQuietMisdreavus <grey@quietmisdreavus.net>
Thu, 28 Feb 2019 22:11:21 +0000 (16:11 -0600)
14 files changed:
src/test/rustdoc-ui/coverage/basic.rs [new file with mode: 0644]
src/test/rustdoc-ui/coverage/basic.stdout [new file with mode: 0644]
src/test/rustdoc-ui/coverage/empty.rs [new file with mode: 0644]
src/test/rustdoc-ui/coverage/empty.stdout [new file with mode: 0644]
src/test/rustdoc-ui/coverage/enums.rs [new file with mode: 0644]
src/test/rustdoc-ui/coverage/enums.stdout [new file with mode: 0644]
src/test/rustdoc-ui/coverage/exotic.rs [new file with mode: 0644]
src/test/rustdoc-ui/coverage/exotic.stdout [new file with mode: 0644]
src/test/rustdoc-ui/coverage/private.rs [new file with mode: 0644]
src/test/rustdoc-ui/coverage/private.stdout [new file with mode: 0644]
src/test/rustdoc-ui/coverage/statics-consts.rs [new file with mode: 0644]
src/test/rustdoc-ui/coverage/statics-consts.stdout [new file with mode: 0644]
src/test/rustdoc-ui/coverage/traits.rs [new file with mode: 0644]
src/test/rustdoc-ui/coverage/traits.stdout [new file with mode: 0644]

diff --git a/src/test/rustdoc-ui/coverage/basic.rs b/src/test/rustdoc-ui/coverage/basic.rs
new file mode 100644 (file)
index 0000000..4247fdf
--- /dev/null
@@ -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;
+}
diff --git a/src/test/rustdoc-ui/coverage/basic.stdout b/src/test/rustdoc-ui/coverage/basic.stdout
new file mode 100644 (file)
index 0000000..089ab60
--- /dev/null
@@ -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% |
++---------------------------+------------+------------+------------+
diff --git a/src/test/rustdoc-ui/coverage/empty.rs b/src/test/rustdoc-ui/coverage/empty.rs
new file mode 100644 (file)
index 0000000..463617a
--- /dev/null
@@ -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
diff --git a/src/test/rustdoc-ui/coverage/empty.stdout b/src/test/rustdoc-ui/coverage/empty.stdout
new file mode 100644 (file)
index 0000000..df68205
--- /dev/null
@@ -0,0 +1,7 @@
++---------------------------+------------+------------+------------+
+| Item Type                 | Documented |      Total | Percentage |
++---------------------------+------------+------------+------------+
+| Modules                   |          0 |          1 |       0.0% |
++---------------------------+------------+------------+------------+
+| Total                     |          0 |          1 |       0.0% |
++---------------------------+------------+------------+------------+
diff --git a/src/test/rustdoc-ui/coverage/enums.rs b/src/test/rustdoc-ui/coverage/enums.rs
new file mode 100644 (file)
index 0000000..5cd7f49
--- /dev/null
@@ -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 {}
diff --git a/src/test/rustdoc-ui/coverage/enums.stdout b/src/test/rustdoc-ui/coverage/enums.stdout
new file mode 100644 (file)
index 0000000..651ea09
--- /dev/null
@@ -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% |
++---------------------------+------------+------------+------------+
diff --git a/src/test/rustdoc-ui/coverage/exotic.rs b/src/test/rustdoc-ui/coverage/exotic.rs
new file mode 100644 (file)
index 0000000..b4adf45
--- /dev/null
@@ -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 {}
diff --git a/src/test/rustdoc-ui/coverage/exotic.stdout b/src/test/rustdoc-ui/coverage/exotic.stdout
new file mode 100644 (file)
index 0000000..97eab50
--- /dev/null
@@ -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% |
++---------------------------+------------+------------+------------+
diff --git a/src/test/rustdoc-ui/coverage/private.rs b/src/test/rustdoc-ui/coverage/private.rs
new file mode 100644 (file)
index 0000000..9024185
--- /dev/null
@@ -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() {}
diff --git a/src/test/rustdoc-ui/coverage/private.stdout b/src/test/rustdoc-ui/coverage/private.stdout
new file mode 100644 (file)
index 0000000..f1a5461
--- /dev/null
@@ -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% |
++---------------------------+------------+------------+------------+
diff --git a/src/test/rustdoc-ui/coverage/statics-consts.rs b/src/test/rustdoc-ui/coverage/statics-consts.rs
new file mode 100644 (file)
index 0000000..3c1dd35
--- /dev/null
@@ -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;
+}
diff --git a/src/test/rustdoc-ui/coverage/statics-consts.stdout b/src/test/rustdoc-ui/coverage/statics-consts.stdout
new file mode 100644 (file)
index 0000000..54516fe
--- /dev/null
@@ -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% |
++---------------------------+------------+------------+------------+
diff --git a/src/test/rustdoc-ui/coverage/traits.rs b/src/test/rustdoc-ui/coverage/traits.rs
new file mode 100644 (file)
index 0000000..0a6defa
--- /dev/null
@@ -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 {} }
diff --git a/src/test/rustdoc-ui/coverage/traits.stdout b/src/test/rustdoc-ui/coverage/traits.stdout
new file mode 100644 (file)
index 0000000..6f5db87
--- /dev/null
@@ -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% |
++---------------------------+------------+------------+------------+